From a85902b08d8b7a55fb8c61369baf4af779a8ab25 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 22 Jul 2011 12:01:33 +0200 Subject: [PATCH 01/85] [DDC-551] Initial code for filter functionality --- lib/Doctrine/ORM/Configuration.php | 14 ++++- lib/Doctrine/ORM/EntityManager.php | 49 +++++++++++++++++ lib/Doctrine/ORM/Query/Filter/SQLFilter.php | 61 +++++++++++++++++++++ 3 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 lib/Doctrine/ORM/Query/Filter/SQLFilter.php diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index a7219da8b..6e48ac19b 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -515,4 +515,16 @@ class Configuration extends \Doctrine\DBAL\Configuration } return $this->_attributes['classMetadataFactoryName']; } -} \ No newline at end of file + + public function addFilter($name, $className) + { + $this->_attributes['filters'][strtolower($name)] = $className; + } + + public function getFilterClassName($name) + { + $name = strtolower($name); + return isset($this->_attributes['filters'][$name]) ? + $this->_attributes['filters'][$name] : null; + } +} diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 0379cc435..c127eefff 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -110,6 +110,13 @@ class EntityManager implements ObjectManager */ private $closed = false; + /** + * Instances of enabled filters. + * + * @var array + */ + private $enabledFilters; + /** * Creates a new EntityManager that operates on the given database connection * and uses the given Configuration and EventManager implementations. @@ -739,4 +746,46 @@ class EntityManager implements ObjectManager return new EntityManager($conn, $config, $conn->getEventManager()); } + + /** @return SQLFilter[] */ + public function getEnabledFilters() + { + return $enabledFilters; + } + + /** Throws exception if filter does not exist. No-op if the filter is alrady enabled. + * @return SQLFilter */ + public function enableFilter($name) + { + if(null === $filterClass = $this->config->getFilter($name)) { + throw new \InvalidArgumentException("Filter '" . $name . "' is does not exist."); + } + + if(!isset($this->enabledFilters[$name])) { + $this->enabledFilters[$name] = new $filterClass($this->conn); + } + + return $this->enabledFilters[$name]; + } + + /** Disable the filter, looses the state */ + public function disableFilter($name) + { + // Get the filter to return it + $filter = $this->getFilter($name); + + unset($this->enabledFilters[$name]); + + return $filter; + } + + /** throws exception if not in enabled filters */ + public function getFilter($name) + { + if(!isset($this->enabledFilters[$name])) { + throw new \InvalidArgumentException("Filter '" . $name . "' is not enabled."); + } + + return $this->enabledFilters[$name]; + } } diff --git a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php new file mode 100644 index 000000000..454c554c1 --- /dev/null +++ b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php @@ -0,0 +1,61 @@ +. + */ + +namespace Doctrine\ORM\Query\Filter; + +use Doctrine\DBAL\Connection; + +/** + * The base class that user defined filters should extend. + * + * Handles the setting and escaping of parameters. + * + * @author Alexander + * @author Benjamin Eberlei + * @abstract + */ +abstract class SQLFilter +{ + private $conn; + + private $parameters; + + final public function __construct(Connection $conn) + { + $this->conn = $conn; + } + + final function setParameter($name, $value, $type) + { + // @todo: check for a valid type? + $parameters[$name] = array('value' => $value, 'type' => $type); + } + + final function getParameter($name) + { + if(!isset($parameters[$name])) { + throw new \InvalidArgumentException("Parameter '" . $name . "' is does not exist."); + } + + // @todo: espace the parameter + return $paramaters[$name]['value']; + } + + abstract function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias); +} From b867744f15b40e19604056481c388a7606f1a728 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 22 Jul 2011 13:08:49 +0200 Subject: [PATCH 02/85] [DDC-551] Added tests for SQLFilter functionality + small fixes --- lib/Doctrine/ORM/EntityManager.php | 8 +- lib/Doctrine/ORM/Query/Filter/SQLFilter.php | 1 + .../Tests/ORM/Functional/SQLFilterTest.php | 154 ++++++++++++++++++ 3 files changed, 159 insertions(+), 4 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index c127eefff..2605e0cec 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -115,7 +115,7 @@ class EntityManager implements ObjectManager * * @var array */ - private $enabledFilters; + private $enabledFilters = array(); /** * Creates a new EntityManager that operates on the given database connection @@ -750,15 +750,15 @@ class EntityManager implements ObjectManager /** @return SQLFilter[] */ public function getEnabledFilters() { - return $enabledFilters; + return $this->enabledFilters; } /** Throws exception if filter does not exist. No-op if the filter is alrady enabled. * @return SQLFilter */ public function enableFilter($name) { - if(null === $filterClass = $this->config->getFilter($name)) { - throw new \InvalidArgumentException("Filter '" . $name . "' is does not exist."); + if(null === $filterClass = $this->config->getFilterClassName($name)) { + throw new \InvalidArgumentException("Filter '" . $name . "' does not exist."); } if(!isset($this->enabledFilters[$name])) { diff --git a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php index 454c554c1..9f7307445 100644 --- a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php +++ b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php @@ -20,6 +20,7 @@ namespace Doctrine\ORM\Query\Filter; use Doctrine\DBAL\Connection; +use Doctrine\ORM\Mapping\ClassMetaData; /** * The base class that user defined filters should extend. diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php new file mode 100644 index 000000000..3cb3ce426 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -0,0 +1,154 @@ + + */ +class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase +{ + public function setUp() + { + parent::setUp(); + } + + public function testConfigureFilter() + { + $config = new \Doctrine\ORM\Configuration(); + + $config->addFilter("locale", "\Doctrine\Tests\ORM\Functional\MyLocaleFilter"); + + $this->assertEquals("\Doctrine\Tests\ORM\Functional\MyLocaleFilter", $config->getFilterClassName("locale")); + $this->assertNull($config->getFilterClassName("foo")); + } + + public function testEntityManagerEnableFilter() + { + $em = $this->_getEntityManager(); + $this->configureFilters($em); + + // Enable an existing filter + $filter = $em->enableFilter("locale"); + $this->assertTrue($filter instanceof \Doctrine\Tests\ORM\Functional\MyLocaleFilter); + + // Enable the filter again + $filter2 = $em->enableFilter("locale"); + $this->assertEquals($filter, $filter2); + + // Enable a non-existing filter + $exceptionThrown = false; + try { + $filter = $em->enableFilter("foo"); + } catch (\InvalidArgumentException $e) { + $exceptionThrown = true; + } + $this->assertTrue($exceptionThrown); + } + + public function testEntityManagerEnabledFilters() + { + $em = $this->_getEntityManager(); + + // No enabled filters + $this->assertEquals(array(), $em->getEnabledFilters()); + + $this->configureFilters($em); + $filter = $em->enableFilter("locale"); + $filter = $em->enableFilter("soft_delete"); + + // Two enabled filters + $this->assertEquals(2, count($em->getEnabledFilters())); + + } + + public function testEntityManagerDisableFilter() + { + $em = $this->_getEntityManager(); + $this->configureFilters($em); + + // Enable the filter + $filter = $em->enableFilter("locale"); + + // Disable it + $this->assertEquals($filter, $em->disableFilter("locale")); + $this->assertEquals(0, count($em->getEnabledFilters())); + + // Disable a non-existing filter + $exceptionThrown = false; + try { + $filter = $em->disableFilter("foo"); + } catch (\InvalidArgumentException $e) { + $exceptionThrown = true; + } + $this->assertTrue($exceptionThrown); + + // Disable a non-enabled filter + $exceptionThrown = false; + try { + $filter = $em->disableFilter("locale"); + } catch (\InvalidArgumentException $e) { + $exceptionThrown = true; + } + $this->assertTrue($exceptionThrown); + } + + public function testEntityManagerGetFilter() + { + $em = $this->_getEntityManager(); + $this->configureFilters($em); + + // Enable the filter + $filter = $em->enableFilter("locale"); + + // Get the filter + $this->assertEquals($filter, $em->getFilter("locale")); + + // Get a non-enabled filter + $exceptionThrown = false; + try { + $filter = $em->getFilter("soft_delete"); + } catch (\InvalidArgumentException $e) { + $exceptionThrown = true; + } + $this->assertTrue($exceptionThrown); + } + + protected function configureFilters($em) + { + // Add filters to the configuration of the EM + $config = $em->getConfiguration(); + $config->addFilter("locale", "\Doctrine\Tests\ORM\Functional\MyLocaleFilter"); + $config->addFilter("soft_delete", "\Doctrine\Tests\ORM\Functional\MySoftDeleteFilter"); + } +} + +class MySoftDeleteFilter extends SQLFilter +{ + public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) + { + if ($targetEntity->name != "MyEntity\SoftDeleteNewsItem") { + return ""; + } + + return $targetTableAlias.'.deleted = 0'; + } +} + +class MyLocaleFilter extends SQLFilter +{ + public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) + { + if (!in_array("LocaleAware", $targetEntity->reflClass->getInterfaceNames())) { + return ""; + } + + return $targetTableAlias.'.locale = ' . $this->getParam('locale'); // getParam uses connection to quote the value. + } +} From 277fc751b6cbcc906e1986947b2b4fee3ff6f382 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 22 Jul 2011 13:51:26 +0200 Subject: [PATCH 03/85] [DDC-551] Added tests for SQLFilter --- lib/Doctrine/ORM/Query/Filter/SQLFilter.php | 10 ++-- .../Tests/ORM/Functional/SQLFilterTest.php | 46 +++++++++++++++++++ 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php index 9f7307445..9477636e3 100644 --- a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php +++ b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php @@ -45,17 +45,19 @@ abstract class SQLFilter final function setParameter($name, $value, $type) { // @todo: check for a valid type? - $parameters[$name] = array('value' => $value, 'type' => $type); + $this->parameters[$name] = array('value' => $value, 'type' => $type); + + return $this; } final function getParameter($name) { - if(!isset($parameters[$name])) { - throw new \InvalidArgumentException("Parameter '" . $name . "' is does not exist."); + if(!isset($this->parameters[$name])) { + throw new \InvalidArgumentException("Parameter '" . $name . "' does not exist."); } // @todo: espace the parameter - return $paramaters[$name]['value']; + return $this->conn->convertToDatabaseValue($this->parameters[$name]['value'], $this->parameters[$name]['type']); } abstract function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias); diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index 3cb3ce426..482ddb534 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\ORM\Query\Filter\SQLFilter; use Doctrine\ORM\Mapping\ClassMetaData; +use Doctrine\DBAL\Types\Type; require_once __DIR__ . '/../../TestInit.php'; @@ -127,6 +128,51 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $config->addFilter("locale", "\Doctrine\Tests\ORM\Functional\MyLocaleFilter"); $config->addFilter("soft_delete", "\Doctrine\Tests\ORM\Functional\MySoftDeleteFilter"); } + + protected function getMockConnection() + { + // Setup connection mock + $conn = $this->getMockBuilder('Doctrine\DBAL\Connection') + ->disableOriginalConstructor() + ->getMock(); + + return $conn; + } + + public function testSQLFilterGetSetParameter() + { + // Setup mock connection + $conn = $this->getMockConnection(); + $conn->expects($this->once()) + ->method('convertToDatabaseValue') + ->with($this->equalTo('en')) + ->will($this->returnValue("'en'")); + + $filter = new MyLocaleFilter($conn); + + $filter->setParameter('locale', 'en', Type::STRING); + + $this->assertEquals("'en'", $filter->getParameter('locale')); + } + + public function testSQLFilterAddConstraint() + { + // Set up metadata mock + $targetEntity = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata') + ->disableOriginalConstructor() + ->getMock(); + + $filter = new MySoftDeleteFilter($this->getMockConnection()); + + // Test for an entity that gets extra filter data + $targetEntity->name = 'MyEntity\SoftDeleteNewsItem'; + $this->assertEquals('t1_.deleted = 0', $filter->addFilterConstraint($targetEntity, 't1_')); + + // Test for an entity that doesn't get extra filter data + $targetEntity->name = 'MyEntity\NoSoftDeleteNewsItem'; + $this->assertEquals('', $filter->addFilterConstraint($targetEntity, 't1_')); + + } } class MySoftDeleteFilter extends SQLFilter From d1908f7207565a3cdd47ee42dd73a38642cde519 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 22 Jul 2011 14:20:36 +0200 Subject: [PATCH 04/85] [DDC-551] Keep filter parameters and enabled filters sorted for hashing --- lib/Doctrine/ORM/EntityManager.php | 3 +++ lib/Doctrine/ORM/Query/Filter/SQLFilter.php | 3 +++ 2 files changed, 6 insertions(+) diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 2605e0cec..558477ca4 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -763,6 +763,9 @@ class EntityManager implements ObjectManager if(!isset($this->enabledFilters[$name])) { $this->enabledFilters[$name] = new $filterClass($this->conn); + + // Keep the enabled filters sorted for the hash + ksort($this->enabledFilters); } return $this->enabledFilters[$name]; diff --git a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php index 9477636e3..16887fd4d 100644 --- a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php +++ b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php @@ -47,6 +47,9 @@ abstract class SQLFilter // @todo: check for a valid type? $this->parameters[$name] = array('value' => $value, 'type' => $type); + // Keep the parameters sorted for the hash + ksort($this->parameters); + return $this; } From 4cf63a4e83665ab674c2e95630f031490d6c42a6 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 22 Jul 2011 14:48:20 +0200 Subject: [PATCH 05/85] [DDC-551] Fixed the escaping of filter parameters --- lib/Doctrine/ORM/Query/Filter/SQLFilter.php | 3 +-- tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php index 16887fd4d..4ca31d64d 100644 --- a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php +++ b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php @@ -59,8 +59,7 @@ abstract class SQLFilter throw new \InvalidArgumentException("Parameter '" . $name . "' does not exist."); } - // @todo: espace the parameter - return $this->conn->convertToDatabaseValue($this->parameters[$name]['value'], $this->parameters[$name]['type']); + return $this->conn->quote($this->parameters[$name]['value'], $this->parameters[$name]['type']); } abstract function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias); diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index 482ddb534..a58fef3bf 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -144,7 +144,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase // Setup mock connection $conn = $this->getMockConnection(); $conn->expects($this->once()) - ->method('convertToDatabaseValue') + ->method('quote') ->with($this->equalTo('en')) ->will($this->returnValue("'en'")); From 4266ab77b219242455c8d46a93f81e2dcf13b143 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 22 Jul 2011 14:55:00 +0200 Subject: [PATCH 06/85] [DDC-551] Added __toString() method to SQLFilter --- lib/Doctrine/ORM/Query/Filter/SQLFilter.php | 5 +++++ .../Tests/ORM/Functional/SQLFilterTest.php | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php index 4ca31d64d..2ac413788 100644 --- a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php +++ b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php @@ -62,5 +62,10 @@ abstract class SQLFilter return $this->conn->quote($this->parameters[$name]['value'], $this->parameters[$name]['type']); } + final function __toString() + { + return serialize($this->parameters); + } + abstract function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias); } diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index a58fef3bf..6cc1a75be 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -173,6 +173,25 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals('', $filter->addFilterConstraint($targetEntity, 't1_')); } + + public function testSQLFilterToString() + { + $filter = new MyLocaleFilter($this->getMockConnection()); + $filter->setParameter('locale', 'en', TYPE::STRING); + $filter->setParameter('foo', 'bar', TYPE::STRING); + + $filter2 = new MyLocaleFilter($this->getMockConnection()); + $filter2->setParameter('foo', 'bar', TYPE::STRING); + $filter2->setParameter('locale', 'en', TYPE::STRING); + + $parameters = array( + 'foo' => array('value' => 'bar', 'type' => TYPE::STRING), + 'locale' => array('value' => 'en', 'type' => TYPE::STRING), + ); + + $this->assertEquals(serialize($parameters), ''.$filter); + $this->assertEquals(''.$filter, ''.$filter2); + } } class MySoftDeleteFilter extends SQLFilter From afd7a540a7f5c01767d15f18a519978ff1562028 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 22 Jul 2011 15:10:31 +0200 Subject: [PATCH 07/85] [DDC-551] Removed 'use ..DBAL\..\Type', causing full testsuite to fail --- .../Tests/ORM/Functional/SQLFilterTest.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index 6cc1a75be..7e6470cfc 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -4,7 +4,6 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\ORM\Query\Filter\SQLFilter; use Doctrine\ORM\Mapping\ClassMetaData; -use Doctrine\DBAL\Types\Type; require_once __DIR__ . '/../../TestInit.php'; @@ -150,7 +149,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $filter = new MyLocaleFilter($conn); - $filter->setParameter('locale', 'en', Type::STRING); + $filter->setParameter('locale', 'en', \Doctrine\DBAL\Types\Type::STRING); $this->assertEquals("'en'", $filter->getParameter('locale')); } @@ -177,16 +176,16 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testSQLFilterToString() { $filter = new MyLocaleFilter($this->getMockConnection()); - $filter->setParameter('locale', 'en', TYPE::STRING); - $filter->setParameter('foo', 'bar', TYPE::STRING); + $filter->setParameter('locale', 'en', \Doctrine\DBAL\Types\Type::STRING); + $filter->setParameter('foo', 'bar', \Doctrine\DBAL\Types\Type::STRING); $filter2 = new MyLocaleFilter($this->getMockConnection()); - $filter2->setParameter('foo', 'bar', TYPE::STRING); - $filter2->setParameter('locale', 'en', TYPE::STRING); + $filter2->setParameter('foo', 'bar', \Doctrine\DBAL\Types\Type::STRING); + $filter2->setParameter('locale', 'en', \Doctrine\DBAL\Types\Type::STRING); $parameters = array( - 'foo' => array('value' => 'bar', 'type' => TYPE::STRING), - 'locale' => array('value' => 'en', 'type' => TYPE::STRING), + 'foo' => array('value' => 'bar', 'type' => \Doctrine\DBAL\Types\Type::STRING), + 'locale' => array('value' => 'en', 'type' => \Doctrine\DBAL\Types\Type::STRING), ); $this->assertEquals(serialize($parameters), ''.$filter); From 6163d9d932104fcf17912674e40926310b4a5c88 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 22 Jul 2011 15:26:03 +0200 Subject: [PATCH 08/85] [DDC-551] Added enabled filters to Query hash --- lib/Doctrine/ORM/Query.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index 820711d55..e413a9260 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -558,6 +558,7 @@ final class Query extends AbstractQuery return md5( $this->getDql() . var_export($this->_hints, true) . + var_export($this->_em->getEnabledFilters(), true) . '&firstResult=' . $this->_firstResult . '&maxResult=' . $this->_maxResults . '&hydrationMode='.$this->_hydrationMode.'DOCTRINE_QUERY_CACHE_SALT' ); @@ -573,4 +574,4 @@ final class Query extends AbstractQuery parent::__clone(); $this->_state = self::STATE_DIRTY; } -} \ No newline at end of file +} From e3dcfa870257fdb1965e5d6ac74f7b1d91684b6d Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 22 Jul 2011 17:01:18 +0200 Subject: [PATCH 09/85] [DDC-551] Added filters to query hash + tests for hash --- lib/Doctrine/ORM/Query.php | 20 +++++++++++++++- .../Tests/ORM/Functional/SQLFilterTest.php | 24 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index e413a9260..0f4cbf1c1 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -556,14 +556,32 @@ final class Query extends AbstractQuery { ksort($this->_hints); + return md5( $this->getDql() . var_export($this->_hints, true) . - var_export($this->_em->getEnabledFilters(), true) . + $this->getFilterHash() . '&firstResult=' . $this->_firstResult . '&maxResult=' . $this->_maxResults . '&hydrationMode='.$this->_hydrationMode.'DOCTRINE_QUERY_CACHE_SALT' ); } + /** + * Generates a string of currently enabled filters to use for the cache id. + * + * @return string + */ + protected function getFilterHash() + { + $filterHash = ''; + + $filters = $this->_em->getEnabledFilters(); + foreach($filters as $name => $filter) { + $filterHash .= $name . $filter; + } + + return $filterHash; + } + /** * Cleanup Query resource when clone is called. * diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index 7e6470cfc..ac9bae0c7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\ORM\Query\Filter\SQLFilter; use Doctrine\ORM\Mapping\ClassMetaData; +use Doctrine\Common\Cache\ArrayCache; require_once __DIR__ . '/../../TestInit.php'; @@ -16,6 +17,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase { public function setUp() { + $this->useModelSet('cms'); parent::setUp(); } @@ -191,6 +193,28 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(serialize($parameters), ''.$filter); $this->assertEquals(''.$filter, ''.$filter2); } + + public function testQueryCache_DependsOnFilters() + { + $query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux'); + + $cache = new ArrayCache(); + $query->setQueryCacheDriver($cache); + + $query->getResult(); + $this->assertEquals(1, count($cache->getIds())); + + $conf = $this->_em->getConfiguration(); + $conf->addFilter("locale", "\Doctrine\Tests\ORM\Functional\MyLocaleFilter"); + $this->_em->enableFilter("locale"); + + $query->getResult(); + $this->assertEquals(2, count($cache->getIds())); + + return $query; + } + + } class MySoftDeleteFilter extends SQLFilter From 3b1ddb034675b80baef427c8cea0f63b91f3a372 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 16 Aug 2011 12:03:47 +0200 Subject: [PATCH 10/85] [DDC-551] Added filters to SQLWalker --- lib/Doctrine/ORM/Query/Filter/SQLFilter.php | 3 + lib/Doctrine/ORM/Query/SqlWalker.php | 46 +++++ .../Tests/ORM/Functional/SQLFilterTest.php | 164 +++++++++++++++++- 3 files changed, 211 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php index 2ac413788..dd90f1789 100644 --- a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php +++ b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php @@ -67,5 +67,8 @@ abstract class SQLFilter return serialize($this->parameters); } + /** + * @return string The contstraint if there is one, empty string otherwise + */ abstract function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias); } diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 7393ba893..8810aed87 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -350,6 +350,20 @@ class SqlWalker implements TreeWalker return ($encapsulate) ? '(' . $sql . ')' : $sql; } + private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias) + { + $filterSql = ''; + + $first = true; + foreach($this->_em->getEnabledFilters() as $filter) { + if("" !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { + if ( ! $first) $sql .= ' AND '; else $first = false; + $filterSql .= '(' . $filterExpr . ')'; + } + } + + return $filterSql; + } /** * Walks down a SelectStatement AST node, thereby generating the appropriate SQL. * @@ -771,6 +785,12 @@ class SqlWalker implements TreeWalker $sql .= $sourceTableAlias . '.' . $quotedTargetColumn . ' = ' . $targetTableAlias . '.' . $sourceColumn; } } + + // Apply the filters + if("" !== $filterExpr = $this->generateFilterConditionSQL($targetClass, $targetTableAlias)) { + if ( ! $first) $sql .= ' AND '; else $first = false; + $sql .= $filterExpr; + } } else if ($assoc['type'] == ClassMetadata::MANY_TO_MANY) { // Join relation table $joinTable = $assoc['joinTable']; @@ -835,6 +855,12 @@ class SqlWalker implements TreeWalker $sql .= $targetTableAlias . '.' . $quotedTargetColumn . ' = ' . $joinTableAlias . '.' . $relationColumn; } } + + // Apply the filters + if("" !== $filterExpr = $this->generateFilterConditionSQL($targetClass, $targetTableAlias)) { + if ( ! $first) $sql .= ' AND '; else $first = false; + $sql .= $filterExpr; + } } // Handle WITH clause @@ -1414,6 +1440,26 @@ class SqlWalker implements TreeWalker $condSql = null !== $whereClause ? $this->walkConditionalExpression($whereClause->conditionalExpression) : ''; $discrSql = $this->_generateDiscriminatorColumnConditionSql($this->_rootAliases); + $filterSql = ''; + + // Apply the filters for all entities in FROM + $first = true; + foreach ($this->_rootAliases as $dqlAlias) { + $class = $this->_queryComponents[$dqlAlias]['metadata']; + $tableAlias = $this->getSQLTableAlias($class->table['name'], $dqlAlias); + + if("" !== $filterExpr = $this->generateFilterConditionSQL($class, $tableAlias)) { + if ( ! $first) $filterSql .= ' AND '; else $first = false; + $filterSql .= $filterExpr; + } + } + + if ('' !== $filterSql) { + if($condSql) $condSql .= ' AND '; + + $condSql .= $filterSql; + } + if ($condSql) { return ' WHERE ' . (( ! $discrSql) ? $condSql : '(' . $condSql . ') AND ' . $discrSql); } else if ($discrSql) { diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index ac9bae0c7..997032cbc 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -6,6 +6,15 @@ use Doctrine\ORM\Query\Filter\SQLFilter; use Doctrine\ORM\Mapping\ClassMetaData; use Doctrine\Common\Cache\ArrayCache; +use Doctrine\ORM\Mapping\ClassMetadataInfo; + +use Doctrine\Tests\Models\CMS\CmsUser; +use Doctrine\Tests\Models\CMS\CmsPhonenumber; +use Doctrine\Tests\Models\CMS\CmsAddress; +use Doctrine\Tests\Models\CMS\CmsGroup; +use Doctrine\Tests\Models\CMS\CmsArticle; +use Doctrine\Tests\Models\CMS\CmsComment; + require_once __DIR__ . '/../../TestInit.php'; /** @@ -15,6 +24,8 @@ require_once __DIR__ . '/../../TestInit.php'; */ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase { + private $userId, $userId2, $articleId, $articleId2; + public function setUp() { $this->useModelSet('cms'); @@ -211,10 +222,124 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $query->getResult(); $this->assertEquals(2, count($cache->getIds())); - return $query; + // Another time doesn't add another cache entry + $query->getResult(); + $this->assertEquals(2, count($cache->getIds())); + } + + public function testToOneFilter() + { + //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); + $this->loadFixtureData(); + + $query = $this->_em->createQuery('select ux, ua from Doctrine\Tests\Models\CMS\CmsUser ux JOIN ux.address ua'); + + // We get two users before enabling the filter + $this->assertEquals(2, count($query->getResult())); + + $conf = $this->_em->getConfiguration(); + $conf->addFilter("country", "\Doctrine\Tests\ORM\Functional\CMSCountryFilter"); + $this->_em->enableFilter("country")->setParameter("country", "Germany", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); + + // We get one user after enabling the filter + $this->assertEquals(1, count($query->getResult())); + } + + public function testManyToManyFilter() + { + $this->loadFixtureData(); + $query = $this->_em->createQuery('select ux, ug from Doctrine\Tests\Models\CMS\CmsUser ux JOIN ux.groups ug'); + + // We get two users before enabling the filter + $this->assertEquals(2, count($query->getResult())); + + $conf = $this->_em->getConfiguration(); + $conf->addFilter("group_prefix", "\Doctrine\Tests\ORM\Functional\CMSGroupPrefixFilter"); + $this->_em->enableFilter("group_prefix")->setParameter("prefix", "bar_%", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); + + // We get one user after enabling the filter + $this->assertEquals(1, count($query->getResult())); + + } + + public function testWhereFilter() + { + $this->loadFixtureData(); + $query = $this->_em->createQuery('select ug from Doctrine\Tests\Models\CMS\CmsGroup ug WHERE 1=1'); + + // We get two users before enabling the filter + $this->assertEquals(2, count($query->getResult())); + + $conf = $this->_em->getConfiguration(); + $conf->addFilter("group_prefix", "\Doctrine\Tests\ORM\Functional\CMSGroupPrefixFilter"); + $this->_em->enableFilter("group_prefix")->setParameter("prefix", "bar_%", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); + + // We get one user after enabling the filter + $this->assertEquals(1, count($query->getResult())); } + private function loadFixtureData() + { + $user = new CmsUser; + $user->name = 'Roman'; + $user->username = 'romanb'; + $user->status = 'developer'; + + $address = new CmsAddress; + $address->country = 'Germany'; + $address->city = 'Berlin'; + $address->zip = '12345'; + + $user->address = $address; // inverse side + $address->user = $user; // owning side! + + $group = new CmsGroup; + $group->name = 'foo_group'; + $user->addGroup($group); + + $article1 = new CmsArticle; + $article1->topic = "Test1"; + $article1->text = "Test"; + $article1->setAuthor($user); + + $article2 = new CmsArticle; + $article2->topic = "Test2"; + $article2->text = "Test"; + $article2->setAuthor($user); + + $this->_em->persist($article1); + $this->_em->persist($article2); + + $this->_em->persist($user); + + $user2 = new CmsUser; + $user2->name = 'Guilherme'; + $user2->username = 'gblanco'; + $user2->status = 'developer'; + + $address2 = new CmsAddress; + $address2->country = 'France'; + $address2->city = 'Paris'; + $address2->zip = '12345'; + + $user->address = $address2; // inverse side + $address2->user = $user2; // owning side! + + $user2->addGroup($group); + $group2 = new CmsGroup; + $group2->name = 'bar_group'; + $user2->addGroup($group2); + + $this->_em->persist($user2); + $this->_em->flush(); + $this->_em->clear(); + + $this->userId = $user->getId(); + $this->userId2 = $user2->getId(); + $this->articleId = $article1->id; + $this->articleId2 = $article2->id; + } } class MySoftDeleteFilter extends SQLFilter @@ -237,6 +362,41 @@ class MyLocaleFilter extends SQLFilter return ""; } - return $targetTableAlias.'.locale = ' . $this->getParam('locale'); // getParam uses connection to quote the value. + return $targetTableAlias.'.locale = ' . $this->getParameter('locale'); // getParam uses connection to quote the value. + } +} + +class CMSCountryFilter extends SQLFilter +{ + public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) + { + if ($targetEntity->name != "Doctrine\Tests\Models\CMS\CmsAddress") { + return ""; + } + + return $targetTableAlias.'.country = ' . $this->getParameter('country'); // getParam uses connection to quote the value. + } +} + +class CMSGroupPrefixFilter extends SQLFilter +{ + public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) + { + if ($targetEntity->name != "Doctrine\Tests\Models\CMS\CmsGroup") { + return ""; + } + + return $targetTableAlias.'.name LIKE ' . $this->getParameter('prefix'); // getParam uses connection to quote the value. + } +} +class CMSArticleTopicFilter extends SQLFilter +{ + public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) + { + if ($targetEntity->name != "Doctrine\Tests\Models\CMS\CmsArticle") { + return ""; + } + + return $targetTableAlias.'.topic = ' . $this->getParameter('topic'); // getParam uses connection to quote the value. } } From 2653d735e230d19b0fcb703800008f3abdb7a3ba Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 16 Aug 2011 13:23:53 +0200 Subject: [PATCH 11/85] [DDC-551] Added state of the complete filter collection to the EM Previously it was sufficient to use the old parser result for a Query if the DQL didn't change (Query::STATE_CLEAN), but now there must also be no changes to the filter collection of the EntityManager. In the old situation each Query object would create a hash of all the filter objects on it's own. That was not very efficient. This commit adds the state of the current filter collection to the EntityManager. The state will be set to FILTERS_STATE_DIRTY as a filter is enabled, removed or a parameter is set on a filter. The hash is also computed by the EntityManager, but only if the filter collection is dirty. This will prevent recalculation of the hash with each query. --- lib/Doctrine/ORM/EntityManager.php | 65 ++++++++++++++++++- lib/Doctrine/ORM/Query.php | 29 ++------- lib/Doctrine/ORM/Query/Filter/SQLFilter.php | 13 ++-- .../Tests/ORM/Functional/SQLFilterTest.php | 36 ++++++++-- 4 files changed, 111 insertions(+), 32 deletions(-) diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 558477ca4..96e013b36 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -110,6 +110,7 @@ class EntityManager implements ObjectManager */ private $closed = false; + /* Filters data */ /** * Instances of enabled filters. * @@ -117,6 +118,29 @@ class EntityManager implements ObjectManager */ private $enabledFilters = array(); + /** + * @var string The filter hash from the last time the query was parsed. + */ + private $filterHash; + + /* Filter STATES */ + /** + * A filter object is in CLEAN state when it has no changed parameters. + */ + const FILTERS_STATE_CLEAN = 1; + + /** + * A filter object is in DIRTY state when it has changed parameters. + */ + const FILTERS_STATE_DIRTY = 2; + + /** + * @var integer $state The current state of this filter + */ + private $filtersState = self::FILTERS_STATE_CLEAN; + + /* End filters data */ + /** * Creates a new EntityManager that operates on the given database connection * and uses the given Configuration and EventManager implementations. @@ -762,10 +786,13 @@ class EntityManager implements ObjectManager } if(!isset($this->enabledFilters[$name])) { - $this->enabledFilters[$name] = new $filterClass($this->conn); + $this->enabledFilters[$name] = new $filterClass($this); // Keep the enabled filters sorted for the hash ksort($this->enabledFilters); + + // Now the filter collection is dirty + $this->filtersState = self::FILTERS_STATE_DIRTY; } return $this->enabledFilters[$name]; @@ -779,6 +806,9 @@ class EntityManager implements ObjectManager unset($this->enabledFilters[$name]); + // Now the filter collection is dirty + $this->filtersState = self::FILTERS_STATE_DIRTY; + return $filter; } @@ -791,4 +821,37 @@ class EntityManager implements ObjectManager return $this->enabledFilters[$name]; } + + /** + * @return boolean True, if the filter collection is clean. + */ + public function isFiltersStateClean() + { + return self::FILTERS_STATE_CLEAN === $this->filtersState; + } + + public function setFiltersStateDirty() + { + $this->filtersState = self::FILTERS_STATE_DIRTY; + } + + /** + * Generates a string of currently enabled filters to use for the cache id. + * + * @return string + */ + public function getFilterHash() + { + // If there are only clean filters, the previous hash can be returned + if(self::FILTERS_STATE_CLEAN === $this->filtersState) { + return $this->filterHash; + } + + $filterHash = ''; + foreach($this->enabledFilters as $name => $filter) { + $filterHash .= $name . $filter; + } + + return $filterHash; + } } diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index 0f4cbf1c1..5a4545ad9 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -198,10 +198,13 @@ final class Query extends AbstractQuery */ private function _parse() { - if ($this->_state === self::STATE_CLEAN) { + // Return previous parser result if the query and the filter collection are both clean + if ($this->_state === self::STATE_CLEAN + && $this->_em->isFiltersStateClean() + ) { return $this->_parserResult; } - + // Check query cache. if ($this->_useQueryCache && ($queryCache = $this->getQueryCacheDriver())) { $hash = $this->_getQueryCacheId(); @@ -556,32 +559,14 @@ final class Query extends AbstractQuery { ksort($this->_hints); - return md5( - $this->getDql() . var_export($this->_hints, true) . - $this->getFilterHash() . + $this->getDql() . var_export($this->_hints, true) . + $this->_em->getFilterHash() . '&firstResult=' . $this->_firstResult . '&maxResult=' . $this->_maxResults . '&hydrationMode='.$this->_hydrationMode.'DOCTRINE_QUERY_CACHE_SALT' ); } - /** - * Generates a string of currently enabled filters to use for the cache id. - * - * @return string - */ - protected function getFilterHash() - { - $filterHash = ''; - - $filters = $this->_em->getEnabledFilters(); - foreach($filters as $name => $filter) { - $filterHash .= $name . $filter; - } - - return $filterHash; - } - /** * Cleanup Query resource when clone is called. * diff --git a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php index dd90f1789..5a66fb64d 100644 --- a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php +++ b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php @@ -19,8 +19,8 @@ namespace Doctrine\ORM\Query\Filter; -use Doctrine\DBAL\Connection; use Doctrine\ORM\Mapping\ClassMetaData; +use Doctrine\ORM\EntityManager; /** * The base class that user defined filters should extend. @@ -33,13 +33,13 @@ use Doctrine\ORM\Mapping\ClassMetaData; */ abstract class SQLFilter { - private $conn; + private $em; private $parameters; - final public function __construct(Connection $conn) + final public function __construct(EntityManager $em) { - $this->conn = $conn; + $this->em = $em; } final function setParameter($name, $value, $type) @@ -50,6 +50,9 @@ abstract class SQLFilter // Keep the parameters sorted for the hash ksort($this->parameters); + // The filter collection of the EM is now dirty + $this->em->setFiltersStateDirty(); + return $this; } @@ -59,7 +62,7 @@ abstract class SQLFilter throw new \InvalidArgumentException("Parameter '" . $name . "' does not exist."); } - return $this->conn->quote($this->parameters[$name]['value'], $this->parameters[$name]['type']); + return $this->em->getConnection()->quote($this->parameters[$name]['value'], $this->parameters[$name]['type']); } final function __toString() diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index 997032cbc..f9afc130d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -151,6 +151,16 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase return $conn; } + protected function getMockEntityManager() + { + // Setup connection mock + $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + return $em; + } + public function testSQLFilterGetSetParameter() { // Setup mock connection @@ -160,7 +170,12 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase ->with($this->equalTo('en')) ->will($this->returnValue("'en'")); - $filter = new MyLocaleFilter($conn); + $em = $this->getMockEntityManager($conn); + $em->expects($this->once()) + ->method('getConnection') + ->will($this->returnValue($conn)); + + $filter = new MyLocaleFilter($em); $filter->setParameter('locale', 'en', \Doctrine\DBAL\Types\Type::STRING); @@ -174,7 +189,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase ->disableOriginalConstructor() ->getMock(); - $filter = new MySoftDeleteFilter($this->getMockConnection()); + $filter = new MySoftDeleteFilter($this->getMockEntityManager()); // Test for an entity that gets extra filter data $targetEntity->name = 'MyEntity\SoftDeleteNewsItem'; @@ -188,11 +203,11 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testSQLFilterToString() { - $filter = new MyLocaleFilter($this->getMockConnection()); + $filter = new MyLocaleFilter($this->getMockEntityManager()); $filter->setParameter('locale', 'en', \Doctrine\DBAL\Types\Type::STRING); $filter->setParameter('foo', 'bar', \Doctrine\DBAL\Types\Type::STRING); - $filter2 = new MyLocaleFilter($this->getMockConnection()); + $filter2 = new MyLocaleFilter($this->getMockEntityManager()); $filter2->setParameter('foo', 'bar', \Doctrine\DBAL\Types\Type::STRING); $filter2->setParameter('locale', 'en', \Doctrine\DBAL\Types\Type::STRING); @@ -227,6 +242,19 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(2, count($cache->getIds())); } + public function testQueryGeneration_DependsOnFilters() + { + $query = $this->_em->createQuery('select a from Doctrine\Tests\Models\CMS\CmsAddress a'); + $firstSQLQuery = $query->getSQL(); + + $conf = $this->_em->getConfiguration(); + $conf->addFilter("country", "\Doctrine\Tests\ORM\Functional\CMSCountryFilter"); + $this->_em->enableFilter("country") + ->setParameter("country", "en", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); + + $this->assertNotEquals($firstSQLQuery, $query->getSQL()); + } + public function testToOneFilter() { //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); From 380058194736e3eb6f219195a06fe60e1480039e Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 16 Aug 2011 16:24:50 +0200 Subject: [PATCH 12/85] [DDC-551] Altered persisters to make filters work with EXTRA_LAZY associations --- .../ORM/Persisters/BasicEntityPersister.php | 35 +++++- .../ORM/Persisters/ManyToManyPersister.php | 51 +++++++- .../ORM/Persisters/OneToManyPersister.php | 12 +- .../Tests/ORM/Functional/SQLFilterTest.php | 115 ++++++++++++++++++ 4 files changed, 205 insertions(+), 8 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 19da2e200..9da8e95fc 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -861,9 +861,17 @@ class BasicEntityPersister $lockSql = ' ' . $this->_platform->getWriteLockSql(); } + $alias = $this->_getSQLTableAlias($this->_class->name); + + $filterSql = $this->generateFilterConditionSQL($this->_class, $alias); + if('' !== $filterSql) { + if($conditionSql) $conditionSql .= ' AND '; + $conditionSql .= $filterSql; + } + return $this->_platform->modifyLimitQuery('SELECT ' . $this->_getSelectColumnListSQL() . $this->_platform->appendLockHint(' FROM ' . $this->_class->getQuotedTableName($this->_platform) . ' ' - . $this->_getSQLTableAlias($this->_class->name), $lockMode) + . $alias, $lockMode) . $this->_selectJoinSql . $joinSql . ($conditionSql ? ' WHERE ' . $conditionSql : '') . $orderBySql, $limit, $offset) @@ -1340,10 +1348,33 @@ class BasicEntityPersister $criteria = array_merge($criteria, $extraConditions); } + $alias = $this->_getSQLTableAlias($this->_class->name); + + $sql = 'SELECT 1 FROM ' . $this->_class->getQuotedTableName($this->_platform) - . ' ' . $this->_getSQLTableAlias($this->_class->name) + . ' ' . $alias . ' WHERE ' . $this->_getSelectConditionSQL($criteria); + $filterSql = $this->generateFilterConditionSQL($this->_class, $alias); + if('' !== $filterSql) { + $sql .= ' AND ' . $filterSql; + } + return (bool) $this->_conn->fetchColumn($sql, array_values($criteria)); } + + private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias) + { + $filterSql = ''; + + $first = true; + foreach($this->_em->getEnabledFilters() as $filter) { + if("" !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { + if ( ! $first) $sql .= ' AND '; else $first = false; + $filterSql .= '(' . $filterExpr . ')'; + } + } + + return $filterSql; + } } diff --git a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php index 6ca2b15a5..ee0b9e1b0 100644 --- a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php @@ -208,7 +208,7 @@ class ManyToManyPersister extends AbstractCollectionPersister if ($whereClause !== '') { $whereClause .= ' AND '; } - $whereClause .= "$joinTableColumn = ?"; + $whereClause .= "t.$joinTableColumn = ?"; if ($class->containsForeignIdentifier) { $params[] = $id[$class->getFieldForColumn($joinColumns[$joinTableColumn])]; @@ -217,7 +217,14 @@ class ManyToManyPersister extends AbstractCollectionPersister } } } - $sql = 'SELECT count(*) FROM ' . $joinTable['name'] . ' WHERE ' . $whereClause; + + list($joinTargetEntitySQL, $filterSql) = $this->getFilterSql($mapping); + + $sql = 'SELECT count(*)' + . ' FROM ' . $joinTable['name'] . ' t' + . $joinTargetEntitySQL + . ' WHERE ' . $whereClause + . $filterSql; return $this->_conn->fetchColumn($sql, $params); } @@ -293,8 +300,44 @@ class ManyToManyPersister extends AbstractCollectionPersister } } } - $sql = 'SELECT 1 FROM ' . $joinTable['name'] . ' WHERE ' . $whereClause; + + list($joinTargetEntitySQL, $filterSql) = $this->getFilterSql($mapping); + + $sql = 'SELECT 1' + . ' FROM ' . $joinTable['name'] . ' t' + . $joinTargetEntitySQL + . ' WHERE ' . $whereClause + . $filterSql; return (bool)$this->_conn->fetchColumn($sql, $params); } -} \ No newline at end of file + + public function getFilterSql($mapping) + { + $targetClass = $this->_em->getClassMetadata($mapping['targetEntity']); + + // Get the SQL for the filters + $filterSql = ''; + foreach($this->_em->getEnabledFilters() as $filter) { + if("" !== $filterExpr = $filter->addFilterConstraint($targetClass, 'te')) { + $filterSql .= ' AND (' . $filterExpr . ')'; + } + } + + // A join is needed if there is filtering on the target entity + $joinTargetEntitySQL = ''; + if('' !== $filterSql) { + $joinTargetEntitySQL = ' JOIN ' + . $targetClass->getQuotedTableName($this->_conn->getDatabasePlatform()) . ' te' + . ' ON'; + + $first = true; + foreach($mapping['relationToTargetKeyColumns'] as $joinTableColumn => $targetTableColumn) { + if(!$first) $joinTargetEntitySQL .= ' AND '; else $first = false; + $joinTargetEntitySQL .= ' t.' . $joinTableColumn . ' = ' . 'te.' . $targetTableColumn; + } + } + + return array($joinTargetEntitySQL, $filterSql); + } +} diff --git a/lib/Doctrine/ORM/Persisters/OneToManyPersister.php b/lib/Doctrine/ORM/Persisters/OneToManyPersister.php index 5e889ddb9..2dfd18e79 100644 --- a/lib/Doctrine/ORM/Persisters/OneToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/OneToManyPersister.php @@ -133,7 +133,7 @@ class OneToManyPersister extends AbstractCollectionPersister if ($where != '') { $where .= ' AND '; } - $where .= $joinColumn['name'] . " = ?"; + $where .= 't.' . $joinColumn['name'] . " = ?"; if ($class->containsForeignIdentifier) { $params[] = $id[$class->getFieldForColumn($joinColumn['referencedColumnName'])]; } else { @@ -141,7 +141,15 @@ class OneToManyPersister extends AbstractCollectionPersister } } - $sql = "SELECT count(*) FROM " . $class->getQuotedTableName($this->_conn->getDatabasePlatform()) . " WHERE " . $where; + $sql = "SELECT count(*) FROM " . $class->getQuotedTableName($this->_conn->getDatabasePlatform()) . " t WHERE " . $where; + + // Apply the filters + foreach($this->_em->getEnabledFilters() as $filter) { + if("" !== $filterExpr = $filter->addFilterConstraint($class, 't')) { + $sql .= ' AND (' . $filterExpr . ')'; + } + } + return $this->_conn->fetchColumn($sql, $params); } diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index f9afc130d..fc6312d97 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -25,6 +25,7 @@ require_once __DIR__ . '/../../TestInit.php'; class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase { private $userId, $userId2, $articleId, $articleId2; + private $groupId, $groupId2; public function setUp() { @@ -32,6 +33,15 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase parent::setUp(); } + public function tearDown() + { + parent::tearDown(); + + $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $class->associationMappings['groups']['fetch'] = ClassMetadataInfo::FETCH_LAZY; + $class->associationMappings['articles']['fetch'] = ClassMetadataInfo::FETCH_LAZY; + } + public function testConfigureFilter() { $config = new \Doctrine\ORM\Configuration(); @@ -307,6 +317,109 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase } + private function loadLazyFixtureData() + { + $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $class->associationMappings['articles']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY; + $class->associationMappings['groups']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY; + $this->loadFixtureData(); + } + + private function useCMSArticleTopicFilter() + { + $conf = $this->_em->getConfiguration(); + $conf->addFilter("article_topic", "\Doctrine\Tests\ORM\Functional\CMSArticleTopicFilter"); + $this->_em->enableFilter("article_topic")->setParameter("topic", "Test1", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); + } + + public function testOneToMany_ExtraLazyCountWithFilter() + { + $this->loadLazyFixtureData(); + $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + + $this->assertFalse($user->articles->isInitialized()); + $this->assertEquals(2, count($user->articles)); + + $this->useCMSArticleTopicFilter(); + + $this->assertEquals(1, count($user->articles)); + } + + public function testOneToMany_ExtraLazyContainsWithFilter() + { + $this->loadLazyFixtureData(); + $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + $filteredArticle = $this->_em->find('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId2); + + $this->assertFalse($user->articles->isInitialized()); + $this->assertTrue($user->articles->contains($filteredArticle)); + + $this->useCMSArticleTopicFilter(); + + $this->assertFalse($user->articles->contains($filteredArticle)); + } + + public function testOneToMany_ExtraLazySliceWithFilter() + { + $this->loadLazyFixtureData(); + $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId); + + $this->assertFalse($user->articles->isInitialized()); + $this->assertEquals(2, count($user->articles->slice(0,10))); + + $this->useCMSArticleTopicFilter(); + + $this->assertEquals(1, count($user->articles->slice(0,10))); + } + + private function useCMSGroupPrefixFilter() + { + $conf = $this->_em->getConfiguration(); + $conf->addFilter("group_prefix", "\Doctrine\Tests\ORM\Functional\CMSGroupPrefixFilter"); + $this->_em->enableFilter("group_prefix")->setParameter("prefix", "foo%", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); + } + + public function testManyToMany_ExtraLazyCountWithFilter() + { + $this->loadLazyFixtureData(); + + $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId2); + + $this->assertFalse($user->groups->isInitialized()); + $this->assertEquals(2, count($user->groups)); + + $this->useCMSGroupPrefixFilter(); + + $this->assertEquals(1, count($user->groups)); + } + + public function testManyToMany_ExtraLazyContainsWithFilter() + { + $this->loadLazyFixtureData(); + $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId2); + $filteredArticle = $this->_em->find('Doctrine\Tests\Models\CMS\CmsGroup', $this->groupId2); + + $this->assertFalse($user->groups->isInitialized()); + $this->assertTrue($user->groups->contains($filteredArticle)); + + $this->useCMSGroupPrefixFilter(); + + $this->assertFalse($user->groups->contains($filteredArticle)); + } + + public function testManyToMany_ExtraLazySliceWithFilter() + { + $this->loadLazyFixtureData(); + $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId2); + + $this->assertFalse($user->groups->isInitialized()); + $this->assertEquals(2, count($user->groups->slice(0,10))); + + $this->useCMSGroupPrefixFilter(); + + $this->assertEquals(1, count($user->groups->slice(0,10))); + } + private function loadFixtureData() { $user = new CmsUser; @@ -367,6 +480,8 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->userId2 = $user2->getId(); $this->articleId = $article1->id; $this->articleId2 = $article2->id; + $this->groupId = $group->id; + $this->groupId2 = $group2->id; } } From 63a3fb5ad8f48c78990391b8dbceeeb4f8392f72 Mon Sep 17 00:00:00 2001 From: Alexander Date: Thu, 15 Sep 2011 21:34:51 +0200 Subject: [PATCH 13/85] [DDC-551] Moved SQLFilter logic to a separate FilterCollection class --- lib/Doctrine/ORM/EntityManager.php | 110 ++----------- .../ORM/Persisters/BasicEntityPersister.php | 2 +- .../ORM/Persisters/ManyToManyPersister.php | 2 +- .../ORM/Persisters/OneToManyPersister.php | 2 +- lib/Doctrine/ORM/Query.php | 2 +- lib/Doctrine/ORM/Query/Filter/SQLFilter.php | 2 +- lib/Doctrine/ORM/Query/FilterCollection.php | 153 ++++++++++++++++++ lib/Doctrine/ORM/Query/SqlWalker.php | 12 +- .../Tests/ORM/Functional/SQLFilterTest.php | 69 +++++--- 9 files changed, 223 insertions(+), 131 deletions(-) create mode 100644 lib/Doctrine/ORM/Query/FilterCollection.php diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 96e013b36..dd7b4b218 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -27,7 +27,8 @@ use Closure, Exception, Doctrine\ORM\Mapping\ClassMetadata, Doctrine\ORM\Mapping\ClassMetadataFactory, Doctrine\ORM\Query\ResultSetMapping, - Doctrine\ORM\Proxy\ProxyFactory; + Doctrine\ORM\Proxy\ProxyFactory, + Doctrine\ORM\Query\FilterCollection; /** * The EntityManager is the central access point to ORM functionality. @@ -110,36 +111,12 @@ class EntityManager implements ObjectManager */ private $closed = false; - /* Filters data */ /** - * Instances of enabled filters. + * Collection of query filters. * - * @var array + * @var Doctrine\ORM\Query\FilterCollection */ - private $enabledFilters = array(); - - /** - * @var string The filter hash from the last time the query was parsed. - */ - private $filterHash; - - /* Filter STATES */ - /** - * A filter object is in CLEAN state when it has no changed parameters. - */ - const FILTERS_STATE_CLEAN = 1; - - /** - * A filter object is in DIRTY state when it has changed parameters. - */ - const FILTERS_STATE_DIRTY = 2; - - /** - * @var integer $state The current state of this filter - */ - private $filtersState = self::FILTERS_STATE_CLEAN; - - /* End filters data */ + private $filterCollection; /** * Creates a new EntityManager that operates on the given database connection @@ -771,55 +748,13 @@ class EntityManager implements ObjectManager return new EntityManager($conn, $config, $conn->getEventManager()); } - /** @return SQLFilter[] */ - public function getEnabledFilters() + public function getFilters() { - return $this->enabledFilters; - } - - /** Throws exception if filter does not exist. No-op if the filter is alrady enabled. - * @return SQLFilter */ - public function enableFilter($name) - { - if(null === $filterClass = $this->config->getFilterClassName($name)) { - throw new \InvalidArgumentException("Filter '" . $name . "' does not exist."); + if(null === $this->filterCollection) { + $this->filterCollection = new FilterCollection($this); } - if(!isset($this->enabledFilters[$name])) { - $this->enabledFilters[$name] = new $filterClass($this); - - // Keep the enabled filters sorted for the hash - ksort($this->enabledFilters); - - // Now the filter collection is dirty - $this->filtersState = self::FILTERS_STATE_DIRTY; - } - - return $this->enabledFilters[$name]; - } - - /** Disable the filter, looses the state */ - public function disableFilter($name) - { - // Get the filter to return it - $filter = $this->getFilter($name); - - unset($this->enabledFilters[$name]); - - // Now the filter collection is dirty - $this->filtersState = self::FILTERS_STATE_DIRTY; - - return $filter; - } - - /** throws exception if not in enabled filters */ - public function getFilter($name) - { - if(!isset($this->enabledFilters[$name])) { - throw new \InvalidArgumentException("Filter '" . $name . "' is not enabled."); - } - - return $this->enabledFilters[$name]; + return $this->filterCollection; } /** @@ -827,31 +762,12 @@ class EntityManager implements ObjectManager */ public function isFiltersStateClean() { - return self::FILTERS_STATE_CLEAN === $this->filtersState; + return null === $this->filterCollection + || $this->filterCollection->setFiltersStateDirty(); } - public function setFiltersStateDirty() + public function hasFilters() { - $this->filtersState = self::FILTERS_STATE_DIRTY; - } - - /** - * Generates a string of currently enabled filters to use for the cache id. - * - * @return string - */ - public function getFilterHash() - { - // If there are only clean filters, the previous hash can be returned - if(self::FILTERS_STATE_CLEAN === $this->filtersState) { - return $this->filterHash; - } - - $filterHash = ''; - foreach($this->enabledFilters as $name => $filter) { - $filterHash .= $name . $filter; - } - - return $filterHash; + return null !== $this->filterCollection; } } diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 1d9c03244..4294a7ad8 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -1448,7 +1448,7 @@ class BasicEntityPersister $filterSql = ''; $first = true; - foreach($this->_em->getEnabledFilters() as $filter) { + foreach($this->_em->getFilters()->getEnabledFilters() as $filter) { if("" !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { if ( ! $first) $sql .= ' AND '; else $first = false; $filterSql .= '(' . $filterExpr . ')'; diff --git a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php index ee0b9e1b0..511971a4a 100644 --- a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php @@ -318,7 +318,7 @@ class ManyToManyPersister extends AbstractCollectionPersister // Get the SQL for the filters $filterSql = ''; - foreach($this->_em->getEnabledFilters() as $filter) { + foreach($this->_em->getFilters()->getEnabledFilters() as $filter) { if("" !== $filterExpr = $filter->addFilterConstraint($targetClass, 'te')) { $filterSql .= ' AND (' . $filterExpr . ')'; } diff --git a/lib/Doctrine/ORM/Persisters/OneToManyPersister.php b/lib/Doctrine/ORM/Persisters/OneToManyPersister.php index 633de1d94..1d3b03fae 100644 --- a/lib/Doctrine/ORM/Persisters/OneToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/OneToManyPersister.php @@ -146,7 +146,7 @@ class OneToManyPersister extends AbstractCollectionPersister $sql = "SELECT count(*) FROM " . $targetClass->getQuotedTableName($this->_conn->getDatabasePlatform()) . " t WHERE " . $where; // Apply the filters - foreach($this->_em->getEnabledFilters() as $filter) { + foreach($this->_em->getFilters()->getEnabledFilters() as $filter) { if("" !== $filterExpr = $filter->addFilterConstraint($targetClass, 't')) { $sql .= ' AND (' . $filterExpr . ')'; } diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index 5a4545ad9..977dbabe7 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -561,7 +561,7 @@ final class Query extends AbstractQuery return md5( $this->getDql() . var_export($this->_hints, true) . - $this->_em->getFilterHash() . + ($this->_em->hasFilters() ? $this->_em->getFilters()->getHash() : '') . '&firstResult=' . $this->_firstResult . '&maxResult=' . $this->_maxResults . '&hydrationMode='.$this->_hydrationMode.'DOCTRINE_QUERY_CACHE_SALT' ); diff --git a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php index 5a66fb64d..1ea27df6e 100644 --- a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php +++ b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php @@ -51,7 +51,7 @@ abstract class SQLFilter ksort($this->parameters); // The filter collection of the EM is now dirty - $this->em->setFiltersStateDirty(); + $this->em->getFilters()->setFiltersStateDirty(); return $this; } diff --git a/lib/Doctrine/ORM/Query/FilterCollection.php b/lib/Doctrine/ORM/Query/FilterCollection.php new file mode 100644 index 000000000..c0a408d60 --- /dev/null +++ b/lib/Doctrine/ORM/Query/FilterCollection.php @@ -0,0 +1,153 @@ +. + */ + +namespace Doctrine\ORM\Query; + +use Doctrine\ORM\Configuration, + Doctrine\ORM\EntityManager; + +/** + * Collection class for all the query filters. + * + * @author Alexander + */ +class FilterCollection +{ + private $config; + private $em; + private $filters; + + /** + * Instances of enabled filters. + * + * @var array + */ + private $enabledFilters = array(); + + /** + * @var string The filter hash from the last time the query was parsed. + */ + private $filterHash; + + /* Filter STATES */ + /** + * A filter object is in CLEAN state when it has no changed parameters. + */ + const FILTERS_STATE_CLEAN = 1; + + /** + * A filter object is in DIRTY state when it has changed parameters. + */ + const FILTERS_STATE_DIRTY = 2; + + /** + * @var integer $state The current state of this filter + */ + private $filtersState = self::FILTERS_STATE_CLEAN; + + final public function __construct(EntityManager $em) + { + $this->em = $em; + $this->config = $em->getConfiguration(); + } + + /** @return SQLFilter[] */ + public function getEnabledFilters() + { + return $this->enabledFilters; + } + + /** Throws exception if filter does not exist. No-op if the filter is alrady enabled. + * @return SQLFilter */ + public function enable($name) + { + if(null === $filterClass = $this->config->getFilterClassName($name)) { + throw new \InvalidArgumentException("Filter '" . $name . "' does not exist."); + } + + if(!isset($this->enabledFilters[$name])) { + $this->enabledFilters[$name] = new $filterClass($this->em); + + // Keep the enabled filters sorted for the hash + ksort($this->enabledFilters); + + // Now the filter collection is dirty + $this->filtersState = self::FILTERS_STATE_DIRTY; + } + + return $this->enabledFilters[$name]; + } + + /** Disable the filter, looses the state */ + public function disable($name) + { + // Get the filter to return it + $filter = $this->getFilter($name); + + unset($this->enabledFilters[$name]); + + // Now the filter collection is dirty + $this->filtersState = self::FILTERS_STATE_DIRTY; + + return $filter; + } + + /** throws exception if not in enabled filters */ + public function getFilter($name) + { + if(!isset($this->enabledFilters[$name])) { + throw new \InvalidArgumentException("Filter '" . $name . "' is not enabled."); + } + + return $this->enabledFilters[$name]; + } + + /** + * @return boolean True, if the filter collection is clean. + */ + public function isClean() + { + return self::FILTERS_STATE_CLEAN === $this->filtersState; + } + + /** + * Generates a string of currently enabled filters to use for the cache id. + * + * @return string + */ + public function getHash() + { + // If there are only clean filters, the previous hash can be returned + if(self::FILTERS_STATE_CLEAN === $this->filtersState) { + return $this->filterHash; + } + + $filterHash = ''; + foreach($this->enabledFilters as $name => $filter) { + $filterHash .= $name . $filter; + } + + return $filterHash; + } + + public function setFiltersStateDirty() + { + $this->filtersState = self::FILTERS_STATE_DIRTY; + } +} diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 833f7d4d4..b12b65e17 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -354,11 +354,13 @@ class SqlWalker implements TreeWalker { $filterSql = ''; - $first = true; - foreach($this->_em->getEnabledFilters() as $filter) { - if("" !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { - if ( ! $first) $sql .= ' AND '; else $first = false; - $filterSql .= '(' . $filterExpr . ')'; + if($this->_em->hasFilters()) { + $first = true; + foreach($this->_em->getFilters()->getEnabledFilters() as $filter) { + if("" !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { + if ( ! $first) $sql .= ' AND '; else $first = false; + $filterSql .= '(' . $filterExpr . ')'; + } } } diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index fc6312d97..6954ef489 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -58,17 +58,17 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->configureFilters($em); // Enable an existing filter - $filter = $em->enableFilter("locale"); + $filter = $em->getFilters()->enable("locale"); $this->assertTrue($filter instanceof \Doctrine\Tests\ORM\Functional\MyLocaleFilter); // Enable the filter again - $filter2 = $em->enableFilter("locale"); + $filter2 = $em->getFilters()->enable("locale"); $this->assertEquals($filter, $filter2); // Enable a non-existing filter $exceptionThrown = false; try { - $filter = $em->enableFilter("foo"); + $filter = $em->getFilters()->enable("foo"); } catch (\InvalidArgumentException $e) { $exceptionThrown = true; } @@ -80,14 +80,14 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $em = $this->_getEntityManager(); // No enabled filters - $this->assertEquals(array(), $em->getEnabledFilters()); + $this->assertEquals(array(), $em->getFilters()->getEnabledFilters()); $this->configureFilters($em); - $filter = $em->enableFilter("locale"); - $filter = $em->enableFilter("soft_delete"); + $filter = $em->getFilters()->enable("locale"); + $filter = $em->getFilters()->enable("soft_delete"); // Two enabled filters - $this->assertEquals(2, count($em->getEnabledFilters())); + $this->assertEquals(2, count($em->getFilters()->getEnabledFilters())); } @@ -97,16 +97,16 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->configureFilters($em); // Enable the filter - $filter = $em->enableFilter("locale"); + $filter = $em->getFilters()->enable("locale"); // Disable it - $this->assertEquals($filter, $em->disableFilter("locale")); - $this->assertEquals(0, count($em->getEnabledFilters())); + $this->assertEquals($filter, $em->getFilters()->disable("locale")); + $this->assertEquals(0, count($em->getFilters()->getEnabledFilters())); // Disable a non-existing filter $exceptionThrown = false; try { - $filter = $em->disableFilter("foo"); + $filter = $em->getFilters()->disable("foo"); } catch (\InvalidArgumentException $e) { $exceptionThrown = true; } @@ -115,7 +115,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase // Disable a non-enabled filter $exceptionThrown = false; try { - $filter = $em->disableFilter("locale"); + $filter = $em->getFilters()->disable("locale"); } catch (\InvalidArgumentException $e) { $exceptionThrown = true; } @@ -128,15 +128,15 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->configureFilters($em); // Enable the filter - $filter = $em->enableFilter("locale"); + $filter = $em->getFilters()->enable("locale"); // Get the filter - $this->assertEquals($filter, $em->getFilter("locale")); + $this->assertEquals($filter, $em->getFilters()->getFilter("locale")); // Get a non-enabled filter $exceptionThrown = false; try { - $filter = $em->getFilter("soft_delete"); + $filter = $em->getFilters()->getFilter("soft_delete"); } catch (\InvalidArgumentException $e) { $exceptionThrown = true; } @@ -171,6 +171,19 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase return $em; } + protected function addMockFilterCollection($em) + { + $filterCollection = $this->getMockBuilder('Doctrine\ORM\Query\FilterCollection') + ->disableOriginalConstructor() + ->getMock(); + + $em->expects($this->any()) + ->method('getFilters') + ->will($this->returnValue($filterCollection)); + + return $filterCollection; + } + public function testSQLFilterGetSetParameter() { // Setup mock connection @@ -185,6 +198,11 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase ->method('getConnection') ->will($this->returnValue($conn)); + $filterCollection = $this->addMockFilterCollection($em); + $filterCollection + ->expects($this->once()) + ->method('setFiltersStateDirty'); + $filter = new MyLocaleFilter($em); $filter->setParameter('locale', 'en', \Doctrine\DBAL\Types\Type::STRING); @@ -213,11 +231,14 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testSQLFilterToString() { - $filter = new MyLocaleFilter($this->getMockEntityManager()); + $em = $this->getMockEntityManager(); + $filterCollection = $this->addMockFilterCollection($em); + + $filter = new MyLocaleFilter($em); $filter->setParameter('locale', 'en', \Doctrine\DBAL\Types\Type::STRING); $filter->setParameter('foo', 'bar', \Doctrine\DBAL\Types\Type::STRING); - $filter2 = new MyLocaleFilter($this->getMockEntityManager()); + $filter2 = new MyLocaleFilter($em); $filter2->setParameter('foo', 'bar', \Doctrine\DBAL\Types\Type::STRING); $filter2->setParameter('locale', 'en', \Doctrine\DBAL\Types\Type::STRING); @@ -242,7 +263,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $conf = $this->_em->getConfiguration(); $conf->addFilter("locale", "\Doctrine\Tests\ORM\Functional\MyLocaleFilter"); - $this->_em->enableFilter("locale"); + $this->_em->getFilters()->enable("locale"); $query->getResult(); $this->assertEquals(2, count($cache->getIds())); @@ -259,7 +280,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $conf = $this->_em->getConfiguration(); $conf->addFilter("country", "\Doctrine\Tests\ORM\Functional\CMSCountryFilter"); - $this->_em->enableFilter("country") + $this->_em->getFilters()->enable("country") ->setParameter("country", "en", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); $this->assertNotEquals($firstSQLQuery, $query->getSQL()); @@ -277,7 +298,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $conf = $this->_em->getConfiguration(); $conf->addFilter("country", "\Doctrine\Tests\ORM\Functional\CMSCountryFilter"); - $this->_em->enableFilter("country")->setParameter("country", "Germany", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); + $this->_em->getFilters()->enable("country")->setParameter("country", "Germany", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); // We get one user after enabling the filter $this->assertEquals(1, count($query->getResult())); @@ -293,7 +314,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $conf = $this->_em->getConfiguration(); $conf->addFilter("group_prefix", "\Doctrine\Tests\ORM\Functional\CMSGroupPrefixFilter"); - $this->_em->enableFilter("group_prefix")->setParameter("prefix", "bar_%", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); + $this->_em->getFilters()->enable("group_prefix")->setParameter("prefix", "bar_%", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); // We get one user after enabling the filter $this->assertEquals(1, count($query->getResult())); @@ -310,7 +331,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $conf = $this->_em->getConfiguration(); $conf->addFilter("group_prefix", "\Doctrine\Tests\ORM\Functional\CMSGroupPrefixFilter"); - $this->_em->enableFilter("group_prefix")->setParameter("prefix", "bar_%", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); + $this->_em->getFilters()->enable("group_prefix")->setParameter("prefix", "bar_%", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); // We get one user after enabling the filter $this->assertEquals(1, count($query->getResult())); @@ -329,7 +350,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase { $conf = $this->_em->getConfiguration(); $conf->addFilter("article_topic", "\Doctrine\Tests\ORM\Functional\CMSArticleTopicFilter"); - $this->_em->enableFilter("article_topic")->setParameter("topic", "Test1", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); + $this->_em->getFilters()->enable("article_topic")->setParameter("topic", "Test1", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); } public function testOneToMany_ExtraLazyCountWithFilter() @@ -376,7 +397,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase { $conf = $this->_em->getConfiguration(); $conf->addFilter("group_prefix", "\Doctrine\Tests\ORM\Functional\CMSGroupPrefixFilter"); - $this->_em->enableFilter("group_prefix")->setParameter("prefix", "foo%", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); + $this->_em->getFilters()->enable("group_prefix")->setParameter("prefix", "foo%", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); } public function testManyToMany_ExtraLazyCountWithFilter() From 58b381bf24087d18e0952d8c3267a4f1cbc395dc Mon Sep 17 00:00:00 2001 From: Alexander Date: Sat, 15 Oct 2011 22:31:20 +0200 Subject: [PATCH 14/85] [DDC-551] use isClean to check the filterCollection state.. --- lib/Doctrine/ORM/EntityManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index fba3e2de4..c5e89c9ae 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -764,7 +764,7 @@ class EntityManager implements ObjectManager public function isFiltersStateClean() { return null === $this->filterCollection - || $this->filterCollection->setFiltersStateDirty(); + || $this->filterCollection->isClean(); } public function hasFilters() From 9ccce8ed742067270a5ec0436cd0d46127296633 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 26 Oct 2011 16:11:27 +0200 Subject: [PATCH 15/85] [DDC-551] Add filters to eagerly joined entities in the persisters --- lib/Doctrine/ORM/Persisters/BasicEntityPersister.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 51cce15a4..737a7c1de 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -1020,10 +1020,17 @@ class BasicEntityPersister $this->_selectJoinSql .= ' AND '; } + $tableAlias = $this->_getSQLTableAlias($assoc['targetEntity'], $assocAlias); $this->_selectJoinSql .= $this->_getSQLTableAlias($assoc['sourceEntity']) . '.' . $sourceCol . ' = ' - . $this->_getSQLTableAlias($assoc['targetEntity'], $assocAlias) . '.' . $targetCol . ' '; + . $tableAlias . '.' . $targetCol . ' '; + $first = false; } + + // Add filter SQL + if('' !== $filterSql = $this->generateFilterConditionSQL($eagerEntity, $tableAlias)) { + $this->_selectJoinSql .= ' AND ' . $filterSql; + } } else { $eagerEntity = $this->_em->getClassMetadata($assoc['targetEntity']); $owningAssoc = $eagerEntity->getAssociationMapping($assoc['mappedBy']); From 53055f1fb2f0d9f825876b73ffaf403ebc7ff8fe Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 1 Nov 2011 12:36:06 +0100 Subject: [PATCH 16/85] [DDC-551] Fixed a bug in the sql generation for filters --- lib/Doctrine/ORM/Persisters/BasicEntityPersister.php | 2 +- lib/Doctrine/ORM/Query/SqlWalker.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 737a7c1de..7b234ca58 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -1529,7 +1529,7 @@ class BasicEntityPersister $first = true; foreach($this->_em->getFilters()->getEnabledFilters() as $filter) { if("" !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { - if ( ! $first) $sql .= ' AND '; else $first = false; + if ( ! $first) $filterSql .= ' AND '; else $first = false; $filterSql .= '(' . $filterExpr . ')'; } } diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 485708386..fa994da2c 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -358,7 +358,7 @@ class SqlWalker implements TreeWalker $first = true; foreach($this->_em->getFilters()->getEnabledFilters() as $filter) { if("" !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { - if ( ! $first) $sql .= ' AND '; else $first = false; + if ( ! $first) $filterSql .= ' AND '; else $first = false; $filterSql .= '(' . $filterExpr . ')'; } } From 5b73f1bd826858dcee43dacdd6bcdc8ee53f7639 Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Wed, 30 Nov 2011 09:57:54 -0500 Subject: [PATCH 17/85] Improved code readability. Improved performance. --- .../ORM/Internal/CommitOrderCalculator.php | 12 +- .../ORM/Internal/Hydration/ObjectHydrator.php | 5 - lib/Doctrine/ORM/PersistentCollection.php | 14 +- lib/Doctrine/ORM/Query/Lexer.php | 96 ++--- lib/Doctrine/ORM/Query/Parser.php | 337 ++++++++++-------- 5 files changed, 250 insertions(+), 214 deletions(-) diff --git a/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php b/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php index 8997b1ea5..aad34e993 100644 --- a/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php +++ b/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php @@ -23,8 +23,9 @@ namespace Doctrine\ORM\Internal; * The CommitOrderCalculator is used by the UnitOfWork to sort out the * correct order in which changes to entities need to be persisted. * - * @since 2.0 - * @author Roman Borschel + * @since 2.0 + * @author Roman Borschel + * @author Guilherme Blanco */ class CommitOrderCalculator { @@ -60,10 +61,9 @@ class CommitOrderCalculator { // Check whether we need to do anything. 0 or 1 node is easy. $nodeCount = count($this->_classes); - if ($nodeCount == 0) { - return array(); - } else if ($nodeCount == 1) { - return array_values($this->_classes); + + if ($nodeCount <= 1) { + return ($nodeCount == 1) ? array_values($this->_classes) : array(); } // Init diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index ced83b126..36dbfa46a 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -36,11 +36,6 @@ use PDO, * @author Guilherme Blanco * * @internal Highly performance-sensitive code. - * - * @todo General behavior is "wrong" if you define an alias to selected IdentificationVariable. - * Example: SELECT u AS user FROM User u - * The result should contains an array where each array index is an array: array('user' => [User object]) - * Problem must be solved somehow by removing the isMixed in ResultSetMapping */ class ObjectHydrator extends AbstractHydrator { diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index 53bff7066..d8a53f2f1 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -164,7 +164,7 @@ final class PersistentCollection implements Collection // If _backRefFieldName is set and its a one-to-many association, // we need to set the back reference. - if ($this->backRefFieldName && $this->association['type'] == ClassMetadata::ONE_TO_MANY) { + if ($this->backRefFieldName && $this->association['type'] === ClassMetadata::ONE_TO_MANY) { // Set back reference to owner $this->typeClass->reflFields[$this->backRefFieldName]->setValue( $element, $this->owner @@ -189,7 +189,7 @@ final class PersistentCollection implements Collection // If _backRefFieldName is set, then the association is bidirectional // and we need to set the back reference. - if ($this->backRefFieldName && $this->association['type'] == ClassMetadata::ONE_TO_MANY) { + if ($this->backRefFieldName && $this->association['type'] === ClassMetadata::ONE_TO_MANY) { // Set back reference to owner $this->typeClass->reflFields[$this->backRefFieldName]->setValue( $element, $this->owner @@ -304,7 +304,7 @@ final class PersistentCollection implements Collection if ($this->association !== null && $this->association['isOwningSide'] && - $this->association['type'] == ClassMetadata::MANY_TO_MANY && + $this->association['type'] === ClassMetadata::MANY_TO_MANY && $this->em->getClassMetadata(get_class($this->owner))->isChangeTrackingNotify()) { $this->em->getUnitOfWork()->scheduleForDirtyCheck($this->owner); } @@ -425,7 +425,7 @@ final class PersistentCollection implements Collection $this->changed(); if ($this->association !== null && - $this->association['type'] == ClassMetadata::ONE_TO_MANY && + $this->association['type'] === ClassMetadata::ONE_TO_MANY && $this->association['orphanRemoval']) { $this->em->getUnitOfWork()->scheduleOrphanRemoval($element); } @@ -448,7 +448,7 @@ final class PersistentCollection implements Collection */ public function contains($element) { - if ( ! $this->initialized && $this->association['fetch'] == Mapping\ClassMetadataInfo::FETCH_EXTRA_LAZY) { + if ( ! $this->initialized && $this->association['fetch'] === Mapping\ClassMetadataInfo::FETCH_EXTRA_LAZY) { $persister = $this->em->getUnitOfWork()->getCollectionPersister($this->association); return $this->coll->contains($element) || $persister->contains($this, $element); @@ -514,7 +514,7 @@ final class PersistentCollection implements Collection */ public function count() { - if ( ! $this->initialized && $this->association['fetch'] == Mapping\ClassMetadataInfo::FETCH_EXTRA_LAZY) { + if ( ! $this->initialized && $this->association['fetch'] === Mapping\ClassMetadataInfo::FETCH_EXTRA_LAZY) { $persister = $this->em->getUnitOfWork()->getCollectionPersister($this->association); return $persister->count($this) + ($this->isDirty ? $this->coll->count() : 0); @@ -630,7 +630,7 @@ final class PersistentCollection implements Collection $uow = $this->em->getUnitOfWork(); - if ($this->association['type'] == ClassMetadata::ONE_TO_MANY && $this->association['orphanRemoval']) { + if ($this->association['type'] === ClassMetadata::ONE_TO_MANY && $this->association['orphanRemoval']) { // we need to initialize here, as orphan removal acts like implicit cascadeRemove, // hence for event listeners we need the objects in memory. $this->initialize(); diff --git a/lib/Doctrine/ORM/Query/Lexer.php b/lib/Doctrine/ORM/Query/Lexer.php index 00fcffd8c..1eef6afeb 100644 --- a/lib/Doctrine/ORM/Query/Lexer.php +++ b/lib/Doctrine/ORM/Query/Lexer.php @@ -49,7 +49,7 @@ class Lexer extends \Doctrine\Common\Lexer const T_PLUS = 17; const T_OPEN_CURLY_BRACE = 18; const T_CLOSE_CURLY_BRACE = 19; - + // All tokens that are also identifiers should be >= 100 const T_IDENTIFIER = 100; const T_ALL = 101; @@ -133,7 +133,7 @@ class Lexer extends \Doctrine\Common\Lexer '\?[0-9]*|:[a-z]{1}[a-z0-9_]{0,}' ); } - + /** * @inheritdoc */ @@ -149,50 +149,58 @@ class Lexer extends \Doctrine\Common\Lexer { $type = self::T_NONE; - // Recognizing numeric values - if (is_numeric($value)) { - return (strpos($value, '.') !== false || stripos($value, 'e') !== false) - ? self::T_FLOAT : self::T_INTEGER; - } - - // Differentiate between quoted names, identifiers, input parameters and symbols - if ($value[0] === "'") { - $value = str_replace("''", "'", substr($value, 1, strlen($value) - 2)); - return self::T_STRING; - } else if (ctype_alpha($value[0]) || $value[0] === '_') { - $name = 'Doctrine\ORM\Query\Lexer::T_' . strtoupper($value); - - if (defined($name)) { - $type = constant($name); - - if ($type > 100) { - return $type; + switch (true) { + // Recognize numeric values + case (is_numeric($value)): + if (strpos($value, '.') !== false || stripos($value, 'e') !== false) { + return self::T_FLOAT; } - } - return self::T_IDENTIFIER; - } else if ($value[0] === '?' || $value[0] === ':') { - return self::T_INPUT_PARAMETER; - } else { - switch ($value) { - case '.': return self::T_DOT; - case ',': return self::T_COMMA; - case '(': return self::T_OPEN_PARENTHESIS; - case ')': return self::T_CLOSE_PARENTHESIS; - case '=': return self::T_EQUALS; - case '>': return self::T_GREATER_THAN; - case '<': return self::T_LOWER_THAN; - case '+': return self::T_PLUS; - case '-': return self::T_MINUS; - case '*': return self::T_MULTIPLY; - case '/': return self::T_DIVIDE; - case '!': return self::T_NEGATE; - case '{': return self::T_OPEN_CURLY_BRACE; - case '}': return self::T_CLOSE_CURLY_BRACE; - default: - // Do nothing - break; - } + return self::T_INTEGER; + + // Recognize quoted strings + case ($value[0] === "'"): + $value = str_replace("''", "'", substr($value, 1, strlen($value) - 2)); + + return self::T_STRING; + + // Recognize identifiers + case (ctype_alpha($value[0]) || $value[0] === '_'): + $name = 'Doctrine\ORM\Query\Lexer::T_' . strtoupper($value); + + if (defined($name)) { + $type = constant($name); + + if ($type > 100) { + return $type; + } + } + + return self::T_IDENTIFIER; + + // Recognize input parameters + case ($value[0] === '?' || $value[0] === ':'): + return self::T_INPUT_PARAMETER; + + // Recognize symbols + case ($value === '.'): return self::T_DOT; + case ($value === ','): return self::T_COMMA; + case ($value === '('): return self::T_OPEN_PARENTHESIS; + case ($value === ')'): return self::T_CLOSE_PARENTHESIS; + case ($value === '='): return self::T_EQUALS; + case ($value === '>'): return self::T_GREATER_THAN; + case ($value === '<'): return self::T_LOWER_THAN; + case ($value === '+'): return self::T_PLUS; + case ($value === '-'): return self::T_MINUS; + case ($value === '*'): return self::T_MULTIPLY; + case ($value === '/'): return self::T_DIVIDE; + case ($value === '!'): return self::T_NEGATE; + case ($value === '{'): return self::T_OPEN_CURLY_BRACE; + case ($value === '}'): return self::T_CLOSE_CURLY_BRACE; + + // Default + default: + // Do nothing } return $type; diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 1a34963f2..a3725eb8d 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -677,13 +677,10 @@ class Parser } // Build the error message - $semanticalError = 'Invalid PathExpression. '; - - if (count($expectedStringTypes) == 1) { - $semanticalError .= 'Must be a ' . $expectedStringTypes[0] . '.'; - } else { - $semanticalError .= implode(' or ', $expectedStringTypes) . ' expected.'; - } + $semanticalError = 'Invalid PathExpression. '; + $semanticalError .= (count($expectedStringTypes) == 1) + ? 'Must be a ' . $expectedStringTypes[0] . '.' + : implode(' or ', $expectedStringTypes) . ' expected.'; $this->semanticalError($semanticalError, $deferredItem['token']); } @@ -1866,53 +1863,78 @@ class Parser $expression = null; $identVariable = null; $peek = $this->_lexer->glimpse(); + $lookaheadType = $this->_lexer->lookahead['type']; - if ($this->_lexer->lookahead['type'] === Lexer::T_IDENTIFIER && $peek['type'] === Lexer::T_DOT) { + switch (true) { // ScalarExpression (u.name) - $expression = $this->ScalarExpression(); - } else if ($this->_lexer->lookahead['type'] === Lexer::T_IDENTIFIER && $peek['type'] !== Lexer::T_OPEN_PARENTHESIS) { - // IdentificationVariable (u) - $expression = $identVariable = $this->IdentificationVariable(); - } else if (in_array($this->_lexer->lookahead['type'], array(Lexer::T_CASE, Lexer::T_COALESCE, Lexer::T_NULLIF))) { - // CaseExpression (CASE ... or NULLIF(...) or COALESCE(...)) - $expression = $this->CaseExpression(); - } else if ($this->_isFunction()) { - // DQL Function (SUM(u.value) or SUM(u.value) + 1) - $this->_lexer->peek(); // "(" - - $lookaheadType = $this->_lexer->lookahead['type']; - $beyond = $this->_peekBeyondClosingParenthesis(); - - if ($this->_isMathOperator($beyond)) { - // SUM(u.id) + COUNT(u.id) + case ($lookaheadType === Lexer::T_IDENTIFIER && $peek['type'] === Lexer::T_DOT): $expression = $this->ScalarExpression(); - } else if ($this->_isAggregateFunction($this->_lexer->lookahead['type'])) { - // COUNT(u.id) - $expression = $this->AggregateExpression(); - } else { - // SUM(u.id) - $expression = $this->FunctionDeclaration(); - } - } else if ($this->_lexer->lookahead['type'] === Lexer::T_PARTIAL) { + break; + + // IdentificationVariable (u) + case ($lookaheadType === Lexer::T_IDENTIFIER && $peek['type'] !== Lexer::T_OPEN_PARENTHESIS): + $expression = $identVariable = $this->IdentificationVariable(); + break; + + // CaseExpression (CASE ... or NULLIF(...) or COALESCE(...)) + case ($lookaheadType === Lexer::T_CASE): + case ($lookaheadType === Lexer::T_COALESCE): + case ($lookaheadType === Lexer::T_NULLIF): + $expression = $this->CaseExpression(); + break; + + // DQL Function (SUM(u.value) or SUM(u.value) + 1) + case ($this->_isFunction()): + $this->_lexer->peek(); // "(" + + switch (true) { + case ($this->_isMathOperator($this->_peekBeyondClosingParenthesis())): + // SUM(u.id) + COUNT(u.id) + $expression = $this->ScalarExpression(); + break; + + case ($this->_isAggregateFunction($lookaheadType)): + // COUNT(u.id) + $expression = $this->AggregateExpression(); + break; + + default: + // IDENTITY(u) + $expression = $this->FunctionDeclaration(); + break; + } + + break; + // PartialObjectExpression (PARTIAL u.{id, name}) - $expression = $this->PartialObjectExpression(); - $identVariable = $expression->identificationVariable; - } else if ($this->_lexer->lookahead['type'] === Lexer::T_OPEN_PARENTHESIS && $peek['type'] === Lexer::T_SELECT) { + case ($lookaheadType === Lexer::T_PARTIAL): + $expression = $this->PartialObjectExpression(); + $identVariable = $expression->identificationVariable; + break; + // Subselect - $this->match(Lexer::T_OPEN_PARENTHESIS); - $expression = $this->Subselect(); - $this->match(Lexer::T_CLOSE_PARENTHESIS); - } else if (in_array($this->_lexer->lookahead['type'], array(Lexer::T_OPEN_PARENTHESIS, Lexer::T_INTEGER, Lexer::T_FLOAT, Lexer::T_STRING))) { + case ($lookaheadType === Lexer::T_OPEN_PARENTHESIS && $peek['type'] === Lexer::T_SELECT): + $this->match(Lexer::T_OPEN_PARENTHESIS); + $expression = $this->Subselect(); + $this->match(Lexer::T_CLOSE_PARENTHESIS); + break; + // Shortcut: ScalarExpression => SimpleArithmeticExpression - $expression = $this->SimpleArithmeticExpression(); - } else if (in_array($this->_lexer->lookahead['type'], array(Lexer::T_PLUS, Lexer::T_MINUS))) { - // SimpleArithmeticExpression : (- u.value ) or ( + u.value ) - $expression = $this->SimpleArithmeticExpression(); - } else { - $this->syntaxError( - 'IdentificationVariable | ScalarExpression | AggregateExpression | FunctionDeclaration | PartialObjectExpression | "(" Subselect ")" | CaseExpression', - $this->_lexer->lookahead - ); + case ($lookaheadType === Lexer::T_OPEN_PARENTHESIS): + case ($lookaheadType === Lexer::T_INTEGER): + case ($lookaheadType === Lexer::T_STRING): + case ($lookaheadType === Lexer::T_FLOAT): + // SimpleArithmeticExpression : (- u.value ) or ( + u.value ) + case ($lookaheadType === Lexer::T_MINUS): + case ($lookaheadType === Lexer::T_PLUS): + $expression = $this->SimpleArithmeticExpression(); + break; + + default: + $this->syntaxError( + 'IdentificationVariable | ScalarExpression | AggregateExpression | FunctionDeclaration | PartialObjectExpression | "(" Subselect ")" | CaseExpression', + $this->_lexer->lookahead + ); } // [["AS"] ["HIDDEN"] AliasResultVariable] @@ -1965,25 +1987,41 @@ class Parser { $peek = $this->_lexer->glimpse(); - if ($peek['value'] != '(' && $this->_lexer->lookahead['type'] === Lexer::T_IDENTIFIER) { - // SingleValuedPathExpression | IdentificationVariable - $expression = ($peek['value'] == '.') - ? $this->StateFieldPathExpression() - : $this->IdentificationVariable(); + switch ($this->_lexer->lookahead['type']) { + case Lexer::T_IDENTIFIER: + switch (true) { + case ($peek['type'] === Lexer::T_DOT): + $expression = $this->StateFieldPathExpression(); + + return new AST\SimpleSelectExpression($expression); + + case ($peek['type'] !== Lexer::T_OPEN_PARENTHESIS): + $expression = $this->IdentificationVariable(); + + return new AST\SimpleSelectExpression($expression); + + default: + // Do nothing + } + break; + + case Lexer::T_OPEN_PARENTHESIS: + if ($peek['type'] !== Lexer::T_SELECT) { + // Shortcut: ScalarExpression => SimpleArithmeticExpression + $expression = $this->SimpleArithmeticExpression(); + + return new AST\SimpleSelectExpression($expression); + } - return new AST\SimpleSelectExpression($expression); - } else if ($this->_lexer->lookahead['value'] == '(') { - if ($peek['type'] == Lexer::T_SELECT) { // Subselect $this->match(Lexer::T_OPEN_PARENTHESIS); $expression = $this->Subselect(); $this->match(Lexer::T_CLOSE_PARENTHESIS); - } else { - // Shortcut: ScalarExpression => SimpleArithmeticExpression - $expression = $this->SimpleArithmeticExpression(); - } - return new AST\SimpleSelectExpression($expression); + return new AST\SimpleSelectExpression($expression); + + default: + // Do nothing } $this->_lexer->peek(); @@ -2099,27 +2137,26 @@ class Parser { $condPrimary = new AST\ConditionalPrimary; - if ($this->_lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) { - // Peek beyond the matching closing paranthesis ')' - $peek = $this->_peekBeyondClosingParenthesis(); - - if (in_array($peek['value'], array("=", "<", "<=", "<>", ">", ">=", "!=")) || - $peek['type'] === Lexer::T_NOT || - $peek['type'] === Lexer::T_BETWEEN || - $peek['type'] === Lexer::T_LIKE || - $peek['type'] === Lexer::T_IN || - $peek['type'] === Lexer::T_IS || - $peek['type'] === Lexer::T_EXISTS) { - $condPrimary->simpleConditionalExpression = $this->SimpleConditionalExpression(); - } else { - $this->match(Lexer::T_OPEN_PARENTHESIS); - $condPrimary->conditionalExpression = $this->ConditionalExpression(); - $this->match(Lexer::T_CLOSE_PARENTHESIS); - } - } else { + if ( ! $this->_lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) { $condPrimary->simpleConditionalExpression = $this->SimpleConditionalExpression(); + + return $condPrimary; } + // Peek beyond the matching closing paranthesis ')' + $peek = $this->_peekBeyondClosingParenthesis(); + + if (in_array($peek['value'], array("=", "<", "<=", "<>", ">", ">=", "!=")) || + in_array($peek['type'], array(Lexer::T_NOT, Lexer::T_BETWEEN, Lexer::T_LIKE, Lexer::T_IN, Lexer::T_IS, Lexer::T_EXISTS))) { + $condPrimary->simpleConditionalExpression = $this->SimpleConditionalExpression(); + + return $condPrimary; + } + + $this->match(Lexer::T_OPEN_PARENTHESIS); + $condPrimary->conditionalExpression = $this->ConditionalExpression(); + $this->match(Lexer::T_CLOSE_PARENTHESIS); + return $condPrimary; } @@ -2132,10 +2169,10 @@ class Parser */ public function SimpleConditionalExpression() { + $token = $this->_lexer->lookahead; + if ($this->_lexer->isNextToken(Lexer::T_NOT)) { $token = $this->_lexer->glimpse(); - } else { - $token = $this->_lexer->lookahead; } if ($token['type'] === Lexer::T_EXISTS) { @@ -2464,9 +2501,9 @@ class Parser } return $this->FunctionDeclaration(); - } else { - return $this->Literal(); } + + return $this->Literal(); } } @@ -2498,30 +2535,46 @@ class Parser */ public function StringPrimary() { - if ($this->_lexer->isNextToken(Lexer::T_IDENTIFIER)) { - $peek = $this->_lexer->glimpse(); + $lookaheadType = $this->_lexer->lookahead['type']; + + switch ($lookaheadType) { + case Lexer::T_IDENTIFIER: + $peek = $this->_lexer->glimpse(); + + if ($peek['value'] == '.') { + return $this->StateFieldPathExpression(); + } + + if ($peek['value'] == '(') { + // do NOT directly go to FunctionsReturningString() because it doesnt check for custom functions. + return $this->FunctionDeclaration(); + } - if ($peek['value'] == '.') { - return $this->StateFieldPathExpression(); - } else if ($peek['value'] == '(') { - // do NOT directly go to FunctionsReturningString() because it doesnt check for custom functions. - return $this->FunctionDeclaration(); - } else { $this->syntaxError("'.' or '('"); - } - } else if ($this->_lexer->isNextToken(Lexer::T_STRING)) { - $this->match(Lexer::T_STRING); + break; - return $this->_lexer->token['value']; - } else if ($this->_lexer->isNextToken(Lexer::T_INPUT_PARAMETER)) { - return $this->InputParameter(); - } else if ($this->_isAggregateFunction($this->_lexer->lookahead['type'])) { - return $this->AggregateExpression(); - } else if (in_array($this->_lexer->lookahead['type'], array(Lexer::T_CASE, Lexer::T_COALESCE, Lexer::T_NULLIF))) { - return $this->CaseExpression(); + case Lexer::T_STRING: + $this->match(Lexer::T_STRING); + + return $this->_lexer->token['value']; + + case Lexer::T_INPUT_PARAMETER: + return $this->InputParameter(); + + case Lexer::T_CASE: + case Lexer::T_COALESCE: + case Lexer::T_NULLIF: + return $this->CaseExpression(); + + default: + if ($this->_isAggregateFunction($lookaheadType)) { + return $this->AggregateExpression(); + } } - $this->syntaxError('StateFieldPathExpression | string | InputParameter | FunctionsReturningStrings | AggregateExpression'); + $this->syntaxError( + 'StateFieldPathExpression | string | InputParameter | FunctionsReturningStrings | AggregateExpression' + ); } /** @@ -2564,40 +2617,28 @@ class Parser */ public function AggregateExpression() { + $lookaheadType = $this->_lexer->lookahead['type']; $isDistinct = false; - $functionName = ''; - if ($this->_lexer->isNextToken(Lexer::T_COUNT)) { - $this->match(Lexer::T_COUNT); - $functionName = $this->_lexer->token['value']; - $this->match(Lexer::T_OPEN_PARENTHESIS); - - if ($this->_lexer->isNextToken(Lexer::T_DISTINCT)) { - $this->match(Lexer::T_DISTINCT); - $isDistinct = true; - } - - $pathExp = $this->SingleValuedPathExpression(); - $this->match(Lexer::T_CLOSE_PARENTHESIS); - } else { - if ($this->_lexer->isNextToken(Lexer::T_AVG)) { - $this->match(Lexer::T_AVG); - } else if ($this->_lexer->isNextToken(Lexer::T_MAX)) { - $this->match(Lexer::T_MAX); - } else if ($this->_lexer->isNextToken(Lexer::T_MIN)) { - $this->match(Lexer::T_MIN); - } else if ($this->_lexer->isNextToken(Lexer::T_SUM)) { - $this->match(Lexer::T_SUM); - } else { - $this->syntaxError('One of: MAX, MIN, AVG, SUM, COUNT'); - } - - $functionName = $this->_lexer->token['value']; - $this->match(Lexer::T_OPEN_PARENTHESIS); - $pathExp = $this->SimpleArithmeticExpression(); - $this->match(Lexer::T_CLOSE_PARENTHESIS); + if ( ! in_array($lookaheadType, array(Lexer::T_COUNT, Lexer::T_AVG, Lexer::T_MAX, Lexer::T_MIN, Lexer::T_SUM))) { + $this->syntaxError('One of: MAX, MIN, AVG, SUM, COUNT'); } + $this->match($lookaheadType); + $functionName = $this->_lexer->token['value']; + $this->match(Lexer::T_OPEN_PARENTHESIS); + + if ($this->_lexer->isNextToken(Lexer::T_DISTINCT)) { + $this->match(Lexer::T_DISTINCT); + $isDistinct = true; + } + + $pathExp = ($lookaheadType === Lexer::T_COUNT) + ? $this->SingleValuedPathExpression() + : $this->SimpleArithmeticExpression(); + + $this->match(Lexer::T_CLOSE_PARENTHESIS); + return new AST\AggregateExpression($functionName, $pathExp, $isDistinct); } @@ -2608,24 +2649,19 @@ class Parser */ public function QuantifiedExpression() { - $type = ''; + $lookaheadType = $this->_lexer->lookahead['type']; + $value = $this->_lexer->lookahead['value']; - if ($this->_lexer->isNextToken(Lexer::T_ALL)) { - $this->match(Lexer::T_ALL); - $type = 'ALL'; - } else if ($this->_lexer->isNextToken(Lexer::T_ANY)) { - $this->match(Lexer::T_ANY); - $type = 'ANY'; - } else if ($this->_lexer->isNextToken(Lexer::T_SOME)) { - $this->match(Lexer::T_SOME); - $type = 'SOME'; - } else { + if ( ! in_array($lookaheadType, array(Lexer::T_ALL, Lexer::T_ANY, Lexer::T_SOME))) { $this->syntaxError('ALL, ANY or SOME'); } + $this->match($lookaheadType); $this->match(Lexer::T_OPEN_PARENTHESIS); + $qExpr = new AST\QuantifiedExpression($this->Subselect()); - $qExpr->type = $type; + $qExpr->type = $value; + $this->match(Lexer::T_CLOSE_PARENTHESIS); return $qExpr; @@ -2666,14 +2702,11 @@ class Parser { $peek = $this->_lexer->glimpse(); - $leftExpr = $this->ArithmeticExpression(); - $operator = $this->ComparisonOperator(); - - if ($this->_isNextAllAnySome()) { - $rightExpr = $this->QuantifiedExpression(); - } else { - $rightExpr = $this->ArithmeticExpression(); - } + $leftExpr = $this->ArithmeticExpression(); + $operator = $this->ComparisonOperator(); + $rightExpr = ($this->_isNextAllAnySome()) + ? $this->QuantifiedExpression() + : $this->ArithmeticExpression(); return new AST\ComparisonExpression($leftExpr, $operator, $rightExpr); } From 4c94a7ccc5404f1288603c341ddab02c6dd78ba3 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 30 Nov 2011 16:40:55 +0100 Subject: [PATCH 18/85] [DDC-551] Various minor fixes after merge and cleanup --- .../ORM/Persisters/BasicEntityPersister.php | 5 +- .../Persisters/JoinedSubclassPersister.php | 4 +- lib/Doctrine/ORM/Query/Filter/SQLFilter.php | 10 +-- lib/Doctrine/ORM/Query/FilterCollection.php | 71 ++++++++++++++----- .../ORM/Functional/Ticket/DDC633Test.php | 2 +- 5 files changed, 64 insertions(+), 28 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 77cab7c5b..1f4550d8c 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -1020,6 +1020,7 @@ class BasicEntityPersister if ($assoc['isOwningSide']) { $this->_selectJoinSql .= ' ' . $this->getJoinSQLForJoinColumns($assoc['joinColumns']); + $this->_selectJoinSql .= ' ' . $eagerEntity->getQuotedTableName($this->_platform) . ' ' . $this->_getSQLTableAlias($eagerEntity->name, $assocAlias) .' ON '; foreach ($assoc['sourceToTargetKeyColumns'] AS $sourceCol => $targetCol) { if ( ! $first) { @@ -1027,7 +1028,7 @@ class BasicEntityPersister } $tableAlias = $this->_getSQLTableAlias($assoc['targetEntity'], $assocAlias); $this->_selectJoinSql .= $this->_getSQLTableAlias($assoc['sourceEntity']) . '.' . $sourceCol . ' = ' - . $tableAlias . '.' . $targetCol . ' '; + . $tableAlias . '.' . $targetCol; $first = false; } @@ -1536,7 +1537,7 @@ class BasicEntityPersister $alias = $this->_getSQLTableAlias($this->_class->name); - $sql = 'SELECT 1' + $sql = 'SELECT 1 ' . $this->getLockTablesSql($alias) . ' WHERE ' . $this->_getSelectConditionSQL($criteria); diff --git a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php index fb60d5e32..d7e79e285 100644 --- a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php @@ -401,10 +401,10 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister * * @return string */ - public function getLockTablesSql() + public function getLockTablesSql($alias = null) { $idColumns = $this->_class->getIdentifierColumnNames(); - $baseTableAlias = $this->_getSQLTableAlias($this->_class->name); + $baseTableAlias = null !== $alias ? $alias : $this->_getSQLTableAlias($this->_class->name); // INNER JOIN parent tables $joinSql = ''; diff --git a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php index 1ea27df6e..81cae335a 100644 --- a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php +++ b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php @@ -42,7 +42,7 @@ abstract class SQLFilter $this->em = $em; } - final function setParameter($name, $value, $type) + final public function setParameter($name, $value, $type) { // @todo: check for a valid type? $this->parameters[$name] = array('value' => $value, 'type' => $type); @@ -56,7 +56,7 @@ abstract class SQLFilter return $this; } - final function getParameter($name) + final public function getParameter($name) { if(!isset($this->parameters[$name])) { throw new \InvalidArgumentException("Parameter '" . $name . "' does not exist."); @@ -65,13 +65,13 @@ abstract class SQLFilter return $this->em->getConnection()->quote($this->parameters[$name]['value'], $this->parameters[$name]['type']); } - final function __toString() + final public function __toString() { return serialize($this->parameters); } /** - * @return string The contstraint if there is one, empty string otherwise + * @return string The constraint if there is one, empty string otherwise */ - abstract function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias); + abstract public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias); } diff --git a/lib/Doctrine/ORM/Query/FilterCollection.php b/lib/Doctrine/ORM/Query/FilterCollection.php index c0a408d60..72b5a757c 100644 --- a/lib/Doctrine/ORM/Query/FilterCollection.php +++ b/lib/Doctrine/ORM/Query/FilterCollection.php @@ -29,6 +29,17 @@ use Doctrine\ORM\Configuration, */ class FilterCollection { + /* Filter STATES */ + /** + * A filter object is in CLEAN state when it has no changed parameters. + */ + const FILTERS_STATE_CLEAN = 1; + + /** + * A filter object is in DIRTY state when it has changed parameters. + */ + const FILTERS_STATE_DIRTY = 2; + private $config; private $em; private $filters; @@ -45,36 +56,41 @@ class FilterCollection */ private $filterHash; - /* Filter STATES */ /** - * A filter object is in CLEAN state when it has no changed parameters. - */ - const FILTERS_STATE_CLEAN = 1; - - /** - * A filter object is in DIRTY state when it has changed parameters. - */ - const FILTERS_STATE_DIRTY = 2; - - /** - * @var integer $state The current state of this filter + * @var integer $state The current state of this filter */ private $filtersState = self::FILTERS_STATE_CLEAN; - final public function __construct(EntityManager $em) + /** + * Constructor. + * + * @param EntityManager $em + */ + public function __construct(EntityManager $em) { $this->em = $em; $this->config = $em->getConfiguration(); } - /** @return SQLFilter[] */ + /** + * Get all the enabled filters. + * + * @return array The enabled filters. + */ public function getEnabledFilters() { return $this->enabledFilters; } - /** Throws exception if filter does not exist. No-op if the filter is alrady enabled. - * @return SQLFilter */ + /** + * Enables a filter from the collection. + * + * @param mixed $name Name of the filter. + * + * @throws \InvalidArgumentException If the filter does not exist. + * + * @return SQLFilter The enabled filter. + */ public function enable($name) { if(null === $filterClass = $this->config->getFilterClassName($name)) { @@ -94,7 +110,15 @@ class FilterCollection return $this->enabledFilters[$name]; } - /** Disable the filter, looses the state */ + /** + * Disables a filter. + * + * @param mixed $name Name of the filter. + * + * @return SQLFilter The disabled filter. + * + * @throws \InvalidArgumentException If the filter does not exist. + */ public function disable($name) { // Get the filter to return it @@ -108,7 +132,15 @@ class FilterCollection return $filter; } - /** throws exception if not in enabled filters */ + /** + * Get an enabled filter from the collection. + * + * @param mixed $name Name of the filter. + * + * @return SQLFilter The filter. + * + * @throws \InvalidArgumentException If the filter is not enabled. + */ public function getFilter($name) { if(!isset($this->enabledFilters[$name])) { @@ -146,6 +178,9 @@ class FilterCollection return $filterHash; } + /** + * Set the filter state to dirty. + */ public function setFiltersStateDirty() { $this->filtersState = self::FILTERS_STATE_DIRTY; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php index fa7e0af2f..0dd24d50c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php @@ -99,4 +99,4 @@ class DDC633Patient * @OneToOne(targetEntity="DDC633Appointment", mappedBy="patient") */ public $appointment; -} \ No newline at end of file +} From f6d5f0481ee1c3d9723e172ce1de8b25dba161ce Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 30 Nov 2011 23:01:10 +0100 Subject: [PATCH 19/85] [DDC-551] Initial support for filters in the JoinedSubclassPersister Still some things to do. --- .../ORM/Persisters/BasicEntityPersister.php | 2 +- .../Persisters/JoinedSubclassPersister.php | 31 ++++++ lib/Doctrine/ORM/Query/Filter/SQLFilter.php | 2 +- .../Tests/ORM/Functional/SQLFilterTest.php | 97 ++++++++++++++++++- 4 files changed, 125 insertions(+), 7 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 1f4550d8c..08252c420 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -1584,7 +1584,7 @@ class BasicEntityPersister ); } - private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias) + private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') { $filterSql = ''; diff --git a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php index d7e79e285..1a5bd8e51 100644 --- a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php @@ -328,8 +328,17 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister $joinSql .= $baseTableAlias . '.' . $idColumn . ' = ' . $tableAlias . '.' . $idColumn; } + + // Filters for each parent table + $filterSql = $this->generateFilterConditionSQL($parentClass, $tableAlias, $parentClass->table['name']); + if('' !== $filterSql) { + if (!$first) $joinSql .= ' AND '; + $joinSql .= $filterSql; + } } + //@todo: filters for the sub tables of childs + // OUTER JOIN sub tables foreach ($this->_class->subClasses as $subClassName) { $subClass = $this->_em->getClassMetadata($subClassName); @@ -389,6 +398,13 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister $lockSql = ' ' . $this->_platform->getWriteLockSql(); } + // Filters for the base table + $filterSql = $this->generateFilterConditionSQL($this->_class, $baseTableAlias, $this->_class->table['name']); + if('' !== $filterSql) { + if($conditionSql) $conditionSql .= ' AND '; + $conditionSql .= $filterSql; + } + return $this->_platform->modifyLimitQuery('SELECT ' . $this->_selectColumnListSql . ' FROM ' . $this->_class->getQuotedTableName($this->_platform) . ' ' . $baseTableAlias . $joinSql @@ -473,4 +489,19 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister $value = $this->fetchVersionValue($this->_getVersionedClassMetadata(), $id); $this->_class->setFieldValue($entity, $this->_class->versionField, $value); } + + private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') + { + $filterSql = ''; + + $first = true; + foreach($this->_em->getFilters()->getEnabledFilters() as $filter) { + if("" !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias, $targetTable)) { + if ( ! $first) $filterSql .= ' AND '; else $first = false; + $filterSql .= '(' . $filterExpr . ')'; + } + } + + return $filterSql; + } } diff --git a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php index 81cae335a..6ffe2b6de 100644 --- a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php +++ b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php @@ -73,5 +73,5 @@ abstract class SQLFilter /** * @return string The constraint if there is one, empty string otherwise */ - abstract public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias); + abstract public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = ''); } diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index aed2dbaf1..92016bc69 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -15,6 +15,10 @@ use Doctrine\Tests\Models\CMS\CmsGroup; use Doctrine\Tests\Models\CMS\CmsArticle; use Doctrine\Tests\Models\CMS\CmsComment; +use Doctrine\Tests\Models\Company\CompanyPerson; +use Doctrine\Tests\Models\Company\CompanyManager; +use Doctrine\Tests\Models\Company\CompanyEmployee; + require_once __DIR__ . '/../../TestInit.php'; /** @@ -30,6 +34,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase public function setUp() { $this->useModelSet('cms'); + $this->useModelSet('company'); parent::setUp(); } @@ -444,6 +449,44 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(1, count($user->groups->slice(0,10))); } + public function testJoinSubclassPersister_FilterOnBaseTable() + { + $this->loadCompanyFixtureData(); + $this->assertEquals(2, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll())); + + // Enable the filter + $conf = $this->_em->getConfiguration(); + $conf->addFilter("manager_title", "\Doctrine\Tests\ORM\Functional\CompanyManagerTitleFilter"); + $this->_em->getFilters() + ->enable("manager_title") + ->setParameter("title", "devlead", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); + + $this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); + + $managers = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll(); + $this->assertEquals(1, count($managers)); + $this->assertEquals("Guilherme", $managers[0]->getName()); + } + + public function testJoinSubclassPersister_FilterOnParentTable() + { + $this->loadCompanyFixtureData(); + $this->assertEquals(2, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll())); + + // Enable the filter + $conf = $this->_em->getConfiguration(); + $conf->addFilter("employee_department", "\Doctrine\Tests\ORM\Functional\CompanyEmployeeDepartmentFilter"); + $this->_em->getFilters() + ->enable("employee_department") + ->setParameter("department", "parsers", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); + + $this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); + + $managers = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll(); + $this->assertEquals(1, count($managers)); + $this->assertEquals("Guilherme", $managers[0]->getName()); + } + private function loadFixtureData() { $user = new CmsUser; @@ -507,11 +550,31 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->groupId = $group->id; $this->groupId2 = $group2->id; } + + private function loadCompanyFixtureData() + { + $manager = new CompanyManager; + $manager->setName('Roman'); + $manager->setTitle('testlead'); + $manager->setSalary(42); + $manager->setDepartment('persisters'); + + $manager2 = new CompanyManager; + $manager2->setName('Guilherme'); + $manager2->setTitle('devlead'); + $manager2->setSalary(42); + $manager2->setDepartment('parsers'); + + $this->_em->persist($manager); + $this->_em->persist($manager2); + $this->_em->flush(); + $this->_em->clear(); + } } class MySoftDeleteFilter extends SQLFilter { - public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) + public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') { if ($targetEntity->name != "MyEntity\SoftDeleteNewsItem") { return ""; @@ -523,7 +586,7 @@ class MySoftDeleteFilter extends SQLFilter class MyLocaleFilter extends SQLFilter { - public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) + public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') { if (!in_array("LocaleAware", $targetEntity->reflClass->getInterfaceNames())) { return ""; @@ -535,7 +598,7 @@ class MyLocaleFilter extends SQLFilter class CMSCountryFilter extends SQLFilter { - public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) + public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') { if ($targetEntity->name != "Doctrine\Tests\Models\CMS\CmsAddress") { return ""; @@ -547,7 +610,7 @@ class CMSCountryFilter extends SQLFilter class CMSGroupPrefixFilter extends SQLFilter { - public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) + public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') { if ($targetEntity->name != "Doctrine\Tests\Models\CMS\CmsGroup") { return ""; @@ -558,7 +621,7 @@ class CMSGroupPrefixFilter extends SQLFilter } class CMSArticleTopicFilter extends SQLFilter { - public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) + public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') { if ($targetEntity->name != "Doctrine\Tests\Models\CMS\CmsArticle") { return ""; @@ -567,3 +630,27 @@ class CMSArticleTopicFilter extends SQLFilter return $targetTableAlias.'.topic = ' . $this->getParameter('topic'); // getParam uses connection to quote the value. } } + +class CompanyManagerTitleFilter extends SQLFilter +{ + public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') + { + if ($targetEntity->name != "Doctrine\Tests\Models\Company\CompanyManager") { + return ""; + } + + return $targetTableAlias.'.title = ' . $this->getParameter('title'); // getParam uses connection to quote the value. + } +} + +class CompanyEmployeeDepartmentFilter extends SQLFilter +{ + public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') + { + if ($targetEntity->name != "Doctrine\Tests\Models\Company\CompanyEmployee") { + return ""; + } + + return $targetTableAlias.'.department = ' . $this->getParameter('department'); // getParam uses connection to quote the value. + } +} From bf1cc29a2a5b4e8374973a41b293e3dbb7e91ca8 Mon Sep 17 00:00:00 2001 From: Alexander Date: Thu, 1 Dec 2011 09:46:02 +0100 Subject: [PATCH 20/85] [DDC-551] Fixed some comments --- lib/Doctrine/ORM/Query/FilterCollection.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Query/FilterCollection.php b/lib/Doctrine/ORM/Query/FilterCollection.php index 72b5a757c..c28f54863 100644 --- a/lib/Doctrine/ORM/Query/FilterCollection.php +++ b/lib/Doctrine/ORM/Query/FilterCollection.php @@ -85,7 +85,7 @@ class FilterCollection /** * Enables a filter from the collection. * - * @param mixed $name Name of the filter. + * @param string $name Name of the filter. * * @throws \InvalidArgumentException If the filter does not exist. * @@ -113,7 +113,7 @@ class FilterCollection /** * Disables a filter. * - * @param mixed $name Name of the filter. + * @param string $name Name of the filter. * * @return SQLFilter The disabled filter. * @@ -135,7 +135,7 @@ class FilterCollection /** * Get an enabled filter from the collection. * - * @param mixed $name Name of the filter. + * @param string $name Name of the filter. * * @return SQLFilter The filter. * From 5e3e8b39571491ece27d755d625fce100ab6ca39 Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Thu, 1 Dec 2011 10:00:26 -0500 Subject: [PATCH 21/85] More refactorings and optimizations. --- UPGRADE_TO_2_2 | 38 ++++- lib/Doctrine/ORM/AbstractQuery.php | 110 ++++++++------- lib/Doctrine/ORM/EntityManager.php | 111 +++++++++------ lib/Doctrine/ORM/EntityRepository.php | 73 +++++----- lib/Doctrine/ORM/Mapping/ClassMetadata.php | 60 ++++---- lib/Doctrine/ORM/NativeQuery.php | 23 +-- lib/Doctrine/ORM/Query.php | 59 +++++--- lib/Doctrine/ORM/QueryBuilder.php | 31 ++-- lib/Doctrine/ORM/UnitOfWork.php | 156 +++++++++++---------- 9 files changed, 388 insertions(+), 273 deletions(-) diff --git a/UPGRADE_TO_2_2 b/UPGRADE_TO_2_2 index 757413029..5b01fab04 100644 --- a/UPGRADE_TO_2_2 +++ b/UPGRADE_TO_2_2 @@ -1,6 +1,6 @@ # ResultCache implementation rewritten -The result cache is completly rewritten and now works on the database result level, not inside the ORM AbstractQuery +The result cache is completely rewritten and now works on the database result level, not inside the ORM AbstractQuery anymore. This means that for result cached queries the hydration will now always be performed again, regardless of the hydration mode. Affected areas are: @@ -12,20 +12,24 @@ The API is backwards compatible however most of the getter methods on the `Abstr deprecated in favor of calling AbstractQuery#getQueryCacheProfile(). This method returns a `Doctrine\DBAL\Cache\QueryCacheProfile` instance with access to result cache driver, lifetime and cache key. + # 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. +The onUpdate foreign key handling makes absolutely no sense in an ORM. Additionally Oracle doesn't even support it. Support for it is removed. + # Changes in Annotation Handling @@ -41,4 +45,32 @@ from 2.0 have to configure the annotation driver if they don't use `Configuratio $driver = new AnnotationDriver($reader, (array)$paths); - $config->setMetadataDriverImpl($driver); \ No newline at end of file + $config->setMetadataDriverImpl($driver); + + +# Scalar mappings can now be ommitted from DQL result + +You are now allowed to mark scalar SELECT expressions as HIDDEN an they are not hydrated anymore. +Example: + +SELECT u, SUM(a.id) AS HIDDEN numArticles FROM User u LEFT JOIN u.Articles a ORDER BY numArticles DESC HAVING numArticles > 10 + +Your result will be a collection of Users, and not an array with key 0 as User object instance and "numArticles" as the number of articles per user + + +# Map entities as scalars in DQL result + +When hydrating to array or even a mixed result in object hydrator, previously you had the 0 index holding you entity instance. +You are now allowed to alias this, providing more flexibility for you code. +Example: + +SELECT u AS user FROM User u + +Will now return a collection of arrays with index "user" pointing to the User object instance. + + +# Performance optimizations + +Thousands of lines were completely reviewed and optimized for best performance. +Removed redundancy and improved code readability made now internal Doctrine code easier to understand. +Also, Doctrine 2.2 now is around 10-15% faster than 2.1. \ No newline at end of file diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index 72eab194b..9a812f446 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -144,7 +144,7 @@ abstract class AbstractQuery { return $this->_params; } - + /** * Get all defined parameter types. * @@ -163,7 +163,11 @@ abstract class AbstractQuery */ public function getParameter($key) { - return isset($this->_params[$key]) ? $this->_params[$key] : null; + if (isset($this->_params[$key])) { + return $this->_params[$key]; + } + + return null; } /** @@ -174,7 +178,11 @@ abstract class AbstractQuery */ public function getParameterType($key) { - return isset($this->_paramTypes[$key]) ? $this->_paramTypes[$key] : null; + if (isset($this->_paramTypes[$key])) { + return $this->_paramTypes[$key]; + } + + return null; } /** @@ -199,14 +207,14 @@ abstract class AbstractQuery public function setParameter($key, $value, $type = null) { $key = trim($key, ':'); - + if ($type === null) { $type = Query\ParameterTypeInferer::inferType($value); } - + $this->_paramTypes[$key] = $type; $this->_params[$key] = $value; - + return $this; } @@ -220,12 +228,9 @@ abstract class AbstractQuery public function setParameters(array $params, array $types = array()) { foreach ($params as $key => $value) { - if (isset($types[$key])) { - $this->setParameter($key, $value, $types[$key]); - } else { - $this->setParameter($key, $value); - } + $this->setParameter($key, $value, isset($types[$key]) ? $types[$key] : null); } + return $this; } @@ -238,6 +243,7 @@ abstract class AbstractQuery public function setResultSetMapping(Query\ResultSetMapping $rsm) { $this->_resultSetMapping = $rsm; + return $this; } @@ -252,11 +258,11 @@ abstract class AbstractQuery if ($resultCacheDriver !== null && ! ($resultCacheDriver instanceof \Doctrine\Common\Cache\Cache)) { throw ORMException::invalidResultCacheDriver(); } - if ($this->_queryCacheProfile) { - $this->_queryCacheProfile = $this->_queryCacheProfile->setResultCacheDriver($resultCacheDriver); - } else { - $this->_queryCacheProfile = new QueryCacheProfile(0, null, $resultCacheDriver); - } + + $this->_queryCacheProfile = $this->_queryCacheProfile + ? $this->_queryCacheProfile->setResultCacheDriver($resultCacheDriver) + : new QueryCacheProfile(0, null, $resultCacheDriver); + return $this; } @@ -270,9 +276,9 @@ abstract class AbstractQuery { if ($this->_queryCacheProfile && $this->_queryCacheProfile->getResultCacheDriver()) { return $this->_queryCacheProfile->getResultCacheDriver(); - } else { - return $this->_em->getConfiguration()->getResultCacheImpl(); } + + return $this->_em->getConfiguration()->getResultCacheImpl(); } /** @@ -289,9 +295,12 @@ abstract class AbstractQuery if ($bool) { $this->setResultCacheLifetime($lifetime); $this->setResultCacheId($resultCacheId); - } else { - $this->_queryCacheProfile = null; + + return $this; } + + $this->_queryCacheProfile = null; + return $this; } @@ -303,16 +312,12 @@ abstract class AbstractQuery */ public function setResultCacheLifetime($lifetime) { - if ($lifetime === null) { - $lifetime = 0; - } else { - $lifetime = (int)$lifetime; - } - if ($this->_queryCacheProfile) { - $this->_queryCacheProfile = $this->_queryCacheProfile->setLifetime($lifetime); - } else { - $this->_queryCacheProfile = new QueryCacheProfile($lifetime); - } + $lifetime = ($lifetime !== null) ? (int) $lifetime : 0; + + $this->_queryCacheProfile = $this->_queryCacheProfile + ? $this->_queryCacheProfile->setLifetime($lifetime) + : new QueryCacheProfile($lifetime); + return $this; } @@ -336,6 +341,7 @@ abstract class AbstractQuery public function expireResultCache($expire = true) { $this->_expireResultCache = $expire; + return $this; } @@ -374,6 +380,7 @@ abstract class AbstractQuery } $this->_hints['fetchMode'][$class][$assocName] = $fetchMode; + return $this; } @@ -387,6 +394,7 @@ abstract class AbstractQuery public function setHydrationMode($hydrationMode) { $this->_hydrationMode = $hydrationMode; + return $this; } @@ -451,14 +459,15 @@ abstract class AbstractQuery return null; } - if (is_array($result)) { - if (count($result) > 1) { - throw new NonUniqueResultException; - } - return array_shift($result); + if ( ! is_array($result)) { + return $result; } - return $result; + if (count($result) > 1) { + throw new NonUniqueResultException; + } + + return array_shift($result); } /** @@ -482,14 +491,15 @@ abstract class AbstractQuery throw new NoResultException; } - if (is_array($result)) { - if (count($result) > 1) { - throw new NonUniqueResultException; - } - return array_shift($result); + if ( ! is_array($result)) { + return $result; } - return $result; + if (count($result) > 1) { + throw new NonUniqueResultException; + } + + return array_shift($result); } /** @@ -515,6 +525,7 @@ abstract class AbstractQuery public function setHint($name, $value) { $this->_hints[$name] = $value; + return $this; } @@ -531,7 +542,7 @@ abstract class AbstractQuery /** * Return the key value map of query hints that are currently set. - * + * * @return array */ public function getHints() @@ -588,8 +599,8 @@ abstract class AbstractQuery } return $this->_em->getHydrator($this->_hydrationMode)->hydrateAll( - $stmt, $this->_resultSetMapping, $this->_hints - ); + $stmt, $this->_resultSetMapping, $this->_hints + ); } /** @@ -602,11 +613,10 @@ abstract class AbstractQuery */ public function setResultCacheId($id) { - if ($this->_queryCacheProfile) { - $this->_queryCacheProfile = $this->_queryCacheProfile->setCacheKey($id); - } else { - $this->_queryCacheProfile = new QueryCacheProfile(0, $id); - } + $this->_queryCacheProfile = $this->_queryCacheProfile + ? $this->_queryCacheProfile->setCacheKey($id) + : new QueryCacheProfile(0, $id); + return $this; } diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 8bb7a5896..f09bacb89 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -130,10 +130,12 @@ class EntityManager implements ObjectManager $this->metadataFactory->setCacheDriver($this->config->getMetadataCacheImpl()); $this->unitOfWork = new UnitOfWork($this); - $this->proxyFactory = new ProxyFactory($this, - $config->getProxyDir(), - $config->getProxyNamespace(), - $config->getAutoGenerateProxyClasses()); + $this->proxyFactory = new ProxyFactory( + $this, + $config->getProxyDir(), + $config->getProxyNamespace(), + $config->getAutoGenerateProxyClasses() + ); } /** @@ -175,6 +177,7 @@ class EntityManager implements ObjectManager if ($this->expressionBuilder === null) { $this->expressionBuilder = new Query\Expr; } + return $this->expressionBuilder; } @@ -267,9 +270,11 @@ class EntityManager implements ObjectManager public function createQuery($dql = "") { $query = new Query($this); + if ( ! empty($dql)) { $query->setDql($dql); } + return $query; } @@ -296,6 +301,7 @@ class EntityManager implements ObjectManager $query = new NativeQuery($this); $query->setSql($sql); $query->setResultSetMapping($rsm); + return $query; } @@ -308,6 +314,7 @@ class EntityManager implements ObjectManager public function createNamedNativeQuery($name) { list($sql, $rsm) = $this->config->getNamedNativeQuery($name); + return $this->createNativeQuery($sql, $rsm); } @@ -336,6 +343,7 @@ class EntityManager implements ObjectManager public function flush($entity = null) { $this->errorIfClosed(); + $this->unitOfWork->commit($entity); } @@ -371,16 +379,18 @@ class EntityManager implements ObjectManager if ($entity = $this->unitOfWork->tryGetById($identifier, $class->rootEntityName)) { return ($entity instanceof $class->name) ? $entity : null; } + if ($class->subClasses) { - $entity = $this->find($entityName, $identifier); - } else { - if ( ! is_array($identifier)) { - $identifier = array($class->identifier[0] => $identifier); - } - $entity = $this->proxyFactory->getProxy($class->name, $identifier); - $this->unitOfWork->registerManaged($entity, $identifier, array()); + return $this->find($entityName, $identifier); } + if ( ! is_array($identifier)) { + $identifier = array($class->identifier[0] => $identifier); + } + + $entity = $this->proxyFactory->getProxy($class->name, $identifier); + $this->unitOfWork->registerManaged($entity, $identifier, array()); + return $entity; } @@ -411,6 +421,7 @@ class EntityManager implements ObjectManager if ($entity = $this->unitOfWork->tryGetById($identifier, $class->rootEntityName)) { return ($entity instanceof $class->name) ? $entity : null; } + if ( ! is_array($identifier)) { $identifier = array($class->identifier[0] => $identifier); } @@ -461,7 +472,9 @@ class EntityManager implements ObjectManager if ( ! is_object($entity)) { throw new \InvalidArgumentException(gettype($entity)); } + $this->errorIfClosed(); + $this->unitOfWork->persist($entity); } @@ -478,7 +491,9 @@ class EntityManager implements ObjectManager if ( ! is_object($entity)) { throw new \InvalidArgumentException(gettype($entity)); } + $this->errorIfClosed(); + $this->unitOfWork->remove($entity); } @@ -493,7 +508,9 @@ class EntityManager implements ObjectManager if ( ! is_object($entity)) { throw new \InvalidArgumentException(gettype($entity)); } + $this->errorIfClosed(); + $this->unitOfWork->refresh($entity); } @@ -511,6 +528,7 @@ class EntityManager implements ObjectManager if ( ! is_object($entity)) { throw new \InvalidArgumentException(gettype($entity)); } + $this->unitOfWork->detach($entity); } @@ -527,7 +545,9 @@ class EntityManager implements ObjectManager if ( ! is_object($entity)) { throw new \InvalidArgumentException(gettype($entity)); } + $this->errorIfClosed(); + return $this->unitOfWork->merge($entity); } @@ -567,20 +587,20 @@ class EntityManager implements ObjectManager public function getRepository($entityName) { $entityName = ltrim($entityName, '\\'); + if (isset($this->repositories[$entityName])) { return $this->repositories[$entityName]; } $metadata = $this->getClassMetadata($entityName); - $customRepositoryClassName = $metadata->customRepositoryClassName; + $repositoryClassName = $metadata->customRepositoryClassName; - if ($customRepositoryClassName !== null) { - $repository = new $customRepositoryClassName($this, $metadata); - } else { - $repositoryClass = $this->config->getDefaultRepositoryClassName(); - $repository = new $repositoryClass($this, $metadata); + if ($repositoryClassName === null) { + $repositoryClassName = $this->config->getDefaultRepositoryClassName(); } + $repository = new $repositoryClassName($this, $metadata); + $this->repositories[$entityName] = $repository; return $repository; @@ -594,9 +614,9 @@ class EntityManager implements ObjectManager */ public function contains($entity) { - return $this->unitOfWork->isScheduledForInsert($entity) || - $this->unitOfWork->isInIdentityMap($entity) && - ! $this->unitOfWork->isScheduledForDelete($entity); + return $this->unitOfWork->isScheduledForInsert($entity) + || $this->unitOfWork->isInIdentityMap($entity) + && ! $this->unitOfWork->isScheduledForDelete($entity); } /** @@ -679,29 +699,27 @@ class EntityManager implements ObjectManager { switch ($hydrationMode) { case Query::HYDRATE_OBJECT: - $hydrator = new Internal\Hydration\ObjectHydrator($this); - break; + return new Internal\Hydration\ObjectHydrator($this); + case Query::HYDRATE_ARRAY: - $hydrator = new Internal\Hydration\ArrayHydrator($this); - break; + return new Internal\Hydration\ArrayHydrator($this); + case Query::HYDRATE_SCALAR: - $hydrator = new Internal\Hydration\ScalarHydrator($this); - break; + return new Internal\Hydration\ScalarHydrator($this); + case Query::HYDRATE_SINGLE_SCALAR: - $hydrator = new Internal\Hydration\SingleScalarHydrator($this); - break; + return new Internal\Hydration\SingleScalarHydrator($this); + case Query::HYDRATE_SIMPLEOBJECT: - $hydrator = new Internal\Hydration\SimpleObjectHydrator($this); - break; + return new Internal\Hydration\SimpleObjectHydrator($this); + default: if ($class = $this->config->getCustomHydrationMode($hydrationMode)) { - $hydrator = new $class($this); - break; + return new $class($this); } - throw ORMException::invalidHydrationMode($hydrationMode); } - return $hydrator; + throw ORMException::invalidHydrationMode($hydrationMode); } /** @@ -737,18 +755,25 @@ class EntityManager implements ObjectManager */ public static function create($conn, Configuration $config, EventManager $eventManager = null) { - if (!$config->getMetadataDriverImpl()) { + if ( ! $config->getMetadataDriverImpl()) { throw ORMException::missingMappingDriverImpl(); } - if (is_array($conn)) { - $conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, ($eventManager ?: new EventManager())); - } else if ($conn instanceof Connection) { - if ($eventManager !== null && $conn->getEventManager() !== $eventManager) { - throw ORMException::mismatchedEventManager(); - } - } else { - throw new \InvalidArgumentException("Invalid argument: " . $conn); + switch (true) { + case (is_array($conn)): + $conn = \Doctrine\DBAL\DriverManager::getConnection( + $conn, $config, ($eventManager ?: new EventManager()) + ); + break; + + case ($conn instanceof Connection): + if ($eventManager !== null && $conn->getEventManager() !== $eventManager) { + throw ORMException::mismatchedEventManager(); + } + break; + + default: + throw new \InvalidArgumentException("Invalid argument: " . $conn); } return new EntityManager($conn, $config, $conn->getEventManager()); diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index a4c239001..f74448141 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -109,11 +109,11 @@ class EntityRepository implements ObjectRepository { // Check identity map first if ($entity = $this->_em->getUnitOfWork()->tryGetById($id, $this->_class->rootEntityName)) { - if (!($entity instanceof $this->_class->name)) { + if ( ! ($entity instanceof $this->_class->name)) { return null; } - - if ($lockMode != LockMode::NONE) { + + if ($lockMode !== LockMode::NONE) { $this->_em->lock($entity, $lockMode, $lockVersion); } @@ -126,23 +126,27 @@ class EntityRepository implements ObjectRepository $id = array_combine($this->_class->identifier, $value); } - if ($lockMode == LockMode::NONE) { - return $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName)->load($id); - } else if ($lockMode == LockMode::OPTIMISTIC) { - if (!$this->_class->isVersioned) { - throw OptimisticLockException::notVersioned($this->_entityName); - } - $entity = $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName)->load($id); + switch ($lockMode) { + case LockMode::NONE: + return $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName)->load($id); - $this->_em->getUnitOfWork()->lock($entity, $lockMode, $lockVersion); + case LockMode::OPTIMISTIC: + if ( ! $this->_class->isVersioned) { + throw OptimisticLockException::notVersioned($this->_entityName); + } - return $entity; - } else { - if (!$this->_em->getConnection()->isTransactionActive()) { - throw TransactionRequiredException::transactionRequired(); - } - - return $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName)->load($id, null, null, array(), $lockMode); + $entity = $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName)->load($id); + + $this->_em->getUnitOfWork()->lock($entity, $lockMode, $lockVersion); + + return $entity; + + default: + if ( ! $this->_em->getConnection()->isTransactionActive()) { + throw TransactionRequiredException::transactionRequired(); + } + + return $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName)->load($id, null, null, array(), $lockMode); } } @@ -191,30 +195,35 @@ class EntityRepository implements ObjectRepository */ public function __call($method, $arguments) { - if (substr($method, 0, 6) == 'findBy') { - $by = substr($method, 6, strlen($method)); - $method = 'findBy'; - } else if (substr($method, 0, 9) == 'findOneBy') { - $by = substr($method, 9, strlen($method)); - $method = 'findOneBy'; - } else { - throw new \BadMethodCallException( - "Undefined method '$method'. The method name must start with ". - "either findBy or findOneBy!" - ); + switch (true) { + case (substr($method, 0, 6) == 'findBy'): + $by = substr($method, 6, strlen($method)); + $method = 'findBy'; + break; + + case (substr($method, 0, 9) == 'findOneBy'): + $by = substr($method, 9, strlen($method)); + $method = 'findOneBy'; + break; + + default: + throw new \BadMethodCallException( + "Undefined method '$method'. The method name must start with ". + "either findBy or findOneBy!" + ); } if (empty($arguments)) { - throw ORMException::findByRequiresParameter($method.$by); + throw ORMException::findByRequiresParameter($method . $by); } $fieldName = lcfirst(\Doctrine\Common\Util\Inflector::classify($by)); if ($this->_class->hasField($fieldName) || $this->_class->hasAssociation($fieldName)) { return $this->$method(array($fieldName => $arguments[0])); - } else { - throw ORMException::invalidFindByCall($this->_entityName, $fieldName, $method.$by); } + + throw ORMException::invalidFindByCall($this->_entityName, $fieldName, $method.$by); } /** diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadata.php b/lib/Doctrine/ORM/Mapping/ClassMetadata.php index 9caa79e11..808e58552 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadata.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadata.php @@ -24,7 +24,7 @@ use ReflectionClass, ReflectionProperty; /** * A ClassMetadata instance holds all the object-relational mapping metadata * of an entity and it's associations. - * + * * Once populated, ClassMetadata instances are usually cached in a serialized form. * * IMPORTANT NOTE: @@ -47,10 +47,10 @@ class ClassMetadata extends ClassMetadataInfo * @var array */ public $reflFields = array(); - + /** * The prototype from which new instances of the mapped class are created. - * + * * @var object */ private $_prototype; @@ -103,13 +103,13 @@ class ClassMetadata extends ClassMetadataInfo } return $this->reflFields[$this->identifier[0]]; } - + /** * Validates & completes the given field mapping. * * @param array $mapping The field mapping to validated & complete. * @return array The validated and completed field mapping. - * + * * @throws MappingException */ protected function _validateAndCompleteFieldMapping(array &$mapping) @@ -124,7 +124,7 @@ class ClassMetadata extends ClassMetadataInfo /** * Extracts the identifier values of an entity of this class. - * + * * For composite identifiers, the identifier values are returned as an array * with the same order as the field order in {@link identifier}. * @@ -135,20 +135,25 @@ class ClassMetadata extends ClassMetadataInfo { if ($this->isIdentifierComposite) { $id = array(); + foreach ($this->identifier as $idField) { $value = $this->reflFields[$idField]->getValue($entity); + if ($value !== null) { $id[$idField] = $value; } } + return $id; - } else { - $value = $this->reflFields[$this->identifier[0]]->getValue($entity); - if ($value !== null) { - return array($this->identifier[0] => $value); - } - return array(); } + + $value = $this->reflFields[$this->identifier[0]]->getValue($entity); + + if ($value !== null) { + return array($this->identifier[0] => $value); + } + + return array(); } /** @@ -215,18 +220,18 @@ class ClassMetadata extends ClassMetadataInfo { return __CLASS__ . '@' . spl_object_hash($this); } - + /** * Determines which fields get serialized. * * It is only serialized what is necessary for best unserialization performance. * That means any metadata properties that are not set or empty or simply have * their default value are NOT serialized. - * + * * Parts that are also NOT serialized because they can not be properly unserialized: * - reflClass (ReflectionClass) * - reflFields (ReflectionProperty array) - * + * * @return array The names of all the fields that should be serialized. */ public function __sleep() @@ -301,7 +306,7 @@ class ClassMetadata extends ClassMetadataInfo /** * Restores some state that can not be serialized/unserialized. - * + * * @return void */ public function __wakeup() @@ -310,30 +315,27 @@ class ClassMetadata extends ClassMetadataInfo $this->reflClass = new ReflectionClass($this->name); foreach ($this->fieldMappings as $field => $mapping) { - if (isset($mapping['declared'])) { - $reflField = new ReflectionProperty($mapping['declared'], $field); - } else { - $reflField = $this->reflClass->getProperty($field); - } + $reflField = isset($mapping['declared']) + ? new ReflectionProperty($mapping['declared'], $field) + : $this->reflClass->getProperty($field); + $reflField->setAccessible(true); $this->reflFields[$field] = $reflField; } foreach ($this->associationMappings as $field => $mapping) { - if (isset($mapping['declared'])) { - $reflField = new ReflectionProperty($mapping['declared'], $field); - } else { - $reflField = $this->reflClass->getProperty($field); - } + $reflField = isset($mapping['declared']) + ? new ReflectionProperty($mapping['declared'], $field) + : $this->reflClass->getProperty($field); $reflField->setAccessible(true); $this->reflFields[$field] = $reflField; } } - + /** * Creates a new instance of the mapped class, without invoking the constructor. - * + * * @return object */ public function newInstance() @@ -341,6 +343,7 @@ class ClassMetadata extends ClassMetadataInfo if ($this->_prototype === null) { $this->_prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name)); } + return clone $this->_prototype; } @@ -354,6 +357,7 @@ class ClassMetadata extends ClassMetadataInfo ($this->reflClass->getMethod($callback)->getModifiers() & \ReflectionMethod::IS_PUBLIC) == 0) { throw MappingException::lifecycleCallbackMethodNotFound($this->name, $callback); } + return parent::addLifecycleCallback($callback, $event); } } diff --git a/lib/Doctrine/ORM/NativeQuery.php b/lib/Doctrine/ORM/NativeQuery.php index dea223fa3..2ab87441a 100644 --- a/lib/Doctrine/ORM/NativeQuery.php +++ b/lib/Doctrine/ORM/NativeQuery.php @@ -1,4 +1,4 @@ -_sql = $sql; + return $this; } @@ -58,16 +59,18 @@ final class NativeQuery extends AbstractQuery protected function _doExecute() { $params = $this->_params; - $types = $this->_paramTypes; - if ($params) { - if (is_int(key($params))) { - ksort($params); - ksort($types); - $params = array_values($params); - $types = array_values($types); - } + $types = $this->_paramTypes; + + if ($params && is_int(key($params))) { + ksort($params); + ksort($types); + + $params = array_values($params); + $types = array_values($types); } - return $this->_em->getConnection()->executeQuery($this->_sql, $params, $types, $this->_queryCacheProfile); + return $this->_em->getConnection()->executeQuery( + $this->_sql, $params, $types, $this->_queryCacheProfile + ); } } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index 7fbafce7b..0aa22df41 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -202,26 +202,30 @@ final class Query extends AbstractQuery return $this->_parserResult; } - // Check query cache. - if ($this->_useQueryCache && ($queryCache = $this->getQueryCacheDriver())) { - $hash = $this->_getQueryCacheId(); - $cached = $this->_expireQueryCache ? false : $queryCache->fetch($hash); + $this->_state = self::STATE_CLEAN; - if ($cached === false) { - // Cache miss. - $parser = new Parser($this); - $this->_parserResult = $parser->parse(); - $queryCache->save($hash, $this->_parserResult, $this->_queryCacheTTL); - } else { - // Cache hit. - $this->_parserResult = $cached; - } - } else { + // Check query cache. + if ( ! ($this->_useQueryCache && ($queryCache = $this->getQueryCacheDriver()))) { $parser = new Parser($this); $this->_parserResult = $parser->parse(); + + return $this->_parserResult; } - $this->_state = self::STATE_CLEAN; + $hash = $this->_getQueryCacheId(); + $cached = $this->_expireQueryCache ? false : $queryCache->fetch($hash); + + if ($cached !== false) { + // Cache hit. + $this->_parserResult = $cached; + + return $this->_parserResult; + } + + // Cache miss. + $parser = new Parser($this); + $this->_parserResult = $parser->parse(); + $queryCache->save($hash, $this->_parserResult, $this->_queryCacheTTL); return $this->_parserResult; } @@ -232,6 +236,7 @@ final class Query extends AbstractQuery protected function _doExecute() { $executor = $this->_parse()->getSqlExecutor(); + if ($this->_queryCacheProfile) { $executor->setQueryCacheProfile($this->_queryCacheProfile); } @@ -339,6 +344,7 @@ final class Query extends AbstractQuery public function setQueryCacheDriver($queryCache) { $this->_queryCache = $queryCache; + return $this; } @@ -351,6 +357,7 @@ final class Query extends AbstractQuery public function useQueryCache($bool) { $this->_useQueryCache = $bool; + return $this; } @@ -364,9 +371,9 @@ final class Query extends AbstractQuery { if ($this->_queryCache) { return $this->_queryCache; - } else { - return $this->_em->getConfiguration()->getQueryCacheImpl(); } + + return $this->_em->getConfiguration()->getQueryCacheImpl(); } /** @@ -380,6 +387,7 @@ final class Query extends AbstractQuery if ($timeToLive !== null) { $timeToLive = (int) $timeToLive; } + $this->_queryCacheTTL = $timeToLive; return $this; @@ -424,6 +432,7 @@ final class Query extends AbstractQuery public function free() { parent::free(); + $this->_dql = null; $this->_state = self::STATE_CLEAN; } @@ -440,6 +449,7 @@ final class Query extends AbstractQuery $this->_dql = $dqlQuery; $this->_state = self::STATE_DIRTY; } + return $this; } @@ -489,6 +499,7 @@ final class Query extends AbstractQuery { $this->_firstResult = $firstResult; $this->_state = self::STATE_DIRTY; + return $this; } @@ -513,6 +524,7 @@ final class Query extends AbstractQuery { $this->_maxResults = $maxResults; $this->_state = self::STATE_DIRTY; + return $this; } @@ -538,6 +550,7 @@ final class Query extends AbstractQuery public function iterate(array $params = array(), $hydrationMode = self::HYDRATE_OBJECT) { $this->setHint(self::HINT_INTERNAL_ITERATION, true); + return parent::iterate($params, $hydrationMode); } @@ -547,6 +560,7 @@ final class Query extends AbstractQuery public function setHint($name, $value) { $this->_state = self::STATE_DIRTY; + return parent::setHint($name, $value); } @@ -556,6 +570,7 @@ final class Query extends AbstractQuery public function setHydrationMode($hydrationMode) { $this->_state = self::STATE_DIRTY; + return parent::setHydrationMode($hydrationMode); } @@ -568,13 +583,14 @@ final class Query extends AbstractQuery */ public function setLockMode($lockMode) { - if ($lockMode == LockMode::PESSIMISTIC_READ || $lockMode == LockMode::PESSIMISTIC_WRITE) { - if (!$this->_em->getConnection()->isTransactionActive()) { + if ($lockMode === LockMode::PESSIMISTIC_READ || $lockMode === LockMode::PESSIMISTIC_WRITE) { + if ( ! $this->_em->getConnection()->isTransactionActive()) { throw TransactionRequiredException::transactionRequired(); } } $this->setHint(self::HINT_LOCK_MODE, $lockMode); + return $this; } @@ -586,9 +602,11 @@ final class Query extends AbstractQuery public function getLockMode() { $lockMode = $this->getHint(self::HINT_LOCK_MODE); - if (!$lockMode) { + + if ( ! $lockMode) { return LockMode::NONE; } + return $lockMode; } @@ -618,6 +636,7 @@ final class Query extends AbstractQuery public function __clone() { parent::__clone(); + $this->_state = self::STATE_DIRTY; } } \ No newline at end of file diff --git a/lib/Doctrine/ORM/QueryBuilder.php b/lib/Doctrine/ORM/QueryBuilder.php index d033eaff2..21143214b 100644 --- a/lib/Doctrine/ORM/QueryBuilder.php +++ b/lib/Doctrine/ORM/QueryBuilder.php @@ -355,12 +355,9 @@ class QueryBuilder public function setParameters(array $params, array $types = array()) { foreach ($params as $key => $value) { - if (isset($types[$key])) { - $this->setParameter($key, $value, $types[$key]); - } else { - $this->setParameter($key, $value); - } + $this->setParameter($key, $value, isset($types[$key]) ? $types[$key] : null); } + return $this; } @@ -394,6 +391,7 @@ class QueryBuilder public function setFirstResult($firstResult) { $this->_firstResult = $firstResult; + return $this; } @@ -417,6 +415,7 @@ class QueryBuilder public function setMaxResults($maxResults) { $this->_maxResults = $maxResults; + return $this; } @@ -652,13 +651,16 @@ class QueryBuilder public function innerJoin($join, $alias, $conditionType = null, $condition = null, $indexBy = null) { $rootAlias = substr($join, 0, strpos($join, '.')); - if (!in_array($rootAlias, $this->getRootAliases())) { + + if ( ! in_array($rootAlias, $this->getRootAliases())) { $rootAlias = $this->getRootAlias(); } - return $this->add('join', array( - $rootAlias => new Expr\Join(Expr\Join::INNER_JOIN, $join, $alias, $conditionType, $condition, $indexBy) - ), true); + $join = new Expr\Join( + Expr\Join::INNER_JOIN, $join, $alias, $conditionType, $condition, $indexBy + ); + + return $this->add('join', array($rootAlias => $join), true); } /** @@ -685,13 +687,16 @@ class QueryBuilder public function leftJoin($join, $alias, $conditionType = null, $condition = null, $indexBy = null) { $rootAlias = substr($join, 0, strpos($join, '.')); - if (!in_array($rootAlias, $this->getRootAliases())) { + + if ( ! in_array($rootAlias, $this->getRootAliases())) { $rootAlias = $this->getRootAlias(); } - return $this->add('join', array( - $rootAlias => new Expr\Join(Expr\Join::LEFT_JOIN, $join, $alias, $conditionType, $condition, $indexBy) - ), true); + $join = new Expr\Join( + Expr\Join::LEFT_JOIN, $join, $alias, $conditionType, $condition, $indexBy + ); + + return $this->add('join', array($rootAlias => $join), true); } /** diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 64f0608e7..25d45fcd0 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1790,7 +1790,7 @@ class UnitOfWork implements PropertyChangedListener public function detach($entity) { $visited = array(); - + $this->doDetach($entity, $visited); } @@ -1804,7 +1804,7 @@ class UnitOfWork implements PropertyChangedListener private function doDetach($entity, array &$visited, $noCascade = false) { $oid = spl_object_hash($entity); - + if (isset($visited[$oid])) { return; // Prevent infinite recursion } @@ -1816,13 +1816,13 @@ class UnitOfWork implements PropertyChangedListener if ($this->isInIdentityMap($entity)) { $this->removeFromIdentityMap($entity); } - + unset( - $this->entityInsertions[$oid], + $this->entityInsertions[$oid], $this->entityUpdates[$oid], - $this->entityDeletions[$oid], + $this->entityDeletions[$oid], $this->entityIdentifiers[$oid], - $this->entityStates[$oid], + $this->entityStates[$oid], $this->originalEntityData[$oid] ); break; @@ -1846,7 +1846,7 @@ class UnitOfWork implements PropertyChangedListener public function refresh($entity) { $visited = array(); - + $this->doRefresh($entity, $visited); } @@ -1860,7 +1860,7 @@ class UnitOfWork implements PropertyChangedListener private function doRefresh($entity, array &$visited) { $oid = spl_object_hash($entity); - + if (isset($visited[$oid])) { return; // Prevent infinite recursion } @@ -1868,11 +1868,11 @@ class UnitOfWork implements PropertyChangedListener $visited[$oid] = $entity; // mark visited $class = $this->em->getClassMetadata(get_class($entity)); - + if ($this->getEntityState($entity) !== self::STATE_MANAGED) { throw new InvalidArgumentException("Entity is not MANAGED."); } - + $this->getEntityPersister($class->name)->refresh( array_combine($class->getIdentifierFieldNames(), $this->entityIdentifiers[$oid]), $entity @@ -1890,31 +1890,32 @@ class UnitOfWork implements PropertyChangedListener private function cascadeRefresh($entity, array &$visited) { $class = $this->em->getClassMetadata(get_class($entity)); - - foreach ($class->associationMappings as $assoc) { - if ( ! $assoc['isCascadeRefresh']) { - continue; - } - + + $associationMappings = array_filter( + $class->associationMappings, + function ($assoc) { return $assoc['isCascadeRefresh']; } + ); + + foreach ($associationMappings as $assoc) { $relatedEntities = $class->reflFields[$assoc['fieldName']]->getValue($entity); - + switch (true) { case ($relatedEntities instanceof PersistentCollection): // Unwrap so that foreach() does not initialize $relatedEntities = $relatedEntities->unwrap(); // break; is commented intentionally! - + case ($relatedEntities instanceof Collection): case (is_array($relatedEntities)): foreach ($relatedEntities as $relatedEntity) { $this->doRefresh($relatedEntity, $visited); } break; - + case ($relatedEntities !== null): $this->doRefresh($relatedEntities, $visited); break; - + default: // Do nothing } @@ -1930,31 +1931,32 @@ class UnitOfWork implements PropertyChangedListener private function cascadeDetach($entity, array &$visited) { $class = $this->em->getClassMetadata(get_class($entity)); - - foreach ($class->associationMappings as $assoc) { - if ( ! $assoc['isCascadeDetach']) { - continue; - } - + + $associationMappings = array_filter( + $class->associationMappings, + function ($assoc) { return $assoc['isCascadeDetach']; } + ); + + foreach ($associationMappings as $assoc) { $relatedEntities = $class->reflFields[$assoc['fieldName']]->getValue($entity); - + switch (true) { case ($relatedEntities instanceof PersistentCollection): // Unwrap so that foreach() does not initialize $relatedEntities = $relatedEntities->unwrap(); // break; is commented intentionally! - + case ($relatedEntities instanceof Collection): case (is_array($relatedEntities)): foreach ($relatedEntities as $relatedEntity) { $this->doDetach($relatedEntity, $visited); } break; - + case ($relatedEntities !== null): $this->doDetach($relatedEntities, $visited); break; - + default: // Do nothing } @@ -1971,11 +1973,15 @@ class UnitOfWork implements PropertyChangedListener private function cascadeMerge($entity, $managedCopy, array &$visited) { $class = $this->em->getClassMetadata(get_class($entity)); - foreach ($class->associationMappings as $assoc) { - if ( ! $assoc['isCascadeMerge']) { - continue; - } + + $associationMappings = array_filter( + $class->associationMappings, + function ($assoc) { return $assoc['isCascadeMerge']; } + ); + + foreach ($associationMappings as $assoc) { $relatedEntities = $class->reflFields[$assoc['fieldName']]->getValue($entity); + if ($relatedEntities instanceof Collection) { if ($relatedEntities === $class->reflFields[$assoc['fieldName']]->getValue($managedCopy)) { continue; @@ -1985,6 +1991,7 @@ class UnitOfWork implements PropertyChangedListener // Unwrap so that foreach() does not initialize $relatedEntities = $relatedEntities->unwrap(); } + foreach ($relatedEntities as $relatedEntity) { $this->doMerge($relatedEntity, $visited, $managedCopy, $assoc); } @@ -2004,31 +2011,32 @@ class UnitOfWork implements PropertyChangedListener private function cascadePersist($entity, array &$visited) { $class = $this->em->getClassMetadata(get_class($entity)); - - foreach ($class->associationMappings as $assoc) { - if ( ! $assoc['isCascadePersist']) { - continue; - } + $associationMappings = array_filter( + $class->associationMappings, + function ($assoc) { return $assoc['isCascadePersist']; } + ); + + foreach ($associationMappings as $assoc) { $relatedEntities = $class->reflFields[$assoc['fieldName']]->getValue($entity); - + switch (true) { case ($relatedEntities instanceof PersistentCollection): // Unwrap so that foreach() does not initialize $relatedEntities = $relatedEntities->unwrap(); // break; is commented intentionally! - + case ($relatedEntities instanceof Collection): case (is_array($relatedEntities)): foreach ($relatedEntities as $relatedEntity) { $this->doPersist($relatedEntity, $visited); } break; - + case ($relatedEntities !== null): $this->doPersist($relatedEntities, $visited); break; - + default: // Do nothing } @@ -2045,11 +2053,12 @@ class UnitOfWork implements PropertyChangedListener { $class = $this->em->getClassMetadata(get_class($entity)); - foreach ($class->associationMappings as $assoc) { - if ( ! $assoc['isCascadeRemove']) { - continue; - } + $associationMappings = array_filter( + $class->associationMappings, + function ($assoc) { return $assoc['isCascadeRemove']; } + ); + foreach ($associationMappings as $assoc) { if ($entity instanceof Proxy && !$entity->__isInitialized__) { $entity->__load(); } @@ -2064,11 +2073,11 @@ class UnitOfWork implements PropertyChangedListener $this->doRemove($relatedEntity, $visited); } break; - + case ($relatedEntities !== null): $this->doRemove($relatedEntities, $visited); break; - + default: // Do nothing } @@ -2100,15 +2109,15 @@ class UnitOfWork implements PropertyChangedListener if ($lockVersion === null) { return; } - + $entityVersion = $class->reflFields[$class->versionField]->getValue($entity); - + if ($entityVersion != $lockVersion) { throw OptimisticLockException::lockFailedVersionMissmatch($entity, $lockVersion, $entityVersion); } - + break; - + case \Doctrine\DBAL\LockMode::PESSIMISTIC_READ: case \Doctrine\DBAL\LockMode::PESSIMISTIC_WRITE: if (!$this->em->getConnection()->isTransactionActive()) { @@ -2122,7 +2131,7 @@ class UnitOfWork implements PropertyChangedListener $lockMode ); break; - + default: // Do nothing } @@ -2138,6 +2147,7 @@ class UnitOfWork implements PropertyChangedListener if ($this->commitOrderCalculator === null) { $this->commitOrderCalculator = new Internal\CommitOrderCalculator; } + return $this->commitOrderCalculator; } @@ -2226,9 +2236,11 @@ class UnitOfWork implements PropertyChangedListener private function newInstance($class) { $entity = $class->newInstance(); + if ($entity instanceof \Doctrine\Common\Persistence\ObjectManagerAware) { $entity->injectObjectManager($this->em, $class); } + return $entity; } @@ -2252,34 +2264,30 @@ class UnitOfWork implements PropertyChangedListener if ($class->isIdentifierComposite) { $id = array(); - + foreach ($class->identifier as $fieldName) { - if (isset($class->associationMappings[$fieldName])) { - $id[$fieldName] = $data[$class->associationMappings[$fieldName]['joinColumns'][0]['name']]; - } else { - $id[$fieldName] = $data[$fieldName]; - } + $id[$fieldName] = isset($class->associationMappings[$fieldName]) + ? $data[$class->associationMappings[$fieldName]['joinColumns'][0]['name']] + : $data[$fieldName]; } - + $idHash = implode(' ', $id); } else { - if (isset($class->associationMappings[$class->identifier[0]])) { - $idHash = $data[$class->associationMappings[$class->identifier[0]]['joinColumns'][0]['name']]; - } else { - $idHash = $data[$class->identifier[0]]; - } - + $idHash = isset($class->associationMappings[$class->identifier[0]]) + ? $data[$class->associationMappings[$class->identifier[0]]['joinColumns'][0]['name']] + : $data[$class->identifier[0]]; + $id = array($class->identifier[0] => $idHash); } if (isset($this->identityMap[$class->rootEntityName][$idHash])) { $entity = $this->identityMap[$class->rootEntityName][$idHash]; $oid = spl_object_hash($entity); - + if ($entity instanceof Proxy && ! $entity->__isInitialized__) { $entity->__isInitialized__ = true; $overrideLocalValues = true; - + if ($entity instanceof NotifyPropertyChanged) { $entity->addPropertyChangedListener($this); } @@ -2303,23 +2311,23 @@ class UnitOfWork implements PropertyChangedListener } else { $entity = $this->newInstance($class); $oid = spl_object_hash($entity); - + $this->entityIdentifiers[$oid] = $id; $this->entityStates[$oid] = self::STATE_MANAGED; $this->originalEntityData[$oid] = $data; $this->identityMap[$class->rootEntityName][$idHash] = $entity; - + if ($entity instanceof NotifyPropertyChanged) { $entity->addPropertyChangedListener($this); } - + $overrideLocalValues = true; } if ( ! $overrideLocalValues) { return $entity; } - + foreach ($data as $field => $value) { if (isset($class->fieldMappings[$field])) { $class->reflFields[$field]->setValue($entity, $value); @@ -2337,7 +2345,7 @@ class UnitOfWork implements PropertyChangedListener if (isset($hints[Query::HINT_FORCE_PARTIAL_LOAD])) { return $entity; } - + foreach ($class->associationMappings as $field => $assoc) { // Check if the association is not among the fetch-joined associations already. if (isset($hints['fetchAlias']) && isset($hints['fetched'][$hints['fetchAlias']][$field])) { From 619a31913a4f5952248a0b909a25c2020619c29f Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Thu, 1 Dec 2011 21:18:39 +0100 Subject: [PATCH 22/85] DDC-1517 - Fix EntityRepository#find() and EntityManager#getReference() breaking on invalid or missing identifiers. --- lib/Doctrine/ORM/EntityManager.php | 26 +++++++++++++------ lib/Doctrine/ORM/EntityRepository.php | 25 +++++++++++------- lib/Doctrine/ORM/ORMException.php | 5 ++++ .../Functional/CompositePrimaryKeyTest.php | 6 +++++ 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index f09bacb89..9033c178c 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -368,28 +368,38 @@ class EntityManager implements ObjectManager * without actually loading it, if the entity is not yet loaded. * * @param string $entityName The name of the entity type. - * @param mixed $identifier The entity identifier. + * @param mixed $id The entity identifier. * @return object The entity reference. */ - public function getReference($entityName, $identifier) + public function getReference($entityName, $id) { $class = $this->metadataFactory->getMetadataFor(ltrim($entityName, '\\')); + if ( ! is_array($id)) { + $id = array($class->identifier[0] => $id); + } + $sortedId = array(); + foreach ($class->identifier as $identifier) { + if (!isset($id[$identifier])) { + throw ORMException::missingIdentifierField($class->name, $identifier); + } + $sortedId[$identifier] = $id[$identifier]; + } // Check identity map first, if its already in there just return it. - if ($entity = $this->unitOfWork->tryGetById($identifier, $class->rootEntityName)) { + if ($entity = $this->unitOfWork->tryGetById($sortedId, $class->rootEntityName)) { return ($entity instanceof $class->name) ? $entity : null; } if ($class->subClasses) { - return $this->find($entityName, $identifier); + return $this->find($entityName, $sortedId); } - if ( ! is_array($identifier)) { - $identifier = array($class->identifier[0] => $identifier); + if ( ! is_array($sortedId)) { + $sortedId = array($class->identifier[0] => $sortedId); } - $entity = $this->proxyFactory->getProxy($class->name, $identifier); - $this->unitOfWork->registerManaged($entity, $identifier, array()); + $entity = $this->proxyFactory->getProxy($class->name, $sortedId); + $this->unitOfWork->registerManaged($entity, $sortedId, array()); return $entity; } diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index f74448141..3261d7e61 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -107,8 +107,19 @@ class EntityRepository implements ObjectRepository */ public function find($id, $lockMode = LockMode::NONE, $lockVersion = null) { + if ( ! is_array($id)) { + $id = array($this->_class->identifier[0] => $id); + } + $sortedId = array(); + foreach ($this->_class->identifier as $identifier) { + if (!isset($id[$identifier])) { + throw ORMException::missingIdentifierField($this->_class->name, $identifier); + } + $sortedId[$identifier] = $id[$identifier]; + } + // Check identity map first - if ($entity = $this->_em->getUnitOfWork()->tryGetById($id, $this->_class->rootEntityName)) { + if ($entity = $this->_em->getUnitOfWork()->tryGetById($sortedId, $this->_class->rootEntityName)) { if ( ! ($entity instanceof $this->_class->name)) { return null; } @@ -120,22 +131,16 @@ class EntityRepository implements ObjectRepository return $entity; // Hit! } - if ( ! is_array($id) || count($id) <= 1) { - // @todo FIXME: Not correct. Relies on specific order. - $value = is_array($id) ? array_values($id) : array($id); - $id = array_combine($this->_class->identifier, $value); - } - switch ($lockMode) { case LockMode::NONE: - return $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName)->load($id); + return $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName)->load($sortedId); case LockMode::OPTIMISTIC: if ( ! $this->_class->isVersioned) { throw OptimisticLockException::notVersioned($this->_entityName); } - $entity = $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName)->load($id); + $entity = $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName)->load($sortedId); $this->_em->getUnitOfWork()->lock($entity, $lockMode, $lockVersion); @@ -146,7 +151,7 @@ class EntityRepository implements ObjectRepository throw TransactionRequiredException::transactionRequired(); } - return $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName)->load($id, null, null, array(), $lockMode); + return $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName)->load($sortedId, null, null, array(), $lockMode); } } diff --git a/lib/Doctrine/ORM/ORMException.php b/lib/Doctrine/ORM/ORMException.php index f15e0fbe1..0e36217d9 100644 --- a/lib/Doctrine/ORM/ORMException.php +++ b/lib/Doctrine/ORM/ORMException.php @@ -144,4 +144,9 @@ class ORMException extends Exception return new self("Invalid repository class '".$className."'. ". "it must be a Doctrine\ORM\EntityRepository."); } + + public static function missingIdentifierField($className, $fieldName) + { + return new self("The identifier $fieldName is missing for a query of " . $className); + } } diff --git a/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php index ee762d345..15f7e0bda 100644 --- a/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php @@ -92,4 +92,10 @@ class CompositePrimaryKeyTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(1, count($tours)); } + + public function testSpecifiyUnknownIdentifierPrimaryKeyFails() + { + $this->setExpectedException('Doctrine\ORM\ORMException', 'The identifier long is missing for a query of Doctrine\Tests\Models\Navigation\NavPointOfInterest'); + $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('key1' => 100)); + } } \ No newline at end of file From 2642daa43851878688d01625f272ff5874cac7b2 Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Thu, 1 Dec 2011 23:52:35 -0500 Subject: [PATCH 23/85] Fixed DDC-1236: GROUP BY now supports ResultVariable and IdentificationVariable. Composite PK is also supported. If you are willing to group by an aggregate function or a function itself, just place it in SELECT expression then refer to it in the GROUP BY clause. If you are not willing to have the function being part of your resultset, just mark the column as HIDDEN and you are done. --- lib/Doctrine/ORM/Query/Parser.php | 20 ++--- lib/Doctrine/ORM/Query/SqlWalker.php | 76 ++++++++++++++----- lib/Doctrine/ORM/Query/TreeWalker.php | 10 ++- lib/Doctrine/ORM/Query/TreeWalkerAdapter.php | 22 ++++-- lib/Doctrine/ORM/Query/TreeWalkerChain.php | 33 +++++--- .../ORM/Query/SelectSqlGenerationTest.php | 49 +++++++++--- 6 files changed, 152 insertions(+), 58 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index a3725eb8d..ff3656b62 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -2,7 +2,7 @@ /* * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHARNTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT @@ -1305,7 +1305,7 @@ class Parser } /** - * GroupByItem ::= IdentificationVariable | SingleValuedPathExpression + * GroupByItem ::= IdentificationVariable | ResultVariable | SingleValuedPathExpression * * @return string | \Doctrine\ORM\Query\AST\PathExpression */ @@ -1314,18 +1314,20 @@ class Parser // We need to check if we are in a IdentificationVariable or SingleValuedPathExpression $glimpse = $this->_lexer->glimpse(); - if ($glimpse['type'] == Lexer::T_DOT) { + if ($glimpse['type'] === Lexer::T_DOT) { return $this->SingleValuedPathExpression(); } - $token = $this->_lexer->lookahead; - $identVariable = $this->IdentificationVariable(); + // Still need to decide between IdentificationVariable or ResultVariable + $lookaheadValue = $this->_lexer->lookahead['value']; - if ( ! isset($this->_queryComponents[$identVariable])) { - $this->semanticalError('Cannot group by undefined identification variable.'); + if ( ! isset($this->_queryComponents[$lookaheadValue])) { + $this->semanticalError('Cannot group by undefined identification or result variable.'); } - return $identVariable; + return (isset($this->_queryComponents[$lookaheadValue]['metadata'])) + ? $this->IdentificationVariable() + : $this->ResultVariable(); } /** @@ -2633,7 +2635,7 @@ class Parser $isDistinct = true; } - $pathExp = ($lookaheadType === Lexer::T_COUNT) + $pathExp = ($lookaheadType === Lexer::T_COUNT) ? $this->SingleValuedPathExpression() : $this->SimpleArithmeticExpression(); diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 3b58dfba2..c12ea0690 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -1014,6 +1014,8 @@ class SqlWalker implements TreeWalker $sql .= $col . ' AS ' . $columnAlias; + $this->_scalarResultAliasMap[$resultAlias] = $columnAlias; + if ( ! $hidden) { $this->_rsm->addScalarResult($columnAlias, $resultAlias); $this->_scalarFields[$dqlAlias][$fieldName] = $columnAlias; @@ -1103,6 +1105,8 @@ class SqlWalker implements TreeWalker $sqlParts[] = $col . ' AS '. $columnAlias; + $this->_scalarResultAliasMap[$resultAlias][] = $columnAlias; + $this->_rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName, $class->name); } @@ -1132,6 +1136,8 @@ class SqlWalker implements TreeWalker $sqlParts[] = $col . ' AS ' . $columnAlias; + $this->_scalarResultAliasMap[$resultAlias][] = $columnAlias; + $this->_rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName, $subClassName); } } @@ -1319,25 +1325,7 @@ class SqlWalker implements TreeWalker $sqlParts = array(); foreach ($groupByClause->groupByItems AS $groupByItem) { - if ( ! is_string($groupByItem)) { - $sqlParts[] = $this->walkGroupByItem($groupByItem); - - continue; - } - - foreach ($this->_queryComponents[$groupByItem]['metadata']->fieldNames AS $field) { - $item = new AST\PathExpression(AST\PathExpression::TYPE_STATE_FIELD, $groupByItem, $field); - $item->type = AST\PathExpression::TYPE_STATE_FIELD; - $sqlParts[] = $this->walkGroupByItem($item); - } - - foreach ($this->_queryComponents[$groupByItem]['metadata']->associationMappings AS $mapping) { - if ($mapping['isOwningSide'] && $mapping['type'] & ClassMetadataInfo::TO_ONE) { - $item = new AST\PathExpression(AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION, $groupByItem, $mapping['fieldName']); - $item->type = AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION; - $sqlParts[] = $this->walkGroupByItem($item); - } - } + $sqlParts[] = $this->walkGroupByItem($groupByItem); } return ' GROUP BY ' . implode(', ', $sqlParts); @@ -1349,9 +1337,38 @@ class SqlWalker implements TreeWalker * @param GroupByItem * @return string The SQL. */ - public function walkGroupByItem(AST\PathExpression $pathExpr) + public function walkGroupByItem($groupByItem) { - return $this->walkPathExpression($pathExpr); + // StateFieldPathExpression + if ( ! is_string($groupByItem)) { + return $this->walkPathExpression($groupByItem); + } + + // ResultVariable + if (isset($this->_queryComponents[$groupByItem]['resultVariable'])) { + return $this->walkResultVariable($groupByItem); + } + + // IdentificationVariable + $sqlParts = array(); + + foreach ($this->_queryComponents[$groupByItem]['metadata']->fieldNames AS $field) { + $item = new AST\PathExpression(AST\PathExpression::TYPE_STATE_FIELD, $groupByItem, $field); + $item->type = AST\PathExpression::TYPE_STATE_FIELD; + + $sqlParts[] = $this->walkPathExpression($item); + } + + foreach ($this->_queryComponents[$groupByItem]['metadata']->associationMappings AS $mapping) { + if ($mapping['isOwningSide'] && $mapping['type'] & ClassMetadataInfo::TO_ONE) { + $item = new AST\PathExpression(AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION, $groupByItem, $mapping['fieldName']); + $item->type = AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION; + + $sqlParts[] = $this->walkPathExpression($item); + } + } + + return implode(', ', $sqlParts); } /** @@ -1997,4 +2014,21 @@ class SqlWalker implements TreeWalker ? $this->_conn->quote($stringPrimary) : $stringPrimary->dispatch($this); } + + /** + * Walks down a ResultVriable that represents an AST node, thereby generating the appropriate SQL. + * + * @param string $resultVariable + * @return string The SQL. + */ + public function walkResultVariable($resultVariable) + { + $resultAlias = $this->_scalarResultAliasMap[$resultVariable]; + + if (is_array($resultAlias)) { + return implode(', ', $resultAlias); + } + + return $resultAlias; + } } diff --git a/lib/Doctrine/ORM/Query/TreeWalker.php b/lib/Doctrine/ORM/Query/TreeWalker.php index 4bbe963a6..84628981c 100644 --- a/lib/Doctrine/ORM/Query/TreeWalker.php +++ b/lib/Doctrine/ORM/Query/TreeWalker.php @@ -168,7 +168,7 @@ interface TreeWalker * @param GroupByItem * @return string The SQL. */ - function walkGroupByItem(AST\PathExpression $pathExpr); + function walkGroupByItem($groupByItem); /** * Walks down an UpdateStatement AST node, thereby generating the appropriate SQL. @@ -394,6 +394,14 @@ interface TreeWalker */ function walkPathExpression($pathExpr); + /** + * Walks down an ResultVariable AST node, thereby generating the appropriate SQL. + * + * @param string $resultVariable + * @return string The SQL. + */ + function walkResultVariable($resultVariable); + /** * Gets an executor that can be used to execute the result of this walker. * diff --git a/lib/Doctrine/ORM/Query/TreeWalkerAdapter.php b/lib/Doctrine/ORM/Query/TreeWalkerAdapter.php index ca2a49520..530b98c50 100644 --- a/lib/Doctrine/ORM/Query/TreeWalkerAdapter.php +++ b/lib/Doctrine/ORM/Query/TreeWalkerAdapter.php @@ -24,7 +24,7 @@ namespace Doctrine\ORM\Query; /** * An adapter implementation of the TreeWalker interface. The methods in this class * are empty. This class exists as convenience for creating tree walkers. - * + * * @author Roman Borschel * @since 2.0 */ @@ -33,7 +33,7 @@ abstract class TreeWalkerAdapter implements TreeWalker private $_query; private $_parserResult; private $_queryComponents; - + /** * {@inheritdoc} */ @@ -71,7 +71,7 @@ abstract class TreeWalkerAdapter implements TreeWalker { return $this->_parserResult; } - + /** * Walks down a SelectStatement AST node, thereby generating the appropriate SQL. * @@ -202,7 +202,7 @@ abstract class TreeWalkerAdapter implements TreeWalker * @param GroupByItem * @return string The SQL. */ - public function walkGroupByItem(AST\PathExpression $pathExpr) {} + public function walkGroupByItem($groupByItem) {} /** * Walks down an UpdateStatement AST node, thereby generating the appropriate SQL. @@ -291,7 +291,7 @@ abstract class TreeWalkerAdapter implements TreeWalker * @return string The SQL. */ public function walkExistsExpression($existsExpr) {} - + /** * Walks down a CollectionMemberExpression AST node, thereby generating the appropriate SQL. * @@ -427,10 +427,18 @@ abstract class TreeWalkerAdapter implements TreeWalker * @return string The SQL. */ public function walkPathExpression($pathExpr) {} - + + /** + * Walks down an ResultVariable AST node, thereby generating the appropriate SQL. + * + * @param string $resultVariable + * @return string The SQL. + */ + public function walkResultVariable($resultVariable) {} + /** * Gets an executor that can be used to execute the result of this walker. - * + * * @return AbstractExecutor */ public function getExecutor($AST) {} diff --git a/lib/Doctrine/ORM/Query/TreeWalkerChain.php b/lib/Doctrine/ORM/Query/TreeWalkerChain.php index 1fc197783..d3891a114 100644 --- a/lib/Doctrine/ORM/Query/TreeWalkerChain.php +++ b/lib/Doctrine/ORM/Query/TreeWalkerChain.php @@ -25,7 +25,7 @@ namespace Doctrine\ORM\Query; * Represents a chain of tree walkers that modify an AST and finally emit output. * Only the last walker in the chain can emit output. Any previous walkers can modify * the AST to influence the final output produced by the last walker. - * + * * @author Roman Borschel * @since 2.0 */ @@ -39,7 +39,7 @@ class TreeWalkerChain implements TreeWalker private $_parserResult; /** The query components of the original query (the "symbol table") that was produced by the Parser. */ private $_queryComponents; - + /** * @inheritdoc */ @@ -49,17 +49,17 @@ class TreeWalkerChain implements TreeWalker $this->_parserResult = $parserResult; $this->_queryComponents = $queryComponents; } - + /** * Adds a tree walker to the chain. - * + * * @param string $walkerClass The class of the walker to instantiate. */ public function addTreeWalker($walkerClass) { $this->_walkers[] = new $walkerClass($this->_query, $this->_parserResult, $this->_queryComponents); } - + /** * Walks down a SelectStatement AST node, thereby generating the appropriate SQL. * @@ -270,10 +270,10 @@ class TreeWalkerChain implements TreeWalker * @param GroupByItem * @return string The SQL. */ - public function walkGroupByItem(AST\PathExpression $pathExpr) + public function walkGroupByItem($groupByItem) { foreach ($this->_walkers as $walker) { - $walker->walkGroupByItem($pathExpr); + $walker->walkGroupByItem($groupByItem); } } @@ -419,7 +419,7 @@ class TreeWalkerChain implements TreeWalker $walker->walkExistsExpression($existsExpr); } } - + /** * Walks down a CollectionMemberExpression AST node, thereby generating the appropriate SQL. * @@ -640,10 +640,23 @@ class TreeWalkerChain implements TreeWalker $walker->walkPathExpression($pathExpr); } } - + + /** + * Walks down an ResultVariable AST node, thereby generating the appropriate SQL. + * + * @param string $resultVariable + * @return string The SQL. + */ + public function walkResultVariable($resultVariable) + { + foreach ($this->_walkers as $walker) { + $walker->walkResultVariable($resultVariable); + } + } + /** * Gets an executor that can be used to execute the result of this walker. - * + * * @return AbstractExecutor */ public function getExecutor($AST) diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index ceb1a3729..50de767db 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -40,7 +40,14 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase $query->setHint($name, $value); } - parent::assertEquals($sqlToBeConfirmed, $query->getSQL()); + $sqlGenerated = $query->getSQL(); + + parent::assertEquals( + $sqlToBeConfirmed, + $sqlGenerated, + sprintf('"%s" is not equal of "%s"', $sqlGenerated, $sqlToBeConfirmed) + ); + $query->free(); } catch (\Exception $e) { $this->fail($e->getMessage() ."\n".$e->getTraceAsString()); @@ -1302,7 +1309,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase "SELECT d0_.article_id AS article_id0, d0_.title AS title1 FROM DDC117Article d0_ WHERE EXISTS (SELECT d1_.source_id, d1_.target_id FROM DDC117Reference d1_ WHERE d1_.source_id = d0_.article_id)" ); } - + /** * @group DDC-1474 */ @@ -1312,13 +1319,13 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase 'SELECT - e.value AS value, e.id FROM ' . __NAMESPACE__ . '\DDC1474Entity e', 'SELECT -d0_.value AS sclr0, d0_.id AS id1 FROM DDC1474Entity d0_' ); - + $this->assertSqlGeneration( 'SELECT e.id, + e.value AS value FROM ' . __NAMESPACE__ . '\DDC1474Entity e', 'SELECT d0_.id AS id0, +d0_.value AS sclr1 FROM DDC1474Entity d0_' ); } - + /** * @group DDC-1430 */ @@ -1328,13 +1335,35 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY u', 'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ GROUP BY c0_.id, c0_.status, c0_.username, c0_.name, c0_.email_id' ); - + $this->assertSqlGeneration( 'SELECT e FROM Doctrine\Tests\Models\CMS\CmsEmployee e GROUP BY e', 'SELECT c0_.id AS id0, c0_.name AS name1 FROM cms_employees c0_ GROUP BY c0_.id, c0_.name, c0_.spouse_id' ); } + /** + * @group DDC-1236 + */ + public function testGroupBySupportsResultVariable() + { + $this->assertSqlGeneration( + 'SELECT u, u.status AS st FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY st', + 'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, c0_.status AS status4 FROM cms_users c0_ GROUP BY status4' + ); + } + + /** + * @group DDC-1236 + */ + public function testGroupBySupportsIdentificationVariable() + { + $this->assertSqlGeneration( + 'SELECT u AS user FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY user', + 'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ GROUP BY id0, status1, username2, name3' + ); + } + public function testCustomTypeValueSql() { if (DBALType::hasType('negative_to_positive')) { @@ -1441,19 +1470,19 @@ class DDC1474Entity { /** - * @Id + * @Id * @Column(type="integer") * @GeneratedValue() */ protected $id; /** - * @column(type="float") + * @column(type="float") */ private $value; /** - * @param string $float + * @param string $float */ public function __construct($float) { @@ -1469,7 +1498,7 @@ class DDC1474Entity } /** - * @return float + * @return float */ public function getValue() { @@ -1477,7 +1506,7 @@ class DDC1474Entity } /** - * @param float $value + * @param float $value */ public function setValue($value) { From 2f6b930a8d418fc34572de1867806a63c34abc6d Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Sat, 3 Dec 2011 15:19:21 -0500 Subject: [PATCH 24/85] Implemented missing support in CollectionMemberComparison. Removed old todo in ArrayHydrator. Finished implementation of IdentificationVariable in ArithmeticPrimary. --- .../ORM/Internal/Hydration/ArrayHydrator.php | 5 - lib/Doctrine/ORM/Query/Parser.php | 2 +- lib/Doctrine/ORM/Query/SqlWalker.php | 125 +++++++++++------- lib/Doctrine/ORM/Tools/EntityGenerator.php | 10 +- .../ORM/Query/SelectSqlGenerationTest.php | 52 ++++++-- 5 files changed, 120 insertions(+), 74 deletions(-) diff --git a/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php index 817e30baf..f2869baa2 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php @@ -28,11 +28,6 @@ use PDO, Doctrine\DBAL\Connection, Doctrine\ORM\Mapping\ClassMetadata; * @since 2.0 * @author Roman Borschel * @author Guilherme Blanco - * - * @todo General behavior is "wrong" if you define an alias to selected IdentificationVariable. - * Example: SELECT u AS user FROM User u - * The result should contains an array where each array index is an array: array('user' => [User object]) - * Problem must be solved somehow by removing the isMixed in ResultSetMapping */ class ArrayHydrator extends AbstractHydrator { diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index ff3656b62..b63af9ac8 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -2607,7 +2607,7 @@ class Parser return $this->InputParameter(); } - return $this->IdentificationVariable(); + return $this->StateFieldPathExpression(); } /** diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index c12ea0690..5826b82d4 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -411,7 +411,8 @@ class SqlWalker implements TreeWalker { $this->_useSqlTableAliases = false; - return $this->walkUpdateClause($AST->updateClause) . $this->walkWhereClause($AST->whereClause); + return $this->walkUpdateClause($AST->updateClause) + . $this->walkWhereClause($AST->whereClause); } /** @@ -424,9 +425,29 @@ class SqlWalker implements TreeWalker { $this->_useSqlTableAliases = false; - return $this->walkDeleteClause($AST->deleteClause) . $this->walkWhereClause($AST->whereClause); + return $this->walkDeleteClause($AST->deleteClause) + . $this->walkWhereClause($AST->whereClause); } + /** + * Walks down an IdentificationVariable AST node, thereby generating the appropriate SQL. + * This one differs of ->walkIdentificationVariable() because it generates the entity identifiers. + * + * @param string $identVariable + * @return string + */ + public function walkEntityIdentificationVariable($identVariable) + { + $class = $this->_queryComponents[$identVariable]['metadata']; + $tableAlias = $this->getSQLTableAlias($class->getTableName(), $identVariable); + $sqlParts = array(); + + foreach ($class->getQuotedIdentifierColumnNames($this->_platform) as $columnName) { + $sqlParts[] = $tableAlias . '.' . $columnName; + } + + return implode(', ', $sqlParts); + } /** * Walks down an IdentificationVariable (no AST node associated), thereby generating the SQL. @@ -689,7 +710,7 @@ class SqlWalker implements TreeWalker $expr = $orderByItem->expression; $sql = ($expr instanceof AST\PathExpression) ? $this->walkPathExpression($expr) - : $this->_scalarResultAliasMap[$this->_queryComponents[$expr]['token']['value']]; + : $this->walkResultVariable($this->_queryComponents[$expr]['token']['value']); return $sql . ' ' . strtoupper($orderByItem->type); } @@ -1287,15 +1308,7 @@ class SqlWalker implements TreeWalker break; default: // IdentificationVariable - $class = $this->_queryComponents[$expr]['metadata']; - $tableAlias = $this->getSQLTableAlias($class->getTableName(), $expr); - $sqlParts = array(); - - foreach ($class->getQuotedIdentifierColumnNames($this->_platform) as $columnName) { - $sqlParts[] = $tableAlias . '.' . $columnName; - } - - $sql .= implode(', ', $sqlParts); + $sql .= $this->walkEntityIdentificationVariable($expr); break; } @@ -1558,20 +1571,30 @@ class SqlWalker implements TreeWalker { $sql = $collMemberExpr->not ? 'NOT ' : ''; $sql .= 'EXISTS (SELECT 1 FROM '; - $entityExpr = $collMemberExpr->entityExpression; + + $entityExpr = $collMemberExpr->entityExpression; $collPathExpr = $collMemberExpr->collectionValuedPathExpression; $fieldName = $collPathExpr->field; - $dqlAlias = $collPathExpr->identificationVariable; + $dqlAlias = $collPathExpr->identificationVariable; $class = $this->_queryComponents[$dqlAlias]['metadata']; - if ($entityExpr instanceof AST\InputParameter) { - $dqlParamKey = $entityExpr->name; - $entity = $this->_query->getParameter($dqlParamKey); - } else { - //TODO - throw new \BadMethodCallException("Not implemented"); + switch (true) { + // InputParameter + case ($entityExpr instanceof AST\InputParameter): + $dqlParamKey = $entityExpr->name; + $entity = $this->_query->getParameter($dqlParamKey); + $entitySql = '?'; + break; + + // SingleValuedAssociationPathExpression | IdentificationVariable + case ($entityExpr instanceof AST\PathExpression): + $entitySql = $this->walkPathExpression($entityExpr); + break; + + default: + throw new \BadMethodCallException("Not implemented"); } $assoc = $class->associationMappings[$fieldName]; @@ -1584,25 +1607,23 @@ class SqlWalker implements TreeWalker $sql .= $targetClass->getQuotedTableName($this->_platform) . ' ' . $targetTableAlias . ' WHERE '; $owningAssoc = $targetClass->associationMappings[$assoc['mappedBy']]; - $first = true; + $sqlParts = array(); foreach ($owningAssoc['targetToSourceKeyColumns'] as $targetColumn => $sourceColumn) { - if ($first) $first = false; else $sql .= ' AND '; + $targetColumn = $class->getQuotedColumnName($class->fieldNames[$targetColumn], $this->_platform); - $sql .= $sourceTableAlias . '.' . $class->getQuotedColumnName($class->fieldNames[$targetColumn], $this->_platform) - . ' = ' - . $targetTableAlias . '.' . $sourceColumn; + $sqlParts[] = $sourceTableAlias . '.' . $targetColumn . ' = ' . $targetTableAlias . '.' . $sourceColumn; } - $sql .= ' AND '; - $first = true; - foreach ($targetClass->getQuotedIdentifierColumnNames($this->_platform) as $targetColumnName) { - if ($first) $first = false; else $sql .= ' AND '; + if (isset($dqlParamKey)) { + $this->_parserResult->addParameterMapping($dqlParamKey, $this->_sqlParamIndex++); + } - $this->_parserResult->addParameterMapping($dqlParamKey, $this->_sqlParamIndex++); - $sql .= $targetTableAlias . '.' . $targetColumnName . ' = ?'; + $sqlParts[] = $targetTableAlias . '.' . $targetColumnName . ' = ' . $entitySql; } + + $sql .= implode(' AND ', $sqlParts); } else { // many-to-many $targetClass = $this->_em->getClassMetadata($assoc['targetEntity']); @@ -1619,39 +1640,42 @@ class SqlWalker implements TreeWalker . ' INNER JOIN ' . $targetClass->getQuotedTableName($this->_platform) . ' ' . $targetTableAlias . ' ON '; // join conditions - $joinColumns = $assoc['isOwningSide'] - ? $joinTable['inverseJoinColumns'] - : $joinTable['joinColumns']; + $joinColumns = $assoc['isOwningSide'] ? $joinTable['inverseJoinColumns'] : $joinTable['joinColumns']; + $joinSqlParts = array(); - $first = true; foreach ($joinColumns as $joinColumn) { - if ($first) $first = false; else $sql .= ' AND '; + $targetColumn = $targetClass->getQuotedColumnName( + $targetClass->fieldNames[$joinColumn['referencedColumnName']], + $this->_platform + ); - $sql .= $joinTableAlias . '.' . $joinColumn['name'] . ' = ' - . $targetTableAlias . '.' . $targetClass->getQuotedColumnName($targetClass->fieldNames[$joinColumn['referencedColumnName']], $this->_platform); + $joinSqlParts[] = $joinTableAlias . '.' . $joinColumn['name'] . ' = ' . $targetTableAlias . '.' . $targetColumn; } + $sql .= implode(' AND ', $joinSqlParts); $sql .= ' WHERE '; $joinColumns = $assoc['isOwningSide'] ? $joinTable['joinColumns'] : $joinTable['inverseJoinColumns']; - $first = true; + $sqlParts = array(); foreach ($joinColumns as $joinColumn) { - if ($first) $first = false; else $sql .= ' AND '; + $targetColumn = $class->getQuotedColumnName( + $class->fieldNames[$joinColumn['referencedColumnName']], + $this->_platform + ); - $sql .= $joinTableAlias . '.' . $joinColumn['name'] . ' = ' - . $sourceTableAlias . '.' . $class->getQuotedColumnName($class->fieldNames[$joinColumn['referencedColumnName']], $this->_platform); + $sqlParts[] = $joinTableAlias . '.' . $joinColumn['name'] . ' = ' . $sourceTableAlias . '.' . $targetColumn; } - $sql .= ' AND '; - $first = true; - foreach ($targetClass->getQuotedIdentifierColumnNames($this->_platform) as $targetColumnName) { - if ($first) $first = false; else $sql .= ' AND '; + if (isset($dqlParamKey)) { + $this->_parserResult->addParameterMapping($dqlParamKey, $this->_sqlParamIndex++); + } - $this->_parserResult->addParameterMapping($dqlParamKey, $this->_sqlParamIndex++); - $sql .= $targetTableAlias . '.' . $targetColumnName . ' = ?'; + $sqlParts[] = $targetTableAlias . '.' . $targetColumnName . ' = ' . $entitySql; } + + $sql .= implode(' AND ', $sqlParts); } return $sql . ')'; @@ -1946,7 +1970,7 @@ class SqlWalker implements TreeWalker { if (is_string($term)) { return (isset($this->_queryComponents[$term])) - ? $this->_scalarResultAliasMap[$this->_queryComponents[$term]['token']['value']] + ? $this->walkResultVariable($this->_queryComponents[$term]['token']['value']) : $term; } @@ -1998,8 +2022,7 @@ class SqlWalker implements TreeWalker return $primary->dispatch($this); } - // TODO: We need to deal with IdentificationVariable here - return ''; + return $this->walkEntityIdentificationVariable($primary); } /** diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index b1ba714d8..66d79a837 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -196,7 +196,7 @@ public function () if ($this->_backupExisting && file_exists($path)) { $backupPath = dirname($path) . DIRECTORY_SEPARATOR . basename($path) . "~"; if (!copy($path, $backupPath)) { - throw new \RuntimeException("Attempt to backup overwritten entitiy file but copy operation failed."); + throw new \RuntimeException("Attempt to backup overwritten entity file but copy operation failed."); } } @@ -404,11 +404,11 @@ public function () $collections[] = '$this->'.$mapping['fieldName'].' = new \Doctrine\Common\Collections\ArrayCollection();'; } } - + if ($collections) { return $this->_prefixCodeWithSpaces(str_replace("", implode("\n".$this->_spaces, $collections), self::$_constructorMethodTemplate)); } - + return ''; } @@ -576,7 +576,7 @@ public function () if (isset($metadata->table['schema'])) { $table[] = 'schema="' . $metadata->table['schema'] . '"'; } - + if (isset($metadata->table['name'])) { $table[] = 'name="' . $metadata->table['name'] . '"'; } @@ -754,7 +754,7 @@ public function () '' => Inflector::camelize($fieldName), '' => $methodName, '' => $fieldName, - '' => ($defaultValue !== null ) ? ('='.$defaultValue) : '', + '' => ($defaultValue !== null ) ? (' = '.$defaultValue) : '', '' => $this->_getClassName($metadata) ); diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 50de767db..031ec2138 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -536,43 +536,71 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ); } - public function testSupportsMemberOfExpression() + public function testSupportsMemberOfExpressionOneToMany() { // "Get all users who have $phone as a phonenumber." (*cough* doesnt really make sense...) - $q1 = $this->_em->createQuery('SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE :param MEMBER OF u.phonenumbers'); - $q1->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true); + $q = $this->_em->createQuery('SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE :param MEMBER OF u.phonenumbers'); + $q->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true); $phone = new \Doctrine\Tests\Models\CMS\CmsPhonenumber; $phone->phonenumber = 101; - $q1->setParameter('param', $phone); + $q->setParameter('param', $phone); $this->assertEquals( 'SELECT c0_.id AS id0 FROM cms_users c0_ WHERE EXISTS (SELECT 1 FROM cms_phonenumbers c1_ WHERE c0_.id = c1_.user_id AND c1_.phonenumber = ?)', - $q1->getSql() + $q->getSql() ); + } + public function testSupportsMemberOfExpressionManyToMany() + { // "Get all users who are members of $group." - $q2 = $this->_em->createQuery('SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE :param MEMBER OF u.groups'); - $q2->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true); + $q = $this->_em->createQuery('SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE :param MEMBER OF u.groups'); + $q->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true); $group = new \Doctrine\Tests\Models\CMS\CmsGroup; $group->id = 101; - $q2->setParameter('param', $group); + $q->setParameter('param', $group); $this->assertEquals( 'SELECT c0_.id AS id0 FROM cms_users c0_ WHERE EXISTS (SELECT 1 FROM cms_users_groups c1_ INNER JOIN cms_groups c2_ ON c1_.group_id = c2_.id WHERE c1_.user_id = c0_.id AND c2_.id = ?)', - $q2->getSql() + $q->getSql() ); + } + public function testSupportsMemberOfExpressionSelfReferencing() + { // "Get all persons who have $person as a friend." // Tough one: Many-many self-referencing ("friends") with class table inheritance - $q3 = $this->_em->createQuery('SELECT p FROM Doctrine\Tests\Models\Company\CompanyPerson p WHERE :param MEMBER OF p.friends'); + $q = $this->_em->createQuery('SELECT p FROM Doctrine\Tests\Models\Company\CompanyPerson p WHERE :param MEMBER OF p.friends'); $person = new \Doctrine\Tests\Models\Company\CompanyPerson; $this->_em->getClassMetadata(get_class($person))->setIdentifierValues($person, array('id' => 101)); - $q3->setParameter('param', $person); + $q->setParameter('param', $person); $this->assertEquals( 'SELECT c0_.id AS id0, c0_.name AS name1, c1_.title AS title2, c2_.salary AS salary3, c2_.department AS department4, c2_.startDate AS startDate5, c0_.discr AS discr6, c0_.spouse_id AS spouse_id7, c1_.car_id AS car_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() + $q->getSql() + ); + } + + public function testSupportsMemberOfWithSingleValuedAssociation() + { + // Impossible example, but it illustrates the purpose + $q = $this->_em->createQuery('SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.email MEMBER OF u.groups'); + + $this->assertEquals( + 'SELECT c0_.id AS id0 FROM cms_users c0_ WHERE EXISTS (SELECT 1 FROM cms_users_groups c1_ INNER JOIN cms_groups c2_ ON c1_.group_id = c2_.id WHERE c1_.user_id = c0_.id AND c2_.id = c0_.email_id)', + $q->getSql() + ); + } + + public function testSupportsMemberOfWithIdentificationVariable() + { + // Impossible example, but it illustrates the purpose + $q = $this->_em->createQuery('SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u MEMBER OF u.groups'); + + $this->assertEquals( + 'SELECT c0_.id AS id0 FROM cms_users c0_ WHERE EXISTS (SELECT 1 FROM cms_users_groups c1_ INNER JOIN cms_groups c2_ ON c1_.group_id = c2_.id WHERE c1_.user_id = c0_.id AND c2_.id = c0_.id)', + $q->getSql() ); } From a26990c3e8693134a2789c4c7c57d6f053f01fcf Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Sun, 4 Dec 2011 02:14:47 -0500 Subject: [PATCH 25/85] DDC-1457: Fixed wrong docblock. --- lib/Doctrine/ORM/UnitOfWork.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 25d45fcd0..803e6683c 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -2147,7 +2147,7 @@ class UnitOfWork implements PropertyChangedListener if ($this->commitOrderCalculator === null) { $this->commitOrderCalculator = new Internal\CommitOrderCalculator; } - + return $this->commitOrderCalculator; } @@ -2652,7 +2652,7 @@ class UnitOfWork implements PropertyChangedListener * * @param string $entityName The name of the Entity. * - * @return Doctrine\ORM\Persisters\AbstractEntityPersister + * @return Doctrine\ORM\Persisters\BasicEntityPersister */ public function getEntityPersister($entityName) { From 0380d5ae580dcbefd63051028fc1ab78599fda6c Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Sun, 4 Dec 2011 02:41:54 -0500 Subject: [PATCH 26/85] Implemented multiple enhancements in InExpression support for DQL. Fixed DDC-1472 and DDC-1416. --- lib/Doctrine/ORM/Query/AST/InExpression.php | 6 +++--- lib/Doctrine/ORM/Query/Parser.php | 2 +- lib/Doctrine/ORM/Query/SqlWalker.php | 3 +-- .../Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php | 8 ++++---- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/Doctrine/ORM/Query/AST/InExpression.php b/lib/Doctrine/ORM/Query/AST/InExpression.php index b1da40156..15c517dc0 100644 --- a/lib/Doctrine/ORM/Query/AST/InExpression.php +++ b/lib/Doctrine/ORM/Query/AST/InExpression.php @@ -35,13 +35,13 @@ namespace Doctrine\ORM\Query\AST; class InExpression extends Node { public $not; - public $pathExpression; + public $expression; public $literals = array(); public $subselect; - public function __construct($pathExpression) + public function __construct($expression) { - $this->pathExpression = $pathExpression; + $this->expression = $expression; } public function dispatch($sqlWalker) diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index b63af9ac8..6c8f515f6 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -2720,7 +2720,7 @@ class Parser */ public function InExpression() { - $inExpression = new AST\InExpression($this->SingleValuedPathExpression()); + $inExpression = new AST\InExpression($this->ArithmeticExpression()); if ($this->_lexer->isNextToken(Lexer::T_NOT)) { $this->match(Lexer::T_NOT); diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 5826b82d4..6d0f926ad 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -1727,8 +1727,7 @@ class SqlWalker implements TreeWalker */ public function walkInExpression($inExpr) { - $sql = $this->walkPathExpression($inExpr->pathExpression) - . ($inExpr->not ? ' NOT' : '') . ' IN ('; + $sql = $this->walkArithmeticExpression($inExpr->expression) . ($inExpr->not ? ' NOT' : '') . ' IN ('; $sql .= ($inExpr->subselect) ? $this->walkSubselect($inExpr->subselect) diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 031ec2138..7a7b7cd3f 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -451,8 +451,8 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase public function testSupportsSingleValuedInExpressionWithoutSpacesInWherePart() { $this->assertSqlGeneration( - "SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id IN(46)", - "SELECT c0_.name AS name0 FROM cms_users c0_ WHERE c0_.id IN (46)" + "SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE IDENTITY(u.email) IN(46)", + "SELECT c0_.name AS name0 FROM cms_users c0_ WHERE c0_.email_id IN (46)" ); } @@ -467,8 +467,8 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase public function testSupportsNotInExpressionInWherePart() { $this->assertSqlGeneration( - 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id NOT IN (1)', - 'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE c0_.id NOT IN (1)' + 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE :id NOT IN (1)', + 'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE ? NOT IN (1)' ); } From e98c775f0d4143d6e8b2877f5311ea09873b02e7 Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 5 Dec 2011 16:14:04 +0100 Subject: [PATCH 27/85] Revert "[DDC-551] Initial support for filters in the JoinedSubclassPersister" This reverts commit f6d5f0481ee1c3d9723e172ce1de8b25dba161ce. --- .../ORM/Persisters/BasicEntityPersister.php | 2 +- .../Persisters/JoinedSubclassPersister.php | 20 +----- lib/Doctrine/ORM/Query/Filter/SQLFilter.php | 2 +- .../Tests/ORM/Functional/SQLFilterTest.php | 72 ++----------------- 4 files changed, 9 insertions(+), 87 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 08252c420..1f4550d8c 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -1584,7 +1584,7 @@ class BasicEntityPersister ); } - private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') + private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias) { $filterSql = ''; diff --git a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php index 1a5bd8e51..190ae7be6 100644 --- a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php @@ -328,17 +328,8 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister $joinSql .= $baseTableAlias . '.' . $idColumn . ' = ' . $tableAlias . '.' . $idColumn; } - - // Filters for each parent table - $filterSql = $this->generateFilterConditionSQL($parentClass, $tableAlias, $parentClass->table['name']); - if('' !== $filterSql) { - if (!$first) $joinSql .= ' AND '; - $joinSql .= $filterSql; - } } - //@todo: filters for the sub tables of childs - // OUTER JOIN sub tables foreach ($this->_class->subClasses as $subClassName) { $subClass = $this->_em->getClassMetadata($subClassName); @@ -398,13 +389,6 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister $lockSql = ' ' . $this->_platform->getWriteLockSql(); } - // Filters for the base table - $filterSql = $this->generateFilterConditionSQL($this->_class, $baseTableAlias, $this->_class->table['name']); - if('' !== $filterSql) { - if($conditionSql) $conditionSql .= ' AND '; - $conditionSql .= $filterSql; - } - return $this->_platform->modifyLimitQuery('SELECT ' . $this->_selectColumnListSql . ' FROM ' . $this->_class->getQuotedTableName($this->_platform) . ' ' . $baseTableAlias . $joinSql @@ -490,13 +474,13 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister $this->_class->setFieldValue($entity, $this->_class->versionField, $value); } - private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') + private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias) { $filterSql = ''; $first = true; foreach($this->_em->getFilters()->getEnabledFilters() as $filter) { - if("" !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias, $targetTable)) { + if("" !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { if ( ! $first) $filterSql .= ' AND '; else $first = false; $filterSql .= '(' . $filterExpr . ')'; } diff --git a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php index 6ffe2b6de..81cae335a 100644 --- a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php +++ b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php @@ -73,5 +73,5 @@ abstract class SQLFilter /** * @return string The constraint if there is one, empty string otherwise */ - abstract public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = ''); + abstract public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias); } diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index 92016bc69..107b4ca84 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -449,44 +449,6 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(1, count($user->groups->slice(0,10))); } - public function testJoinSubclassPersister_FilterOnBaseTable() - { - $this->loadCompanyFixtureData(); - $this->assertEquals(2, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll())); - - // Enable the filter - $conf = $this->_em->getConfiguration(); - $conf->addFilter("manager_title", "\Doctrine\Tests\ORM\Functional\CompanyManagerTitleFilter"); - $this->_em->getFilters() - ->enable("manager_title") - ->setParameter("title", "devlead", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); - - $this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); - - $managers = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll(); - $this->assertEquals(1, count($managers)); - $this->assertEquals("Guilherme", $managers[0]->getName()); - } - - public function testJoinSubclassPersister_FilterOnParentTable() - { - $this->loadCompanyFixtureData(); - $this->assertEquals(2, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll())); - - // Enable the filter - $conf = $this->_em->getConfiguration(); - $conf->addFilter("employee_department", "\Doctrine\Tests\ORM\Functional\CompanyEmployeeDepartmentFilter"); - $this->_em->getFilters() - ->enable("employee_department") - ->setParameter("department", "parsers", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); - - $this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); - - $managers = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll(); - $this->assertEquals(1, count($managers)); - $this->assertEquals("Guilherme", $managers[0]->getName()); - } - private function loadFixtureData() { $user = new CmsUser; @@ -574,7 +536,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase class MySoftDeleteFilter extends SQLFilter { - public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') + public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) { if ($targetEntity->name != "MyEntity\SoftDeleteNewsItem") { return ""; @@ -586,7 +548,7 @@ class MySoftDeleteFilter extends SQLFilter class MyLocaleFilter extends SQLFilter { - public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') + public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) { if (!in_array("LocaleAware", $targetEntity->reflClass->getInterfaceNames())) { return ""; @@ -598,7 +560,7 @@ class MyLocaleFilter extends SQLFilter class CMSCountryFilter extends SQLFilter { - public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') + public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) { if ($targetEntity->name != "Doctrine\Tests\Models\CMS\CmsAddress") { return ""; @@ -610,7 +572,7 @@ class CMSCountryFilter extends SQLFilter class CMSGroupPrefixFilter extends SQLFilter { - public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') + public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) { if ($targetEntity->name != "Doctrine\Tests\Models\CMS\CmsGroup") { return ""; @@ -621,7 +583,7 @@ class CMSGroupPrefixFilter extends SQLFilter } class CMSArticleTopicFilter extends SQLFilter { - public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') + public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) { if ($targetEntity->name != "Doctrine\Tests\Models\CMS\CmsArticle") { return ""; @@ -630,27 +592,3 @@ class CMSArticleTopicFilter extends SQLFilter return $targetTableAlias.'.topic = ' . $this->getParameter('topic'); // getParam uses connection to quote the value. } } - -class CompanyManagerTitleFilter extends SQLFilter -{ - public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') - { - if ($targetEntity->name != "Doctrine\Tests\Models\Company\CompanyManager") { - return ""; - } - - return $targetTableAlias.'.title = ' . $this->getParameter('title'); // getParam uses connection to quote the value. - } -} - -class CompanyEmployeeDepartmentFilter extends SQLFilter -{ - public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') - { - if ($targetEntity->name != "Doctrine\Tests\Models\Company\CompanyEmployee") { - return ""; - } - - return $targetTableAlias.'.department = ' . $this->getParameter('department'); // getParam uses connection to quote the value. - } -} From 752b5023260527dcf458e0b66778518a22f90096 Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 5 Dec 2011 18:26:56 +0100 Subject: [PATCH 28/85] [DDC-551] Add filters only on root entities in JoinedSubclassPersister --- .../Persisters/JoinedSubclassPersister.php | 17 +++++++ .../Tests/ORM/Functional/SQLFilterTest.php | 50 +++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php index 190ae7be6..9e9477f0a 100644 --- a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php @@ -327,6 +327,14 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister if ($first) $first = false; else $joinSql .= ' AND '; $joinSql .= $baseTableAlias . '.' . $idColumn . ' = ' . $tableAlias . '.' . $idColumn; + + if($parentClass->name === $this->_class->rootEntityName) { + // Add filters on the root class + $filterSql = $this->generateFilterConditionSQL($parentClass, $tableAlias); + if('' !== $filterSql) { + $joinSql .= ' AND ' . $filterSql; + } + } } } @@ -374,6 +382,15 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister $conditionSql = $this->_getSelectConditionSQL($criteria, $assoc); + // If the current class in the root entity, add the filters + if($this->_class->name === $this->_class->rootEntityName) { + $filterSql = $this->generateFilterConditionSQL($this->_class, $baseTableAlias); + if('' !== $filterSql) { + if($conditionSql) $conditionSql .= ' AND '; + $conditionSql .= $filterSql; + } + } + $orderBy = ($assoc !== null && isset($assoc['orderBy'])) ? $assoc['orderBy'] : $orderBy; $orderBySql = $orderBy ? $this->_getOrderBySQL($orderBy, $baseTableAlias) : ''; diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index 107b4ca84..5d9803277 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -513,6 +513,40 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->groupId2 = $group2->id; } + public function testJoinSubclassPersister_FilterOnlyOnRootTableWhenFetchingSubEntity() + { + $this->loadCompanyFixtureData(); + $this->assertEquals(2, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll())); + + // Enable the filter + $conf = $this->_em->getConfiguration(); + $conf->addFilter("person_name", "\Doctrine\Tests\ORM\Functional\CompanyPersonNameFilter"); + $this->_em->getFilters() + ->enable("person_name") + ->setParameter("name", "Guilh%", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); + + $managers = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll(); + $this->assertEquals(1, count($managers)); + $this->assertEquals("Guilherme", $managers[0]->getName()); + } + + public function testJoinSubclassPersister_FilterOnlyOnRootTableWhenFetchingRootEntity() + { + $this->loadCompanyFixtureData(); + $this->assertEquals(3, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyPerson')->findAll())); + + // Enable the filter + $conf = $this->_em->getConfiguration(); + $conf->addFilter("person_name", "\Doctrine\Tests\ORM\Functional\CompanyPersonNameFilter"); + $this->_em->getFilters() + ->enable("person_name") + ->setParameter("name", "Guilh%", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); + + $managers = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyPerson')->findAll(); + $this->assertEquals(1, count($managers)); + $this->assertEquals("Guilherme", $managers[0]->getName()); + } + private function loadCompanyFixtureData() { $manager = new CompanyManager; @@ -527,8 +561,12 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $manager2->setSalary(42); $manager2->setDepartment('parsers'); + $person = new CompanyPerson; + $person->setName('Benjamin'); + $this->_em->persist($manager); $this->_em->persist($manager2); + $this->_em->persist($person); $this->_em->flush(); $this->_em->clear(); } @@ -592,3 +630,15 @@ class CMSArticleTopicFilter extends SQLFilter return $targetTableAlias.'.topic = ' . $this->getParameter('topic'); // getParam uses connection to quote the value. } } + +class CompanyPersonNameFilter extends SQLFilter +{ + public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') + { + if ($targetEntity->name != "Doctrine\Tests\Models\Company\CompanyPerson") { + return ""; + } + + return $targetTableAlias.'.name LIKE ' . $this->getParameter('name'); + } +} From 4c842974b47812cd7bff4e5b28effc46867ee570 Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 5 Dec 2011 18:56:44 +0100 Subject: [PATCH 29/85] [DDC-551] Add filters only on root entities in SingleTablePersister --- .../ORM/Persisters/BasicEntityPersister.php | 10 ++- .../Persisters/JoinedSubclassPersister.php | 14 ---- .../ORM/Persisters/SingleTablePersister.php | 12 +++ .../Tests/ORM/Functional/SQLFilterTest.php | 73 +++++++++++++++++-- 4 files changed, 88 insertions(+), 21 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 1f4550d8c..af7cf302c 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -1584,7 +1584,15 @@ class BasicEntityPersister ); } - private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias) + /** + * Generates the filter SQL for a given entity and table alias. + * + * @param ClassMetadata $targetEntity Metadata of the target entity. + * @param string $targetTableAlias The table alias of the joined/selected table. + * + * @return string The SQL query part to add to a query. + */ + protected function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias) { $filterSql = ''; diff --git a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php index 9e9477f0a..73e65797c 100644 --- a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php @@ -491,18 +491,4 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister $this->_class->setFieldValue($entity, $this->_class->versionField, $value); } - private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias) - { - $filterSql = ''; - - $first = true; - foreach($this->_em->getFilters()->getEnabledFilters() as $filter) { - if("" !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { - if ( ! $first) $filterSql .= ' AND '; else $first = false; - $filterSql .= '(' . $filterExpr . ')'; - } - } - - return $filterSql; - } } diff --git a/lib/Doctrine/ORM/Persisters/SingleTablePersister.php b/lib/Doctrine/ORM/Persisters/SingleTablePersister.php index 0f1b9e3de..d11486e93 100644 --- a/lib/Doctrine/ORM/Persisters/SingleTablePersister.php +++ b/lib/Doctrine/ORM/Persisters/SingleTablePersister.php @@ -131,4 +131,16 @@ class SingleTablePersister extends AbstractEntityInheritancePersister return $conditionSql; } + + /** {@inheritdoc} */ + protected function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias) + { + // Ensure that the filters are applied to the root entity of the inheritance tree + $realTargetEntity = $targetEntity; + if($targetEntity->name !== $targetEntity->rootEntityName) { + $realTargetEntity = $this->_em->getClassMetadata($targetEntity->rootEntityName); + } + + return parent::generateFilterConditionSQL($realTargetEntity, $targetTableAlias); + } } diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index 5d9803277..2353814b0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -19,6 +19,9 @@ use Doctrine\Tests\Models\Company\CompanyPerson; use Doctrine\Tests\Models\Company\CompanyManager; use Doctrine\Tests\Models\Company\CompanyEmployee; +use Doctrine\Tests\Models\Company\CompanyFlexContract; +use Doctrine\Tests\Models\Company\CompanyFlexUltraContract; + require_once __DIR__ . '/../../TestInit.php'; /** @@ -515,7 +518,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testJoinSubclassPersister_FilterOnlyOnRootTableWhenFetchingSubEntity() { - $this->loadCompanyFixtureData(); + $this->loadCompanyJoinedSubclassFixtureData(); $this->assertEquals(2, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll())); // Enable the filter @@ -532,7 +535,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testJoinSubclassPersister_FilterOnlyOnRootTableWhenFetchingRootEntity() { - $this->loadCompanyFixtureData(); + $this->loadCompanyJoinedSubclassFixtureData(); $this->assertEquals(3, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyPerson')->findAll())); // Enable the filter @@ -542,12 +545,12 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase ->enable("person_name") ->setParameter("name", "Guilh%", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); - $managers = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyPerson')->findAll(); - $this->assertEquals(1, count($managers)); - $this->assertEquals("Guilherme", $managers[0]->getName()); + $persons = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyPerson')->findAll(); + $this->assertEquals(1, count($persons)); + $this->assertEquals("Guilherme", $persons[0]->getName()); } - private function loadCompanyFixtureData() + private function loadCompanyJoinedSubclassFixtureData() { $manager = new CompanyManager; $manager->setName('Roman'); @@ -570,6 +573,52 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->flush(); $this->_em->clear(); } + + public function testSingleTableInheritance_FilterOnlyOnRootTableWhenFetchingSubEntity() + { + $this->loadCompanySingleTableInheritanceFixtureData(); + $this->assertEquals(2, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyFlexUltraContract')->findAll())); + + // Enable the filter + $conf = $this->_em->getConfiguration(); + $conf->addFilter("completed_contract", "\Doctrine\Tests\ORM\Functional\CompletedContractFilter"); + $this->_em->getFilters() + ->enable("completed_contract"); + + $this->assertEquals(1, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyFlexUltraContract')->findAll())); + } + + public function testSingleTableInheritance_FilterOnlyOnRootTableWhenFetchingRootEntity() + { + $this->loadCompanySingleTableInheritanceFixtureData(); + $this->assertEquals(4, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyFlexContract')->findAll())); + + // Enable the filter + $conf = $this->_em->getConfiguration(); + $conf->addFilter("completed_contract", "\Doctrine\Tests\ORM\Functional\CompletedContractFilter"); + $this->_em->getFilters() + ->enable("completed_contract"); + + $this->assertEquals(2, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyFlexContract')->findAll())); + } + + private function loadCompanySingleTableInheritanceFixtureData() + { + $contract1 = new CompanyFlexUltraContract; + $contract2 = new CompanyFlexUltraContract; + $contract2->markCompleted(); + + $contract3 = new CompanyFlexContract; + $contract4 = new CompanyFlexContract; + $contract4->markCompleted(); + + $this->_em->persist($contract1); + $this->_em->persist($contract2); + $this->_em->persist($contract3); + $this->_em->persist($contract4); + $this->_em->flush(); + $this->_em->clear(); + } } class MySoftDeleteFilter extends SQLFilter @@ -642,3 +691,15 @@ class CompanyPersonNameFilter extends SQLFilter return $targetTableAlias.'.name LIKE ' . $this->getParameter('name'); } } + +class CompletedContractFilter extends SQLFilter +{ + public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') + { + if ($targetEntity->name != "Doctrine\Tests\Models\Company\CompanyContract") { + return ""; + } + + return $targetTableAlias.'.completed = 1'; + } +} From 33c68df3bab8c39b0f04e20a02d46891033593dc Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 5 Dec 2011 17:35:49 -0200 Subject: [PATCH 30/85] Fixed DDC-1170 --- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 4 + .../ORM/Mapping/Driver/YamlDriver.php | 4 + .../ORM/Mapping/AbstractMappingDriverTest.php | 80 +++++++++++++++++++ ...ctrine.Tests.ORM.Mapping.DDC1170Entity.php | 16 ++++ ...ne.Tests.ORM.Mapping.DDC1170Entity.dcm.xml | 15 ++++ ...ne.Tests.ORM.Mapping.DDC1170Entity.dcm.yml | 10 +++ 6 files changed, 129 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.DDC1170Entity.php create mode 100644 tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.DDC1170Entity.dcm.xml create mode 100644 tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.DDC1170Entity.dcm.yml diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 6f655d0db..8228ba1ca 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -232,6 +232,10 @@ class XmlDriver extends AbstractFileDriver if (isset($idElement['column'])) { $mapping['columnName'] = (string)$idElement['column']; } + + if (isset($idElement['column-definition'])) { + $mapping['columnDefinition'] = (string)$idElement['column-definition']; + } $metadata->mapField($mapping); diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index a33c19b6b..4ef66f9f8 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -181,6 +181,10 @@ class YamlDriver extends AbstractFileDriver if (isset($idElement['length'])) { $mapping['length'] = $idElement['length']; } + + if (isset($idElement['columnDefinition'])) { + $mapping['columnDefinition'] = $idElement['columnDefinition']; + } $metadata->mapField($mapping); diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 7c2887301..2499d4eb6 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -373,6 +373,25 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals(ClassMetadataInfo::GENERATOR_TYPE_NONE, $class->generatorType); } + + /** + * @group DDC-1170 + */ + public function testIdentifierColumnDefinition() + { + + $class = $this->createClassMetadata(__NAMESPACE__ . '\DDC1170Entity'); + + + $this->assertArrayHasKey('id', $class->fieldMappings); + $this->assertArrayHasKey('value', $class->fieldMappings); + + $this->assertArrayHasKey('columnDefinition', $class->fieldMappings['id']); + $this->assertArrayHasKey('columnDefinition', $class->fieldMappings['value']); + + $this->assertEquals("INT unsigned NOT NULL", $class->fieldMappings['id']['columnDefinition']); + $this->assertEquals("VARCHAR(255) NOT NULL", $class->fieldMappings['value']['columnDefinition']); + } } /** @@ -597,4 +616,65 @@ class Dog extends Animal { } +} + + +/** + * @Entity + */ +class DDC1170Entity +{ + + /** + * @param string $value + */ + function __construct($value = null) + { + $this->value = $value; + } + + /** + * @Id + * @GeneratedValue(strategy="NONE") + * @Column(type="integer", columnDefinition = "INT unsigned NOT NULL") + **/ + private $id; + + /** + * @Column(columnDefinition = "VARCHAR(255) NOT NULL") + */ + private $value; + + /** + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * @return string + */ + public function getValue() + { + return $this->value; + } + + public static function loadMetadata(ClassMetadataInfo $metadata) + { + $metadata->mapField(array( + 'id' => true, + 'fieldName' => 'id', + 'columnDefinition' => 'INT unsigned NOT NULL', + )); + + $metadata->mapField(array( + 'fieldName' => 'value', + 'columnDefinition' => 'VARCHAR(255) NOT NULL' + )); + + $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE); + } + } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.DDC1170Entity.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.DDC1170Entity.php new file mode 100644 index 000000000..97f4624ba --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.DDC1170Entity.php @@ -0,0 +1,16 @@ +mapField(array( + 'id' => true, + 'fieldName' => 'id', + 'columnDefinition' => 'INT unsigned NOT NULL', +)); + +$metadata->mapField(array( + 'fieldName' => 'value', + 'columnDefinition' => 'VARCHAR(255) NOT NULL' +)); + +$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE); \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.DDC1170Entity.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.DDC1170Entity.dcm.xml new file mode 100644 index 000000000..9f5ad7fac --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.DDC1170Entity.dcm.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.DDC1170Entity.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.DDC1170Entity.dcm.yml new file mode 100644 index 000000000..8b2ac518b --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.DDC1170Entity.dcm.yml @@ -0,0 +1,10 @@ +Doctrine\Tests\ORM\Mapping\DDC1170Entity: + type: entity + id: + id: + columnDefinition: INT unsigned NOT NULL + generator: + strategy: NONE + fields: + value: + columnDefinition: VARCHAR(255) NOT NULL \ No newline at end of file From 3b7d16c60f432fa94131171852ef2154e079cac6 Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 5 Dec 2011 21:14:31 +0100 Subject: [PATCH 31/85] [DDC-551] General cleanup of the code. --- lib/Doctrine/ORM/Configuration.php | 14 ++++++ lib/Doctrine/ORM/EntityManager.php | 15 ++++++- .../ORM/Persisters/BasicEntityPersister.php | 10 ++--- .../Persisters/JoinedSubclassPersister.php | 6 +-- .../ORM/Persisters/ManyToManyPersister.php | 41 ++++++++++++----- lib/Doctrine/ORM/Query/Filter/SQLFilter.php | 45 ++++++++++++++++++- lib/Doctrine/ORM/Query/FilterCollection.php | 12 ++++- lib/Doctrine/ORM/Query/SqlWalker.php | 10 ++++- .../Tests/ORM/Functional/SQLFilterTest.php | 1 + 9 files changed, 130 insertions(+), 24 deletions(-) diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index 50a424256..5f5a58b30 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -496,11 +496,25 @@ class Configuration extends \Doctrine\DBAL\Configuration return $this->_attributes['classMetadataFactoryName']; } + /** + * Add a filter to the list of possible filters. + * + * @param string $name The name of the filter. + * @param string $className The class name of the filter. + */ public function addFilter($name, $className) { $this->_attributes['filters'][strtolower($name)] = $className; } + /** + * Gets the class name for a given filter name. + * + * @param string $name The name of the filter. + * + * @return string The class name of the filter, or null of it is not + * defined. + */ public function getFilterClassName($name) { $name = strtolower($name); diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 2916caf3a..80fd6685d 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -762,6 +762,12 @@ class EntityManager implements ObjectManager return new EntityManager($conn, $config, $conn->getEventManager()); } + /** + * Gets the enabled filters. + * + * @access public + * @return FilterCollection The active filter collection. + */ public function getFilters() { if(null === $this->filterCollection) { @@ -772,7 +778,9 @@ class EntityManager implements ObjectManager } /** - * @return boolean True, if the filter collection is clean. + * Checks whether the state of the filter collection is clean. + * + * @return boolean True, iff the filter collection is clean. */ public function isFiltersStateClean() { @@ -780,6 +788,11 @@ class EntityManager implements ObjectManager || $this->filterCollection->isClean(); } + /** + * Checks whether the Entity Manager has filters. + * + * @return True, iff the EM has a filter collection. + */ public function hasFilters() { return null !== $this->filterCollection; diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index af7cf302c..ec725693f 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -902,8 +902,7 @@ class BasicEntityPersister $alias = $this->_getSQLTableAlias($this->_class->name); - $filterSql = $this->generateFilterConditionSQL($this->_class, $alias); - if('' !== $filterSql) { + if('' !== $filterSql = $this->generateFilterConditionSQL($this->_class, $alias)) { if($conditionSql) $conditionSql .= ' AND '; $conditionSql .= $filterSql; } @@ -1541,8 +1540,7 @@ class BasicEntityPersister . $this->getLockTablesSql($alias) . ' WHERE ' . $this->_getSelectConditionSQL($criteria); - $filterSql = $this->generateFilterConditionSQL($this->_class, $alias); - if('' !== $filterSql) { + if('' !== $filterSql = $this->generateFilterConditionSQL($this->_class, $alias)) { $sql .= ' AND ' . $filterSql; } @@ -1598,8 +1596,8 @@ class BasicEntityPersister $first = true; foreach($this->_em->getFilters()->getEnabledFilters() as $filter) { - if("" !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { - if ( ! $first) $filterSql .= ' AND '; else $first = false; + if('' !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { + if (!$first) $filterSql .= ' AND '; else $first = false; $filterSql .= '(' . $filterExpr . ')'; } } diff --git a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php index 73e65797c..daed5b01d 100644 --- a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php @@ -330,8 +330,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister if($parentClass->name === $this->_class->rootEntityName) { // Add filters on the root class - $filterSql = $this->generateFilterConditionSQL($parentClass, $tableAlias); - if('' !== $filterSql) { + if('' !== $filterSql = $this->generateFilterConditionSQL($parentClass, $tableAlias)) { $joinSql .= ' AND ' . $filterSql; } } @@ -384,8 +383,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister // If the current class in the root entity, add the filters if($this->_class->name === $this->_class->rootEntityName) { - $filterSql = $this->generateFilterConditionSQL($this->_class, $baseTableAlias); - if('' !== $filterSql) { + if('' !== $filterSql = $this->generateFilterConditionSQL($this->_class, $baseTableAlias)) { if($conditionSql) $conditionSql .= ' AND '; $conditionSql .= $filterSql; } diff --git a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php index 8a1b6cc32..2a97e32c9 100644 --- a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php @@ -21,7 +21,8 @@ namespace Doctrine\ORM\Persisters; -use Doctrine\ORM\PersistentCollection, +use Doctrine\ORM\Mapping\ClassMetadata, + Doctrine\ORM\PersistentCollection, Doctrine\ORM\UnitOfWork; /** @@ -315,21 +316,20 @@ class ManyToManyPersister extends AbstractCollectionPersister return (bool) $this->_conn->fetchColumn($sql, $params); } + /** + * Generates the filter SQL for a given mapping. + * + * @param array $targetEntity Array containing mapping information. + * + * @return string The SQL query part to add to a query. + */ public function getFilterSql($mapping) { $targetClass = $this->_em->getClassMetadata($mapping['targetEntity']); - // Get the SQL for the filters - $filterSql = ''; - foreach($this->_em->getFilters()->getEnabledFilters() as $filter) { - if("" !== $filterExpr = $filter->addFilterConstraint($targetClass, 'te')) { - $filterSql .= ' AND (' . $filterExpr . ')'; - } - } - // A join is needed if there is filtering on the target entity $joinTargetEntitySQL = ''; - if('' !== $filterSql) { + if('' !== $filterSql = $this->generateFilterConditionSQL($targetClass, 'te')) { $joinTargetEntitySQL = ' JOIN ' . $targetClass->getQuotedTableName($this->_conn->getDatabasePlatform()) . ' te' . ' ON'; @@ -343,4 +343,25 @@ class ManyToManyPersister extends AbstractCollectionPersister return array($joinTargetEntitySQL, $filterSql); } + + /** + * Generates the filter SQL for a given entity and table alias. + * + * @param ClassMetadata $targetEntity Metadata of the target entity. + * @param string $targetTableAlias The table alias of the joined/selected table. + * + * @return string The SQL query part to add to a query. + */ + protected function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias) + { + $filterSql = ''; + + foreach($this->_em->getFilters()->getEnabledFilters() as $filter) { + if('' !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { + $filterSql .= 'AND (' . $filterExpr . ')'; + } + } + + return $filterSql; + } } diff --git a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php index 81cae335a..9be8628a2 100644 --- a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php +++ b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php @@ -33,15 +33,39 @@ use Doctrine\ORM\EntityManager; */ abstract class SQLFilter { + /** + * The entity manager. + * @var EntityManager + */ private $em; + /** + * Parameters for the filter. + * @var array + */ private $parameters; + /** + * Constructs the SQLFilter object. + * + * @param EntityManager $em The EM + * @final + */ final public function __construct(EntityManager $em) { $this->em = $em; } + /** + * Sets a parameter that can be used by the filter. + * + * @param string $name Name of the parameter. + * @param string $value Value of the parameter. + * @param string $type Type of the parameter. + * + * @final + * @return SQLFilter The current SQL filter. + */ final public function setParameter($name, $value, $type) { // @todo: check for a valid type? @@ -56,6 +80,17 @@ abstract class SQLFilter return $this; } + /** + * Gets a parameter to use in a query. + * + * The function is responsible for the right output escaping to use the + * value in a query. + * + * @param string $name Name of the parameter. + * + * @final + * @return string The SQL escaped parameter to use in a query. + */ final public function getParameter($name) { if(!isset($this->parameters[$name])) { @@ -65,13 +100,21 @@ abstract class SQLFilter return $this->em->getConnection()->quote($this->parameters[$name]['value'], $this->parameters[$name]['type']); } + /** + * Returns as string representation of the SQLFilter parameters (the state). + * + * @final + * @return string String representation of the the SQLFilter. + */ final public function __toString() { return serialize($this->parameters); } /** - * @return string The constraint if there is one, empty string otherwise + * Gets the SQL query part to add to a query. + * + * @return string The constraint SQL if there is available, empty string otherwise */ abstract public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias); } diff --git a/lib/Doctrine/ORM/Query/FilterCollection.php b/lib/Doctrine/ORM/Query/FilterCollection.php index c28f54863..8e055ecdb 100644 --- a/lib/Doctrine/ORM/Query/FilterCollection.php +++ b/lib/Doctrine/ORM/Query/FilterCollection.php @@ -40,9 +40,19 @@ class FilterCollection */ const FILTERS_STATE_DIRTY = 2; + /** + * The used Configuration. + * + * @var Doctrine\ORM\Configuration + */ private $config; + + /** + * The EntityManager that "owns" this FilterCollection instance. + * + * @var Doctrine\ORM\EntityManager + */ private $em; - private $filters; /** * Instances of enabled filters. diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 0cbecb99d..e95cb400f 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -352,12 +352,20 @@ class SqlWalker implements TreeWalker return (count($sqlParts) > 1) ? '(' . $sql . ')' : $sql; } + /** + * Generates the filter SQL for a given entity and table alias. + * + * @param ClassMetadata $targetEntity Metadata of the target entity. + * @param string $targetTableAlias The table alias of the joined/selected table. + * + * @return string The SQL query part to add to a query. + */ private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias) { $filterSql = ''; if($this->_em->hasFilters()) { - $first = true; + $first = true; foreach($this->_em->getFilters()->getEnabledFilters() as $filter) { if("" !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { if ( ! $first) $filterSql .= ' AND '; else $first = false; diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index 2353814b0..ff9332373 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -668,6 +668,7 @@ class CMSGroupPrefixFilter extends SQLFilter return $targetTableAlias.'.name LIKE ' . $this->getParameter('prefix'); // getParam uses connection to quote the value. } } + class CMSArticleTopicFilter extends SQLFilter { public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) From e8d30068e25e769a2c1bcf63c651def577fa541c Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 5 Dec 2011 22:05:42 +0100 Subject: [PATCH 32/85] [DDC-551] Various refactorings --- lib/Doctrine/ORM/Persisters/BasicEntityPersister.php | 9 ++++----- lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php | 1 + lib/Doctrine/ORM/Persisters/ManyToManyPersister.php | 9 ++++----- lib/Doctrine/ORM/Persisters/OneToManyPersister.php | 1 + lib/Doctrine/ORM/Persisters/SingleTablePersister.php | 1 + lib/Doctrine/ORM/Query/SqlWalker.php | 9 ++++----- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index ec725693f..c58c4c3bf 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -72,6 +72,7 @@ use PDO, * @author Roman Borschel * @author Giorgio Sironi * @author Benjamin Eberlei + * @author Alexander * @since 2.0 */ class BasicEntityPersister @@ -1592,16 +1593,14 @@ class BasicEntityPersister */ protected function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias) { - $filterSql = ''; + $filterClauses = array(); - $first = true; foreach($this->_em->getFilters()->getEnabledFilters() as $filter) { if('' !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { - if (!$first) $filterSql .= ' AND '; else $first = false; - $filterSql .= '(' . $filterExpr . ')'; + $filterClauses[] = '(' . $filterExpr . ')'; } } - return $filterSql; + return implode(' AND ', $filterClauses); } } diff --git a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php index daed5b01d..ad34f5c31 100644 --- a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php @@ -31,6 +31,7 @@ use Doctrine\ORM\ORMException, * * @author Roman Borschel * @author Benjamin Eberlei + * @author Alexander * @since 2.0 * @see http://martinfowler.com/eaaCatalog/classTableInheritance.html */ diff --git a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php index 41d7b24a9..f765b77f1 100644 --- a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php @@ -30,6 +30,7 @@ use Doctrine\ORM\Mapping\ClassMetadata, * * @author Roman Borschel * @author Guilherme Blanco + * @author Alexander * @since 2.0 */ class ManyToManyPersister extends AbstractCollectionPersister @@ -379,16 +380,14 @@ class ManyToManyPersister extends AbstractCollectionPersister */ protected function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias) { - $filterSql = ''; + $filterClauses = array(); - $first = true; foreach($this->_em->getFilters()->getEnabledFilters() as $filter) { if('' !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { - if($first) $first = false; else $filterSql .= ' AND '; - $filterSql .= '(' . $filterExpr . ')'; + $filterClauses[] = '(' . $filterExpr . ')'; } } - return $filterSql; + return implode(' AND ', $filterClauses); } } diff --git a/lib/Doctrine/ORM/Persisters/OneToManyPersister.php b/lib/Doctrine/ORM/Persisters/OneToManyPersister.php index 0cc380337..17575aaac 100644 --- a/lib/Doctrine/ORM/Persisters/OneToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/OneToManyPersister.php @@ -29,6 +29,7 @@ use Doctrine\ORM\PersistentCollection, * * @author Roman Borschel * @author Guilherme Blanco + * @author Alexander * @since 2.0 */ class OneToManyPersister extends AbstractCollectionPersister diff --git a/lib/Doctrine/ORM/Persisters/SingleTablePersister.php b/lib/Doctrine/ORM/Persisters/SingleTablePersister.php index d11486e93..cb005575f 100644 --- a/lib/Doctrine/ORM/Persisters/SingleTablePersister.php +++ b/lib/Doctrine/ORM/Persisters/SingleTablePersister.php @@ -27,6 +27,7 @@ use Doctrine\ORM\Mapping\ClassMetadata; * * @author Roman Borschel * @author Benjamin Eberlei + * @author Alexander * @since 2.0 * @link http://martinfowler.com/eaaCatalog/singleTableInheritance.html */ diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index e3d412df1..cf20f747b 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -33,6 +33,7 @@ use Doctrine\DBAL\LockMode, * @author Guilherme Blanco * @author Roman Borschel * @author Benjamin Eberlei + * @author Alexander * @since 2.0 * @todo Rename: SQLWalker */ @@ -362,19 +363,17 @@ class SqlWalker implements TreeWalker */ private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias) { - $filterSql = ''; + $filterClauses = array(); if($this->_em->hasFilters()) { - $first = true; foreach($this->_em->getFilters()->getEnabledFilters() as $filter) { if("" !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { - if ( ! $first) $filterSql .= ' AND '; else $first = false; - $filterSql .= '(' . $filterExpr . ')'; + $filterClauses[] = '(' . $filterExpr . ')'; } } } - return $filterSql; + return implode(' AND ', $filterClauses); } /** * Walks down a SelectStatement AST node, thereby generating the appropriate SQL. From f4663f45127e0dcd029b992dedc426a3cfa6fd1d Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 5 Dec 2011 22:19:54 +0100 Subject: [PATCH 33/85] [DDC-551] Another batch of small refactorings --- lib/Doctrine/ORM/EntityManager.php | 1 - lib/Doctrine/ORM/Persisters/ManyToManyPersister.php | 7 ++++--- lib/Doctrine/ORM/Query/SqlWalker.php | 11 ++++------- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 9adf82301..3f9e477c7 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -800,7 +800,6 @@ class EntityManager implements ObjectManager /** * Gets the enabled filters. * - * @access public * @return FilterCollection The active filter collection. */ public function getFilters() diff --git a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php index f765b77f1..e9f4b9820 100644 --- a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php @@ -360,11 +360,12 @@ class ManyToManyPersister extends AbstractCollectionPersister . $targetClass->getQuotedTableName($this->_conn->getDatabasePlatform()) . ' te' . ' ON'; - $first = true; + $joinTargetEntitySQLClauses = array(); foreach($mapping['relationToTargetKeyColumns'] as $joinTableColumn => $targetTableColumn) { - if(!$first) $joinTargetEntitySQL .= ' AND '; else $first = false; - $joinTargetEntitySQL .= ' t.' . $joinTableColumn . ' = ' . 'te.' . $targetTableColumn; + $joinTargetEntitySQLClauses[] = ' t.' . $joinTableColumn . ' = ' . 'te.' . $targetTableColumn; } + + $joinTargetEntitySQL .= implode(' AND ', $joinTargetEntitySQLClauses); } return array($joinTargetEntitySQL, $filterSql); diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index cf20f747b..e6a08bf5a 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -1502,24 +1502,21 @@ class SqlWalker implements TreeWalker $condSql = null !== $whereClause ? $this->walkConditionalExpression($whereClause->conditionalExpression) : ''; $discrSql = $this->_generateDiscriminatorColumnConditionSql($this->_rootAliases); - $filterSql = ''; - // Apply the filters for all entities in FROM - $first = true; + $filterClauses = array(); foreach ($this->_rootAliases as $dqlAlias) { $class = $this->_queryComponents[$dqlAlias]['metadata']; $tableAlias = $this->getSQLTableAlias($class->table['name'], $dqlAlias); if("" !== $filterExpr = $this->generateFilterConditionSQL($class, $tableAlias)) { - if ( ! $first) $filterSql .= ' AND '; else $first = false; - $filterSql .= $filterExpr; + $filterClauses[] = $filterExpr; } } - if ('' !== $filterSql) { + if (count($filterClauses)) { if($condSql) $condSql .= ' AND '; - $condSql .= $filterSql; + $condSql .= implode(' AND ', $filterClauses); } if ($condSql) { From efe7a014828508d46a06cbcb381a3c60e4b13c38 Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 5 Dec 2011 23:00:52 +0100 Subject: [PATCH 34/85] [DDC-551] Fixed CS, comments by @stof --- lib/Doctrine/ORM/EntityManager.php | 6 ++--- .../ORM/Persisters/BasicEntityPersister.php | 19 +++++++++------- .../Persisters/JoinedSubclassPersister.php | 13 ++++++----- .../ORM/Persisters/ManyToManyPersister.php | 14 ++++++------ .../ORM/Persisters/OneToManyPersister.php | 4 ++-- .../ORM/Persisters/SingleTablePersister.php | 2 +- lib/Doctrine/ORM/Query/Filter/SQLFilter.php | 8 ++----- lib/Doctrine/ORM/Query/FilterCollection.php | 10 ++++----- lib/Doctrine/ORM/Query/SqlWalker.php | 22 +++++++++---------- 9 files changed, 50 insertions(+), 48 deletions(-) diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 3f9e477c7..b353828ae 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -804,7 +804,7 @@ class EntityManager implements ObjectManager */ public function getFilters() { - if(null === $this->filterCollection) { + if (null === $this->filterCollection) { $this->filterCollection = new FilterCollection($this); } @@ -814,7 +814,7 @@ class EntityManager implements ObjectManager /** * Checks whether the state of the filter collection is clean. * - * @return boolean True, iff the filter collection is clean. + * @return boolean True, if the filter collection is clean. */ public function isFiltersStateClean() { @@ -825,7 +825,7 @@ class EntityManager implements ObjectManager /** * Checks whether the Entity Manager has filters. * - * @return True, iff the EM has a filter collection. + * @return True, if the EM has a filter collection. */ public function hasFilters() { diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index c58c4c3bf..9ce8acc69 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -903,8 +903,11 @@ class BasicEntityPersister $alias = $this->_getSQLTableAlias($this->_class->name); - if('' !== $filterSql = $this->generateFilterConditionSQL($this->_class, $alias)) { - if($conditionSql) $conditionSql .= ' AND '; + if ('' !== $filterSql = $this->generateFilterConditionSQL($this->_class, $alias)) { + if ($conditionSql) { + $conditionSql .= ' AND '; + } + $conditionSql .= $filterSql; } @@ -1033,7 +1036,7 @@ class BasicEntityPersister } // Add filter SQL - if('' !== $filterSql = $this->generateFilterConditionSQL($eagerEntity, $tableAlias)) { + if ('' !== $filterSql = $this->generateFilterConditionSQL($eagerEntity, $tableAlias)) { $this->_selectJoinSql .= ' AND ' . $filterSql; } } else { @@ -1541,7 +1544,7 @@ class BasicEntityPersister . $this->getLockTablesSql($alias) . ' WHERE ' . $this->_getSelectConditionSQL($criteria); - if('' !== $filterSql = $this->generateFilterConditionSQL($this->_class, $alias)) { + if ('' !== $filterSql = $this->generateFilterConditionSQL($this->_class, $alias)) { $sql .= ' AND ' . $filterSql; } @@ -1559,8 +1562,8 @@ class BasicEntityPersister protected function getJoinSQLForJoinColumns($joinColumns) { // if one of the join columns is nullable, return left join - foreach($joinColumns as $joinColumn) { - if(isset($joinColumn['nullable']) && $joinColumn['nullable']){ + foreach ($joinColumns as $joinColumn) { + if (isset($joinColumn['nullable']) && $joinColumn['nullable']) { return 'LEFT JOIN'; } } @@ -1595,8 +1598,8 @@ class BasicEntityPersister { $filterClauses = array(); - foreach($this->_em->getFilters()->getEnabledFilters() as $filter) { - if('' !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { + foreach ($this->_em->getFilters()->getEnabledFilters() as $filter) { + if ('' !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { $filterClauses[] = '(' . $filterExpr . ')'; } } diff --git a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php index ad34f5c31..02d6ab75c 100644 --- a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php @@ -329,9 +329,9 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister $joinSql .= $baseTableAlias . '.' . $idColumn . ' = ' . $tableAlias . '.' . $idColumn; - if($parentClass->name === $this->_class->rootEntityName) { + if ($parentClass->name === $this->_class->rootEntityName) { // Add filters on the root class - if('' !== $filterSql = $this->generateFilterConditionSQL($parentClass, $tableAlias)) { + if ('' !== $filterSql = $this->generateFilterConditionSQL($parentClass, $tableAlias)) { $joinSql .= ' AND ' . $filterSql; } } @@ -383,9 +383,12 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister $conditionSql = $this->_getSelectConditionSQL($criteria, $assoc); // If the current class in the root entity, add the filters - if($this->_class->name === $this->_class->rootEntityName) { - if('' !== $filterSql = $this->generateFilterConditionSQL($this->_class, $baseTableAlias)) { - if($conditionSql) $conditionSql .= ' AND '; + if ($this->_class->name === $this->_class->rootEntityName) { + if ('' !== $filterSql = $this->generateFilterConditionSQL($this->_class, $baseTableAlias)) { + if ($conditionSql) { + $conditionSql .= ' AND '; + } + $conditionSql .= $filterSql; } } diff --git a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php index e9f4b9820..bfb6ef08e 100644 --- a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php @@ -219,7 +219,7 @@ class ManyToManyPersister extends AbstractCollectionPersister } list($joinTargetEntitySQL, $filterSql) = $this->getFilterSql($mapping); - if('' !== $filterSql) { + if ('' !== $filterSql) { $whereClauses[] = $filterSql; } @@ -331,9 +331,9 @@ class ManyToManyPersister extends AbstractCollectionPersister : $sourceId[$sourceClass->fieldNames[$mapping['relationToSourceKeyColumns'][$joinTableColumn]]]; } - if($addFilters) { + if ($addFilters) { list($joinTargetEntitySQL, $filterSql) = $this->getFilterSql($mapping); - if('' !== $filterSql) { + if ('' !== $filterSql) { $quotedJoinTable .= ' t ' . $joinTargetEntitySQL; $whereClauses[] = $filterSql; } @@ -355,13 +355,13 @@ class ManyToManyPersister extends AbstractCollectionPersister // A join is needed if there is filtering on the target entity $joinTargetEntitySQL = ''; - if('' !== $filterSql = $this->generateFilterConditionSQL($targetClass, 'te')) { + if ('' !== $filterSql = $this->generateFilterConditionSQL($targetClass, 'te')) { $joinTargetEntitySQL = ' JOIN ' . $targetClass->getQuotedTableName($this->_conn->getDatabasePlatform()) . ' te' . ' ON'; $joinTargetEntitySQLClauses = array(); - foreach($mapping['relationToTargetKeyColumns'] as $joinTableColumn => $targetTableColumn) { + foreach ($mapping['relationToTargetKeyColumns'] as $joinTableColumn => $targetTableColumn) { $joinTargetEntitySQLClauses[] = ' t.' . $joinTableColumn . ' = ' . 'te.' . $targetTableColumn; } @@ -383,8 +383,8 @@ class ManyToManyPersister extends AbstractCollectionPersister { $filterClauses = array(); - foreach($this->_em->getFilters()->getEnabledFilters() as $filter) { - if('' !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { + foreach ($this->_em->getFilters()->getEnabledFilters() as $filter) { + if ('' !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { $filterClauses[] = '(' . $filterExpr . ')'; } } diff --git a/lib/Doctrine/ORM/Persisters/OneToManyPersister.php b/lib/Doctrine/ORM/Persisters/OneToManyPersister.php index 17575aaac..2fe1d5acb 100644 --- a/lib/Doctrine/ORM/Persisters/OneToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/OneToManyPersister.php @@ -121,8 +121,8 @@ class OneToManyPersister extends AbstractCollectionPersister : $id[$sourceClass->fieldNames[$joinColumn['referencedColumnName']]]; } - foreach($this->_em->getFilters()->getEnabledFilters() as $filter) { - if("" !== $filterExpr = $filter->addFilterConstraint($targetClass, 't')) { + foreach ($this->_em->getFilters()->getEnabledFilters() as $filter) { + if ('' !== $filterExpr = $filter->addFilterConstraint($targetClass, 't')) { $whereClauses[] = '(' . $filterExpr . ')'; } } diff --git a/lib/Doctrine/ORM/Persisters/SingleTablePersister.php b/lib/Doctrine/ORM/Persisters/SingleTablePersister.php index cb005575f..39a6b4954 100644 --- a/lib/Doctrine/ORM/Persisters/SingleTablePersister.php +++ b/lib/Doctrine/ORM/Persisters/SingleTablePersister.php @@ -138,7 +138,7 @@ class SingleTablePersister extends AbstractEntityInheritancePersister { // Ensure that the filters are applied to the root entity of the inheritance tree $realTargetEntity = $targetEntity; - if($targetEntity->name !== $targetEntity->rootEntityName) { + if ($targetEntity->name !== $targetEntity->rootEntityName) { $realTargetEntity = $this->_em->getClassMetadata($targetEntity->rootEntityName); } diff --git a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php index 9be8628a2..772ef683b 100644 --- a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php +++ b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php @@ -49,7 +49,6 @@ abstract class SQLFilter * Constructs the SQLFilter object. * * @param EntityManager $em The EM - * @final */ final public function __construct(EntityManager $em) { @@ -63,7 +62,6 @@ abstract class SQLFilter * @param string $value Value of the parameter. * @param string $type Type of the parameter. * - * @final * @return SQLFilter The current SQL filter. */ final public function setParameter($name, $value, $type) @@ -88,12 +86,11 @@ abstract class SQLFilter * * @param string $name Name of the parameter. * - * @final * @return string The SQL escaped parameter to use in a query. */ final public function getParameter($name) { - if(!isset($this->parameters[$name])) { + if (!isset($this->parameters[$name])) { throw new \InvalidArgumentException("Parameter '" . $name . "' does not exist."); } @@ -103,8 +100,7 @@ abstract class SQLFilter /** * Returns as string representation of the SQLFilter parameters (the state). * - * @final - * @return string String representation of the the SQLFilter. + * @return string String representation of the SQLFilter. */ final public function __toString() { diff --git a/lib/Doctrine/ORM/Query/FilterCollection.php b/lib/Doctrine/ORM/Query/FilterCollection.php index 8e055ecdb..35c8d043c 100644 --- a/lib/Doctrine/ORM/Query/FilterCollection.php +++ b/lib/Doctrine/ORM/Query/FilterCollection.php @@ -103,11 +103,11 @@ class FilterCollection */ public function enable($name) { - if(null === $filterClass = $this->config->getFilterClassName($name)) { + if (null === $filterClass = $this->config->getFilterClassName($name)) { throw new \InvalidArgumentException("Filter '" . $name . "' does not exist."); } - if(!isset($this->enabledFilters[$name])) { + if (!isset($this->enabledFilters[$name])) { $this->enabledFilters[$name] = new $filterClass($this->em); // Keep the enabled filters sorted for the hash @@ -153,7 +153,7 @@ class FilterCollection */ public function getFilter($name) { - if(!isset($this->enabledFilters[$name])) { + if (!isset($this->enabledFilters[$name])) { throw new \InvalidArgumentException("Filter '" . $name . "' is not enabled."); } @@ -176,12 +176,12 @@ class FilterCollection public function getHash() { // If there are only clean filters, the previous hash can be returned - if(self::FILTERS_STATE_CLEAN === $this->filtersState) { + if (self::FILTERS_STATE_CLEAN === $this->filtersState) { return $this->filterHash; } $filterHash = ''; - foreach($this->enabledFilters as $name => $filter) { + foreach ($this->enabledFilters as $name => $filter) { $filterHash .= $name . $filter; } diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index e6a08bf5a..ea834fc6a 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -365,9 +365,9 @@ class SqlWalker implements TreeWalker { $filterClauses = array(); - if($this->_em->hasFilters()) { - foreach($this->_em->getFilters()->getEnabledFilters() as $filter) { - if("" !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { + if ($this->_em->hasFilters()) { + foreach ($this->_em->getFilters()->getEnabledFilters() as $filter) { + if ('' !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { $filterClauses[] = '(' . $filterExpr . ')'; } } @@ -827,9 +827,8 @@ class SqlWalker implements TreeWalker } // Apply the filters - if("" !== $filterExpr = $this->generateFilterConditionSQL($targetClass, $targetTableAlias)) { - if ( ! $first) $sql .= ' AND '; else $first = false; - $sql .= $filterExpr; + if ('' !== $filterExpr = $this->generateFilterConditionSQL($targetClass, $targetTableAlias)) { + $sql .= ' AND ' . $filterExpr; } } else if ($assoc['type'] == ClassMetadata::MANY_TO_MANY) { // Join relation table @@ -896,9 +895,8 @@ class SqlWalker implements TreeWalker } // Apply the filters - if("" !== $filterExpr = $this->generateFilterConditionSQL($targetClass, $targetTableAlias)) { - if ( ! $first) $sql .= ' AND '; else $first = false; - $sql .= $filterExpr; + if ('' !== $filterExpr = $this->generateFilterConditionSQL($targetClass, $targetTableAlias)) { + $sql .= ' AND ' . $filterExpr; } } @@ -1508,13 +1506,15 @@ class SqlWalker implements TreeWalker $class = $this->_queryComponents[$dqlAlias]['metadata']; $tableAlias = $this->getSQLTableAlias($class->table['name'], $dqlAlias); - if("" !== $filterExpr = $this->generateFilterConditionSQL($class, $tableAlias)) { + if ('' !== $filterExpr = $this->generateFilterConditionSQL($class, $tableAlias)) { $filterClauses[] = $filterExpr; } } if (count($filterClauses)) { - if($condSql) $condSql .= ' AND '; + if ($condSql) { + $condSql .= ' AND '; + } $condSql .= implode(' AND ', $filterClauses); } From 5e91f0c1ca473f2c899c329c3a844257e7f48cd5 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 7 Dec 2011 10:02:15 +0100 Subject: [PATCH 35/85] [DDC-551] Update SQLWalker to reflect filter requirements for inheritance --- lib/Doctrine/ORM/Query/SqlWalker.php | 37 ++++++++++++++++--- .../Tests/ORM/Functional/SQLFilterTest.php | 14 +++++++ 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index ea834fc6a..69bf903be 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -268,6 +268,11 @@ class SqlWalker implements TreeWalker $sqlParts[] = $baseTableAlias . '.' . $columnName . ' = ' . $tableAlias . '.' . $columnName; } + // Add filters on the root class + if ('' !== $filterSql = $this->generateFilterConditionSQL($parentClass, $tableAlias)) { + $sqlParts[] = $filterSql; + } + $sql .= implode(' AND ', $sqlParts); } @@ -363,13 +368,35 @@ class SqlWalker implements TreeWalker */ private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias) { - $filterClauses = array(); + if (!$this->_em->hasFilters()) { + return ''; + } - if ($this->_em->hasFilters()) { - foreach ($this->_em->getFilters()->getEnabledFilters() as $filter) { - if ('' !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { - $filterClauses[] = '(' . $filterExpr . ')'; + switch($targetEntity->inheritanceType) { + case ClassMetadata::INHERITANCE_TYPE_NONE: + break; + case ClassMetadata::INHERITANCE_TYPE_JOINED: + // The classes in the inheritance will be added to the query one by one, + // but only the root node is getting filtered + if ($targetEntity->name !== $targetEntity->rootEntityName) { + return ''; } + break; + case ClassMetadata::INHERITANCE_TYPE_SINGLE_TABLE: + // With STI the table will only be queried once, make sure that the filters + // are added to the root entity + $targetEntity = $this->_em->getClassMetadata($targetEntity->rootEntityName); + break; + default: + //@todo: throw exception? + return ''; + break; + } + + $filterClauses = array(); + foreach ($this->_em->getFilters()->getEnabledFilters() as $filter) { + if ('' !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { + $filterClauses[] = '(' . $filterExpr . ')'; } } diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index ff9332373..d56ddb99b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -519,7 +519,10 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testJoinSubclassPersister_FilterOnlyOnRootTableWhenFetchingSubEntity() { $this->loadCompanyJoinedSubclassFixtureData(); + // Persister $this->assertEquals(2, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll())); + // SQLWalker + $this->assertEquals(2, count($this->_em->createQuery("SELECT cm FROM Doctrine\Tests\Models\Company\CompanyManager cm")->getResult())); // Enable the filter $conf = $this->_em->getConfiguration(); @@ -531,12 +534,15 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $managers = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll(); $this->assertEquals(1, count($managers)); $this->assertEquals("Guilherme", $managers[0]->getName()); + + $this->assertEquals(1, count($this->_em->createQuery("SELECT cm FROM Doctrine\Tests\Models\Company\CompanyManager cm")->getResult())); } public function testJoinSubclassPersister_FilterOnlyOnRootTableWhenFetchingRootEntity() { $this->loadCompanyJoinedSubclassFixtureData(); $this->assertEquals(3, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyPerson')->findAll())); + $this->assertEquals(3, count($this->_em->createQuery("SELECT cp FROM Doctrine\Tests\Models\Company\CompanyPerson cp")->getResult())); // Enable the filter $conf = $this->_em->getConfiguration(); @@ -548,6 +554,8 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $persons = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyPerson')->findAll(); $this->assertEquals(1, count($persons)); $this->assertEquals("Guilherme", $persons[0]->getName()); + + $this->assertEquals(1, count($this->_em->createQuery("SELECT cp FROM Doctrine\Tests\Models\Company\CompanyPerson cp")->getResult())); } private function loadCompanyJoinedSubclassFixtureData() @@ -577,7 +585,10 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testSingleTableInheritance_FilterOnlyOnRootTableWhenFetchingSubEntity() { $this->loadCompanySingleTableInheritanceFixtureData(); + // Persister $this->assertEquals(2, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyFlexUltraContract')->findAll())); + // SQLWalker + $this->assertEquals(2, count($this->_em->createQuery("SELECT cfc FROM Doctrine\Tests\Models\Company\CompanyFlexUltraContract cfc")->getResult())); // Enable the filter $conf = $this->_em->getConfiguration(); @@ -586,12 +597,14 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase ->enable("completed_contract"); $this->assertEquals(1, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyFlexUltraContract')->findAll())); + $this->assertEquals(1, count($this->_em->createQuery("SELECT cfc FROM Doctrine\Tests\Models\Company\CompanyFlexUltraContract cfc")->getResult())); } public function testSingleTableInheritance_FilterOnlyOnRootTableWhenFetchingRootEntity() { $this->loadCompanySingleTableInheritanceFixtureData(); $this->assertEquals(4, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyFlexContract')->findAll())); + $this->assertEquals(4, count($this->_em->createQuery("SELECT cfc FROM Doctrine\Tests\Models\Company\CompanyFlexContract cfc")->getResult())); // Enable the filter $conf = $this->_em->getConfiguration(); @@ -600,6 +613,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase ->enable("completed_contract"); $this->assertEquals(2, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyFlexContract')->findAll())); + $this->assertEquals(2, count($this->_em->createQuery("SELECT cfc FROM Doctrine\Tests\Models\Company\CompanyFlexContract cfc")->getResult())); } private function loadCompanySingleTableInheritanceFixtureData() From df19e68a8613b783591631f64851cc1f6a8c4dbf Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Wed, 7 Dec 2011 11:23:15 -0200 Subject: [PATCH 36/85] Fixed DDC-1057 --- lib/Doctrine/ORM/Query/ResultSetMapping.php | 31 ++++++++++++++-- .../ORM/Hydration/ResultSetMappingTest.php | 37 +++++++++++++++++++ 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Query/ResultSetMapping.php b/lib/Doctrine/ORM/Query/ResultSetMapping.php index 5c6305e25..68713a7cc 100644 --- a/lib/Doctrine/ORM/Query/ResultSetMapping.php +++ b/lib/Doctrine/ORM/Query/ResultSetMapping.php @@ -120,6 +120,7 @@ class ResultSetMapping * results or joined entity results within this ResultSetMapping. * @param string $resultAlias The result alias with which the entity result should be * placed in the result structure. + * @return ResultSetMapping This ResultSetMapping instance. * * @todo Rename: addRootEntity */ @@ -131,6 +132,8 @@ class ResultSetMapping if ($resultAlias !== null) { $this->isMixed = true; } + + return $this; } /** @@ -141,13 +144,16 @@ class ResultSetMapping * @param string $alias The alias of the entity result or joined entity result the discriminator * column should be used for. * @param string $discrColumn The name of the discriminator column in the SQL result set. - * + * @return ResultSetMapping This ResultSetMapping instance. + * * @todo Rename: addDiscriminatorColumn */ public function setDiscriminatorColumn($alias, $discrColumn) { $this->discriminatorColumns[$alias] = $discrColumn; $this->columnOwnerMap[$discrColumn] = $alias; + + return $this; } /** @@ -155,6 +161,7 @@ class ResultSetMapping * * @param string $alias The alias of an entity result or joined entity result. * @param string $fieldName The name of the field to use for indexing. + * @return ResultSetMapping This ResultSetMapping instance. */ public function addIndexBy($alias, $fieldName) { @@ -168,6 +175,8 @@ class ResultSetMapping break; } + + return $this; /* TODO: check if this exception can be put back, for now it's gone because of assumptions made by some ORM internals if ( ! $found) { @@ -186,11 +195,13 @@ class ResultSetMapping * Set to index by a scalar result column name * * @param $resultColumnName - * @return void + * @return ResultSetMapping This ResultSetMapping instance. */ public function addIndexByScalar($resultColumnName) { $this->indexByMap['scalars'] = $resultColumnName; + + return $this; } /** @@ -198,11 +209,13 @@ class ResultSetMapping * * @param $alias * @param $resultColumnName - * @return void + * @return ResultSetMapping This ResultSetMapping instance. */ public function addIndexByColumn($alias, $resultColumnName) { $this->indexByMap[$alias] = $resultColumnName; + + return $this; } /** @@ -242,6 +255,7 @@ class ResultSetMapping * the field $fieldName is defined on a subclass, specify that here. * If not specified, the field is assumed to belong to the class * designated by $alias. + * @return ResultSetMapping This ResultSetMapping instance. * @todo Rename: addField */ public function addFieldResult($alias, $columnName, $fieldName, $declaringClass = null) @@ -256,6 +270,8 @@ class ResultSetMapping if ( ! $this->isMixed && $this->scalarMappings) { $this->isMixed = true; } + + return $this; } /** @@ -265,6 +281,7 @@ class ResultSetMapping * @param string $alias The unique alias to use for the joined entity. * @param string $parentAlias The alias of the entity result that is the parent of this joined result. * @param object $relation The association field that connects the parent entity result with the joined entity result. + * @return ResultSetMapping This ResultSetMapping instance. * @todo Rename: addJoinedEntity */ public function addJoinedEntityResult($class, $alias, $parentAlias, $relation) @@ -272,6 +289,8 @@ class ResultSetMapping $this->aliasMap[$alias] = $class; $this->parentAliasMap[$alias] = $parentAlias; $this->relationMap[$alias] = $relation; + + return $this; } /** @@ -279,6 +298,7 @@ class ResultSetMapping * * @param string $columnName The name of the column in the SQL result set. * @param string $alias The result alias with which the scalar result should be placed in the result structure. + * @return ResultSetMapping This ResultSetMapping instance. * @todo Rename: addScalar */ public function addScalarResult($columnName, $alias) @@ -288,6 +308,8 @@ class ResultSetMapping if ( ! $this->isMixed && $this->fieldMappings) { $this->isMixed = true; } + + return $this; } /** @@ -439,6 +461,7 @@ class ResultSetMapping * @param string $columnName * @param string $fieldName * @param bool + * @return ResultSetMapping This ResultSetMapping instance. */ public function addMetaResult($alias, $columnName, $fieldName, $isIdentifierColumn = false) { @@ -448,5 +471,7 @@ class ResultSetMapping if ($isIdentifierColumn) { $this->isIdentifierColumn[$alias][$columnName] = true; } + + return $this; } } diff --git a/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php b/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php index 562fd4d87..d18c4dbb7 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php @@ -14,7 +14,14 @@ require_once __DIR__ . '/../../TestInit.php'; */ class ResultSetMappingTest extends \Doctrine\Tests\OrmTestCase { + /** + * @var ResultSetMapping + */ private $_rsm; + + /** + * @var \Doctrine\ORM\EntityManager + */ private $_em; protected function setUp() { @@ -56,5 +63,35 @@ class ResultSetMappingTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals('username', $this->_rsm->getFieldName('username')); $this->assertEquals('name', $this->_rsm->getFieldName('name')); } + + /** + * @group DDC-1057 + * + * Fluent interface test, not a real result set mapping + */ + public function testFluentInterface() + { + $rms = $this->_rsm; + + $rms->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser','u') + ->addJoinedEntityResult('Doctrine\Tests\Models\CMS\CmsPhonenumber','p','u','phonenumbers') + ->addFieldResult('u', 'id', 'id') + ->addFieldResult('u', 'name', 'name') + ->setDiscriminatorColumn('name', 'name') + ->addIndexByColumn('id', 'id') + ->addIndexBy('username', 'username') + ->addIndexByScalar('sclr0') + ->addScalarResult('sclr0', 'numPhones') + ->addMetaResult('a', 'user_id', 'user_id'); + + + $this->assertTrue($rms->hasIndexBy('id')); + $this->assertTrue($rms->isFieldResult('id')); + $this->assertTrue($rms->isFieldResult('name')); + $this->assertTrue($rms->isScalarResult('sclr0')); + $this->assertTrue($rms->isRelation('p')); + $this->assertTrue($rms->hasParentAlias('p')); + $this->assertTrue($rms->isMixedResult()); + } } From c6a89c64f30527625097f5e440fa6a9c559d42a3 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Wed, 7 Dec 2011 12:16:27 -0200 Subject: [PATCH 37/85] put return after comment --- lib/Doctrine/ORM/Query/ResultSetMapping.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Query/ResultSetMapping.php b/lib/Doctrine/ORM/Query/ResultSetMapping.php index 68713a7cc..239f79c9e 100644 --- a/lib/Doctrine/ORM/Query/ResultSetMapping.php +++ b/lib/Doctrine/ORM/Query/ResultSetMapping.php @@ -176,8 +176,6 @@ class ResultSetMapping break; } - return $this; - /* TODO: check if this exception can be put back, for now it's gone because of assumptions made by some ORM internals if ( ! $found) { $message = sprintf( @@ -189,6 +187,8 @@ class ResultSetMapping throw new \LogicException($message); } */ + + return $this; } /** From 8e50a31b98e1a7ceaab89f54e9c18b684c911514 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Wed, 7 Dec 2011 12:31:23 -0200 Subject: [PATCH 38/85] trying remove whitespaces --- lib/Doctrine/ORM/Query/ResultSetMapping.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Query/ResultSetMapping.php b/lib/Doctrine/ORM/Query/ResultSetMapping.php index 239f79c9e..3c292fda4 100644 --- a/lib/Doctrine/ORM/Query/ResultSetMapping.php +++ b/lib/Doctrine/ORM/Query/ResultSetMapping.php @@ -121,7 +121,6 @@ class ResultSetMapping * @param string $resultAlias The result alias with which the entity result should be * placed in the result structure. * @return ResultSetMapping This ResultSetMapping instance. - * * @todo Rename: addRootEntity */ public function addEntityResult($class, $alias, $resultAlias = null) @@ -145,7 +144,6 @@ class ResultSetMapping * column should be used for. * @param string $discrColumn The name of the discriminator column in the SQL result set. * @return ResultSetMapping This ResultSetMapping instance. - * * @todo Rename: addDiscriminatorColumn */ public function setDiscriminatorColumn($alias, $discrColumn) @@ -175,7 +173,7 @@ class ResultSetMapping break; } - + /* TODO: check if this exception can be put back, for now it's gone because of assumptions made by some ORM internals if ( ! $found) { $message = sprintf( From 0febf0611439e05abbb1bf4b4e9668f7ad125c67 Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Fri, 9 Dec 2011 00:04:47 -0500 Subject: [PATCH 39/85] Made ClassMetadataBuilder support ClassMetadataInfo instead of ClassMetadata. Fixed DDC-1508. --- .../Mapping/Builder/ClassMetadataBuilder.php | 97 +++++++++++++++---- 1 file changed, 80 insertions(+), 17 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/Builder/ClassMetadataBuilder.php b/lib/Doctrine/ORM/Mapping/Builder/ClassMetadataBuilder.php index 978a87601..f7d5031cd 100644 --- a/lib/Doctrine/ORM/Mapping/Builder/ClassMetadataBuilder.php +++ b/lib/Doctrine/ORM/Mapping/Builder/ClassMetadataBuilder.php @@ -19,7 +19,8 @@ namespace Doctrine\ORM\Mapping\Builder; -use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\Mapping\ClassMetadata, + Doctrine\ORM\Mapping\ClassMetadataInfo; /** * Builder Object for ClassMetadata @@ -28,18 +29,19 @@ use Doctrine\ORM\Mapping\ClassMetadata; * @link www.doctrine-project.com * @since 2.2 * @author Benjamin Eberlei + * @author Guilherme Blanco */ class ClassMetadataBuilder { /** - * @var ClassMetadata + * @var \Doctrine\ORM\Mapping\ClassMetadataInfo */ private $cm; /** - * @param ClassMetadata $cm + * @param \Doctrine\ORM\Mapping\ClassMetadataInfo $cm */ - public function __construct(ClassMetadata $cm) + public function __construct(ClassMetadataInfo $cm) { $this->cm = $cm; } @@ -60,6 +62,7 @@ class ClassMetadataBuilder public function setMappedSuperClass() { $this->cm->isMappedSuperclass = true; + return $this; } @@ -72,6 +75,7 @@ class ClassMetadataBuilder public function setCustomRepositoryClass($repositoryClassName) { $this->cm->setCustomRepositoryClass($repositoryClassName); + return $this; } @@ -83,6 +87,7 @@ class ClassMetadataBuilder public function setReadOnly() { $this->cm->markReadOnly(); + return $this; } @@ -95,6 +100,7 @@ class ClassMetadataBuilder public function setTable($name) { $this->cm->setPrimaryTable(array('name' => $name)); + return $this; } @@ -110,7 +116,9 @@ class ClassMetadataBuilder if (!isset($this->cm->table['indexes'])) { $this->cm->table['indexes'] = array(); } + $this->cm->table['indexes'][$name] = array('columns' => $columns); + return $this; } @@ -123,10 +131,12 @@ class ClassMetadataBuilder */ public function addUniqueConstraint(array $columns, $name) { - if (!isset($this->cm->table['uniqueConstraints'])) { + if ( ! isset($this->cm->table['uniqueConstraints'])) { $this->cm->table['uniqueConstraints'] = array(); } + $this->cm->table['uniqueConstraints'][$name] = array('columns' => $columns); + return $this; } @@ -143,6 +153,7 @@ class ClassMetadataBuilder 'name' => $name, 'query' => $dqlQuery, )); + return $this; } @@ -154,6 +165,7 @@ class ClassMetadataBuilder public function setJoinedTableInheritance() { $this->cm->setInheritanceType(ClassMetadata::INHERITANCE_TYPE_JOINED); + return $this; } @@ -165,6 +177,7 @@ class ClassMetadataBuilder public function setSingleTableInheritance() { $this->cm->setInheritanceType(ClassMetadata::INHERITANCE_TYPE_SINGLE_TABLE); + return $this; } @@ -181,12 +194,13 @@ class ClassMetadataBuilder 'type' => $type, 'length' => $length, )); + return $this; } /** * Add a subclass to this inheritance hierachy. - * + * * @param string $name * @param string $class * @return ClassMetadataBuilder @@ -194,6 +208,7 @@ class ClassMetadataBuilder public function addDiscriminatorMapClass($name, $class) { $this->cm->addDiscriminatorMapClass($name, $class); + return $this; } @@ -205,6 +220,7 @@ class ClassMetadataBuilder public function setChangeTrackingPolicyDeferredExplicit() { $this->cm->setChangeTrackingPolicy(ClassMetadata::CHANGETRACKING_DEFERRED_EXPLICIT); + return $this; } @@ -216,12 +232,13 @@ class ClassMetadataBuilder public function setChangeTrackingPolicyNotify() { $this->cm->setChangeTrackingPolicy(ClassMetadata::CHANGETRACKING_NOTIFY); + return $this; } /** * Add lifecycle event - * + * * @param string $methodName * @param string $event * @return ClassMetadataBuilder @@ -229,6 +246,7 @@ class ClassMetadataBuilder public function addLifecycleEvent($methodName, $event) { $this->cm->addLifecycleCallback($methodName, $event); + return $this; } @@ -243,7 +261,9 @@ class ClassMetadataBuilder { $mapping['fieldName'] = $name; $mapping['type'] = $type; + $this->cm->mapField($mapping); + return $this; } @@ -256,12 +276,18 @@ class ClassMetadataBuilder */ public function createField($name, $type) { - return new FieldBuilder($this, array('fieldName' => $name, 'type' => $type)); + return new FieldBuilder( + $this, + array( + 'fieldName' => $name, + 'type' => $type + ) + ); } /** * Add a simple many to one association, optionally with the inversed by field. - * + * * @param string $name * @param string $targetEntity * @param string|null $inversedBy @@ -270,9 +296,11 @@ class ClassMetadataBuilder public function addManyToOne($name, $targetEntity, $inversedBy = null) { $builder = $this->createManyToOne($name, $targetEntity); + if ($inversedBy) { $builder->setInversedBy($inversedBy); } + return $builder->build(); } @@ -287,19 +315,33 @@ class ClassMetadataBuilder */ public function createManyToOne($name, $targetEntity) { - return new AssociationBuilder($this, array('fieldName' => $name, 'targetEntity' => $targetEntity), ClassMetadata::MANY_TO_ONE); + return new AssociationBuilder( + $this, + array( + 'fieldName' => $name, + 'targetEntity' => $targetEntity + ), + ClassMetadata::MANY_TO_ONE + ); } /** * Create OneToOne Assocation Builder - * + * * @param string $name * @param string $targetEntity * @return AssociationBuilder */ public function createOneToOne($name, $targetEntity) { - return new AssociationBuilder($this, array('fieldName' => $name, 'targetEntity' => $targetEntity), ClassMetadata::ONE_TO_ONE); + return new AssociationBuilder( + $this, + array( + 'fieldName' => $name, + 'targetEntity' => $targetEntity + ), + ClassMetadata::ONE_TO_ONE + ); } /** @@ -314,6 +356,7 @@ class ClassMetadataBuilder { $builder = $this->createOneToOne($name, $targetEntity); $builder->setMappedBy($mappedBy); + return $builder->build(); } @@ -328,9 +371,11 @@ class ClassMetadataBuilder public function addOwningOneToOne($name, $targetEntity, $inversedBy = null) { $builder = $this->createOneToOne($name, $targetEntity); + if ($inversedBy) { $builder->setInversedBy($inversedBy); } + return $builder->build(); } @@ -343,12 +388,19 @@ class ClassMetadataBuilder */ public function createManyToMany($name, $targetEntity) { - return new ManyToManyAssociationBuilder($this, array('fieldName' => $name, 'targetEntity' => $targetEntity), ClassMetadata::MANY_TO_MANY); + return new ManyToManyAssociationBuilder( + $this, + array( + 'fieldName' => $name, + 'targetEntity' => $targetEntity + ), + ClassMetadata::MANY_TO_MANY + ); } /** * Add a simple owning many to many assocation. - * + * * @param string $name * @param string $targetEntity * @param string|null $inversedBy @@ -357,9 +409,11 @@ class ClassMetadataBuilder public function addOwningManyToMany($name, $targetEntity, $inversedBy = null) { $builder = $this->createManyToMany($name, $targetEntity); + if ($inversedBy) { $builder->setInversedBy($inversedBy); } + return $builder->build(); } @@ -375,24 +429,32 @@ class ClassMetadataBuilder { $builder = $this->createManyToMany($name, $targetEntity); $builder->setMappedBy($mappedBy); + return $builder->build(); } /** * Create a one to many assocation builder - * + * * @param string $name * @param string $targetEntity * @return OneToManyAssociationBuilder */ public function createOneToMany($name, $targetEntity) { - return new OneToManyAssociationBuilder($this, array('fieldName' => $name, 'targetEntity' => $targetEntity), ClassMetadata::ONE_TO_MANY); + return new OneToManyAssociationBuilder( + $this, + array( + 'fieldName' => $name, + 'targetEntity' => $targetEntity + ), + ClassMetadata::ONE_TO_MANY + ); } /** * Add simple OneToMany assocation. - * + * * @param string $name * @param string $targetEntity * @param string $mappedBy @@ -402,6 +464,7 @@ class ClassMetadataBuilder { $builder = $this->createOneToMany($name, $targetEntity); $builder->setMappedBy($mappedBy); + return $builder->build(); } } From 954b5077e495aa9fa4eb54ef4cb8ac309e9415ae Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Fri, 9 Dec 2011 10:59:53 -0500 Subject: [PATCH 40/85] Fixed nesting recursion error in some situations. Complement to DDC-1276. --- lib/Doctrine/ORM/UnitOfWork.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 803e6683c..eb3111fb8 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1735,7 +1735,7 @@ class UnitOfWork implements PropertyChangedListener $managedCol->initialize(); // clear and set dirty a managed collection if its not also the same collection to merge from. - if (!$managedCol->isEmpty() && $managedCol != $mergeCol) { + if (!$managedCol->isEmpty() && $managedCol !== $mergeCol) { $managedCol->unwrap()->clear(); $managedCol->setDirty(true); From 2ce924673392fb6cb18370e84a116a64d989c2a5 Mon Sep 17 00:00:00 2001 From: Deni Date: Sun, 11 Dec 2011 17:24:38 +0400 Subject: [PATCH 41/85] Fixed typo in the XmlDriver --- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 2 +- .../ORM/Mapping/XmlMappingDriverTest.php | 18 +++++++++++++++ ...ts.Models.DDC117.DDC117Translation.dcm.xml | 22 +++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC117.DDC117Translation.dcm.xml diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 8228ba1ca..5785ccf2c 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -216,7 +216,7 @@ class XmlDriver extends AbstractFileDriver $associationIds = array(); foreach ($xmlRoot->id as $idElement) { if ((bool)$idElement['association-key'] == true) { - $associationIds[(string)$idElement['fieldName']] = true; + $associationIds[(string)$idElement['name']] = true; continue; } diff --git a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php index 8308ea260..9ba8748f4 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php @@ -33,6 +33,24 @@ class XmlMappingDriverTest extends AbstractMappingDriverTest $this->assertEquals($expectedMap, $class->discriminatorMap); } + public function testIdentifierWithAssociationKey() + { + $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\DDC117\DDC117Translation'); + + $this->assertEquals(array('language', 'article'), $class->identifier); + $this->assertArrayHasKey('article', $class->associationMappings); + + $this->assertArrayHasKey('id', $class->associationMappings['article']); + $this->assertTrue($class->associationMappings['article']['id']); + } + /** * @param string $xmlMappingFile * @dataProvider dataValidSchema diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC117.DDC117Translation.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC117.DDC117Translation.dcm.xml new file mode 100644 index 000000000..c0df0886a --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC117.DDC117Translation.dcm.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file From bd0fb574e3ac0a578202b171b83775b9a3bbf953 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 11 Dec 2011 16:07:35 +0100 Subject: [PATCH 42/85] DDC-1515 - Merge from 2.1.x --- .../Internal/Hydration/AbstractHydrator.php | 1 + .../ORM/Internal/Hydration/ObjectHydrator.php | 4 +- .../ORM/Functional/Ticket/DDC1515Test.php | 64 +++++++++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1515Test.php diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index 146dfb5c5..436a93666 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -244,6 +244,7 @@ abstract class AbstractHydrator if (isset($cache[$key]['isMetaColumn'])) { if ( ! isset($rowData[$dqlAlias][$cache[$key]['fieldName']]) || $value !== null) { + $nonemptyComponents[$dqlAlias] = true; $rowData[$dqlAlias][$cache[$key]['fieldName']] = $value; } diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index 36dbfa46a..49737ac58 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -332,9 +332,9 @@ class ObjectHydrator extends AbstractHydrator // Hydrate the data chunks foreach ($rowData as $dqlAlias => $data) { $entityName = $this->_rsm->aliasMap[$dqlAlias]; - + if (isset($this->_rsm->parentAliasMap[$dqlAlias])) { - // It's a joined result + // It's a joined result $parentAlias = $this->_rsm->parentAliasMap[$dqlAlias]; // we need the $path to save into the identifier map which entities were already diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1515Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1515Test.php new file mode 100644 index 000000000..9bd3360b8 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1515Test.php @@ -0,0 +1,64 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1515Foo'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1515Bar'), + )); + } + + public function testIssue() + { + $bar = new DDC1515Bar(); + $this->_em->persist($bar); + $this->_em->flush(); + + $foo = new DDC1515Foo(); + $foo->bar = $bar; + $this->_em->persist($foo); + $this->_em->flush(); + $this->_em->clear(); + + $bar = $this->_em->find(__NAMESPACE__ . '\DDC1515Bar', $bar->id); + $this->assertInstanceOf(__NAMESPACE__.'\DDC1515Foo', $bar->foo); + } +} + +/** + * @Entity + */ +class DDC1515Foo +{ + /** + * @OneToOne(targetEntity="DDC1515Bar", inversedBy="foo") @Id + */ + public $bar; +} + +/** + * @Entity + */ +class DDC1515Bar +{ + /** + * @Id @Column(type="integer") @GeneratedValue + */ + public $id; + + /** + * @OneToOne(targetEntity="DDC1515Foo", mappedBy="bar") + */ + public $foo; +} + + From 57970499fdd2eb6436494131fba517dde70541a7 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 11 Dec 2011 16:11:16 +0100 Subject: [PATCH 43/85] Revert "DDC-1515 - Merge from 2.1.x" This reverts commit bd0fb574e3ac0a578202b171b83775b9a3bbf953. --- .../Internal/Hydration/AbstractHydrator.php | 1 - .../ORM/Internal/Hydration/ObjectHydrator.php | 4 +- .../ORM/Functional/Ticket/DDC1515Test.php | 64 ------------------- 3 files changed, 2 insertions(+), 67 deletions(-) delete mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1515Test.php diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index 436a93666..146dfb5c5 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -244,7 +244,6 @@ abstract class AbstractHydrator if (isset($cache[$key]['isMetaColumn'])) { if ( ! isset($rowData[$dqlAlias][$cache[$key]['fieldName']]) || $value !== null) { - $nonemptyComponents[$dqlAlias] = true; $rowData[$dqlAlias][$cache[$key]['fieldName']] = $value; } diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index 49737ac58..36dbfa46a 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -332,9 +332,9 @@ class ObjectHydrator extends AbstractHydrator // Hydrate the data chunks foreach ($rowData as $dqlAlias => $data) { $entityName = $this->_rsm->aliasMap[$dqlAlias]; - + if (isset($this->_rsm->parentAliasMap[$dqlAlias])) { - // It's a joined result + // It's a joined result $parentAlias = $this->_rsm->parentAliasMap[$dqlAlias]; // we need the $path to save into the identifier map which entities were already diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1515Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1515Test.php deleted file mode 100644 index 9bd3360b8..000000000 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1515Test.php +++ /dev/null @@ -1,64 +0,0 @@ -_schemaTool->createSchema(array( - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1515Foo'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1515Bar'), - )); - } - - public function testIssue() - { - $bar = new DDC1515Bar(); - $this->_em->persist($bar); - $this->_em->flush(); - - $foo = new DDC1515Foo(); - $foo->bar = $bar; - $this->_em->persist($foo); - $this->_em->flush(); - $this->_em->clear(); - - $bar = $this->_em->find(__NAMESPACE__ . '\DDC1515Bar', $bar->id); - $this->assertInstanceOf(__NAMESPACE__.'\DDC1515Foo', $bar->foo); - } -} - -/** - * @Entity - */ -class DDC1515Foo -{ - /** - * @OneToOne(targetEntity="DDC1515Bar", inversedBy="foo") @Id - */ - public $bar; -} - -/** - * @Entity - */ -class DDC1515Bar -{ - /** - * @Id @Column(type="integer") @GeneratedValue - */ - public $id; - - /** - * @OneToOne(targetEntity="DDC1515Foo", mappedBy="bar") - */ - public $foo; -} - - From f6d2b00d5c85eb916e05fbbbfa3e09d57ee1a003 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 11 Dec 2011 16:42:59 +0100 Subject: [PATCH 44/85] DDC-1400 - var_dump(), seriously? --- tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1400Test.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1400Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1400Test.php index 1639f98bd..2523b5b72 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1400Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1400Test.php @@ -59,12 +59,7 @@ class DDC1400Test extends \Doctrine\Tests\OrmFunctionalTestCase $q->setParameter('activeUser', $user1); $articles = $q->getResult(); - var_dump(array_keys($articles[0]->userStates->toArray())); - $this->_em->flush(); - var_dump($this->_sqlLoggerStack); - - } } From 40d094fea218555429a2c0a7b01216c8f62149c3 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 11 Dec 2011 17:08:58 +0100 Subject: [PATCH 45/85] DDC-1515 - Now the real bugfix --- .../Internal/Hydration/AbstractHydrator.php | 3 + .../ORM/Functional/Ticket/DDC1515Test.php | 64 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1515Test.php diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index 146dfb5c5..6c095c9e3 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -245,6 +245,9 @@ abstract class AbstractHydrator if (isset($cache[$key]['isMetaColumn'])) { if ( ! isset($rowData[$dqlAlias][$cache[$key]['fieldName']]) || $value !== null) { $rowData[$dqlAlias][$cache[$key]['fieldName']] = $value; + if ($cache[$key]['isIdentifier']) { + $nonemptyComponents[$dqlAlias] = true; + } } continue; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1515Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1515Test.php new file mode 100644 index 000000000..9bd3360b8 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1515Test.php @@ -0,0 +1,64 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1515Foo'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1515Bar'), + )); + } + + public function testIssue() + { + $bar = new DDC1515Bar(); + $this->_em->persist($bar); + $this->_em->flush(); + + $foo = new DDC1515Foo(); + $foo->bar = $bar; + $this->_em->persist($foo); + $this->_em->flush(); + $this->_em->clear(); + + $bar = $this->_em->find(__NAMESPACE__ . '\DDC1515Bar', $bar->id); + $this->assertInstanceOf(__NAMESPACE__.'\DDC1515Foo', $bar->foo); + } +} + +/** + * @Entity + */ +class DDC1515Foo +{ + /** + * @OneToOne(targetEntity="DDC1515Bar", inversedBy="foo") @Id + */ + public $bar; +} + +/** + * @Entity + */ +class DDC1515Bar +{ + /** + * @Id @Column(type="integer") @GeneratedValue + */ + public $id; + + /** + * @OneToOne(targetEntity="DDC1515Foo", mappedBy="bar") + */ + public $foo; +} + + From f7175c229ee85e33102066d9740d5c385cd683f7 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 11 Dec 2011 18:39:04 +0100 Subject: [PATCH 46/85] DDC-551 - Fix some ugly yoda conditions and a wrong nesting. --- lib/Doctrine/ORM/Persisters/BasicEntityPersister.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 9ce8acc69..40ccf91d0 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -903,7 +903,7 @@ class BasicEntityPersister $alias = $this->_getSQLTableAlias($this->_class->name); - if ('' !== $filterSql = $this->generateFilterConditionSQL($this->_class, $alias)) { + if ($filterSql = $this->generateFilterConditionSQL($this->_class, $alias)) { if ($conditionSql) { $conditionSql .= ' AND '; } @@ -1025,11 +1025,11 @@ class BasicEntityPersister $this->_selectJoinSql .= ' ' . $this->getJoinSQLForJoinColumns($assoc['joinColumns']); $this->_selectJoinSql .= ' ' . $eagerEntity->getQuotedTableName($this->_platform) . ' ' . $this->_getSQLTableAlias($eagerEntity->name, $assocAlias) .' ON '; + $tableAlias = $this->_getSQLTableAlias($assoc['targetEntity'], $assocAlias); foreach ($assoc['sourceToTargetKeyColumns'] AS $sourceCol => $targetCol) { if ( ! $first) { $this->_selectJoinSql .= ' AND '; } - $tableAlias = $this->_getSQLTableAlias($assoc['targetEntity'], $assocAlias); $this->_selectJoinSql .= $this->_getSQLTableAlias($assoc['sourceEntity']) . '.' . $sourceCol . ' = ' . $tableAlias . '.' . $targetCol; $first = false; From 69b1eb5c6490ecea4ea181cbd6a75ea1fb2771e1 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 11 Dec 2011 18:46:57 +0100 Subject: [PATCH 47/85] DDC-551 - Fix locking mess with filters --- lib/Doctrine/ORM/Persisters/BasicEntityPersister.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 40ccf91d0..4cec1314d 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -1036,7 +1036,7 @@ class BasicEntityPersister } // Add filter SQL - if ('' !== $filterSql = $this->generateFilterConditionSQL($eagerEntity, $tableAlias)) { + if ($filterSql = $this->generateFilterConditionSQL($eagerEntity, $tableAlias)) { $this->_selectJoinSql .= ' AND ' . $filterSql; } } else { @@ -1284,10 +1284,10 @@ class BasicEntityPersister * * @return string */ - protected function getLockTablesSql($alias = null) + protected function getLockTablesSql() { return 'FROM ' . $this->_class->getQuotedTableName($this->_platform) . ' ' - . (null !== $alias ? $alias : $this->_getSQLTableAlias($this->_class->name)); + . $this->_getSQLTableAlias($this->_class->name); } /** @@ -1541,10 +1541,10 @@ class BasicEntityPersister $alias = $this->_getSQLTableAlias($this->_class->name); $sql = 'SELECT 1 ' - . $this->getLockTablesSql($alias) + . $this->getLockTablesSql() . ' WHERE ' . $this->_getSelectConditionSQL($criteria); - if ('' !== $filterSql = $this->generateFilterConditionSQL($this->_class, $alias)) { + if ($filterSql = $this->generateFilterConditionSQL($this->_class, $alias)) { $sql .= ' AND ' . $filterSql; } From ca5dbb182a92466fbda9e524c0452e589a866100 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 11 Dec 2011 19:27:50 +0100 Subject: [PATCH 48/85] DDC-551 - Make filters case-sensitive everywhere --- lib/Doctrine/ORM/Configuration.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index 5f5a58b30..874d3725f 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -504,7 +504,7 @@ class Configuration extends \Doctrine\DBAL\Configuration */ public function addFilter($name, $className) { - $this->_attributes['filters'][strtolower($name)] = $className; + $this->_attributes['filters'][$name] = $className; } /** @@ -517,7 +517,6 @@ class Configuration extends \Doctrine\DBAL\Configuration */ public function getFilterClassName($name) { - $name = strtolower($name); return isset($this->_attributes['filters'][$name]) ? $this->_attributes['filters'][$name] : null; } From ad6130b02d5dd2ae37ee5621ed67e5b84e3199cb Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 11 Dec 2011 19:29:36 +0100 Subject: [PATCH 49/85] DDC-551 - Cleanup filters branch, especially inheritance related code and yoda conditions and some inconsistencies --- .../ORM/Persisters/BasicEntityPersister.php | 3 ++- .../Persisters/JoinedSubclassPersister.php | 23 ++++++------------- .../ORM/Persisters/ManyToManyPersister.php | 18 +++++++++++---- .../ORM/Persisters/OneToManyPersister.php | 4 +--- .../ORM/Persisters/SingleTablePersister.php | 8 +++---- lib/Doctrine/ORM/Query/Filter/SQLFilter.php | 1 - 6 files changed, 26 insertions(+), 31 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 4cec1314d..ea9e8cba4 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -1604,6 +1604,7 @@ class BasicEntityPersister } } - return implode(' AND ', $filterClauses); + $sql = implode(' AND ', $filterClauses); + return $sql ? "(" . $sql . ")" : ""; // Wrap again to avoid "X or Y and FilterConditionSQL" } } diff --git a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php index 02d6ab75c..aca4d14b4 100644 --- a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php @@ -328,13 +328,6 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister if ($first) $first = false; else $joinSql .= ' AND '; $joinSql .= $baseTableAlias . '.' . $idColumn . ' = ' . $tableAlias . '.' . $idColumn; - - if ($parentClass->name === $this->_class->rootEntityName) { - // Add filters on the root class - if ('' !== $filterSql = $this->generateFilterConditionSQL($parentClass, $tableAlias)) { - $joinSql .= ' AND ' . $filterSql; - } - } } } @@ -383,14 +376,12 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister $conditionSql = $this->_getSelectConditionSQL($criteria, $assoc); // If the current class in the root entity, add the filters - if ($this->_class->name === $this->_class->rootEntityName) { - if ('' !== $filterSql = $this->generateFilterConditionSQL($this->_class, $baseTableAlias)) { - if ($conditionSql) { - $conditionSql .= ' AND '; - } - - $conditionSql .= $filterSql; + if ($filterSql = $this->generateFilterConditionSQL($this->_em->getClassMetadata($this->_class->rootEntityName), $this->_getSQLTableAlias($this->_class->rootEntityName))) { + if ($conditionSql) { + $conditionSql .= ' AND '; } + + $conditionSql .= $filterSql; } $orderBy = ($assoc !== null && isset($assoc['orderBy'])) ? $assoc['orderBy'] : $orderBy; @@ -420,10 +411,10 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister * * @return string */ - public function getLockTablesSql($alias = null) + public function getLockTablesSql() { $idColumns = $this->_class->getIdentifierColumnNames(); - $baseTableAlias = null !== $alias ? $alias : $this->_getSQLTableAlias($this->_class->name); + $baseTableAlias = $this->_getSQLTableAlias($this->_class->name); // INNER JOIN parent tables $joinSql = ''; diff --git a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php index bfb6ef08e..99391d9fa 100644 --- a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php @@ -219,7 +219,7 @@ class ManyToManyPersister extends AbstractCollectionPersister } list($joinTargetEntitySQL, $filterSql) = $this->getFilterSql($mapping); - if ('' !== $filterSql) { + if ($filterSql) { $whereClauses[] = $filterSql; } @@ -333,7 +333,7 @@ class ManyToManyPersister extends AbstractCollectionPersister if ($addFilters) { list($joinTargetEntitySQL, $filterSql) = $this->getFilterSql($mapping); - if ('' !== $filterSql) { + if ($filterSql) { $quotedJoinTable .= ' t ' . $joinTargetEntitySQL; $whereClauses[] = $filterSql; } @@ -345,6 +345,12 @@ class ManyToManyPersister extends AbstractCollectionPersister /** * Generates the filter SQL for a given mapping. * + * This method is not used for actually grabbing the related entities + * but when the extra-lazy collection methods are called on a filtered + * association. This is why besides the many to many table we also + * have to join in the actual entities table leading to additional + * JOIN. + * * @param array $targetEntity Array containing mapping information. * * @return string The SQL query part to add to a query. @@ -352,10 +358,11 @@ class ManyToManyPersister extends AbstractCollectionPersister public function getFilterSql($mapping) { $targetClass = $this->_em->getClassMetadata($mapping['targetEntity']); + $targetClass = $this->_em->getClassMetadata($targetClass->rootEntityName); // A join is needed if there is filtering on the target entity $joinTargetEntitySQL = ''; - if ('' !== $filterSql = $this->generateFilterConditionSQL($targetClass, 'te')) { + if ($filterSql = $this->generateFilterConditionSQL($targetClass, 'te')) { $joinTargetEntitySQL = ' JOIN ' . $targetClass->getQuotedTableName($this->_conn->getDatabasePlatform()) . ' te' . ' ON'; @@ -384,11 +391,12 @@ class ManyToManyPersister extends AbstractCollectionPersister $filterClauses = array(); foreach ($this->_em->getFilters()->getEnabledFilters() as $filter) { - if ('' !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { + if ($filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { $filterClauses[] = '(' . $filterExpr . ')'; } } - return implode(' AND ', $filterClauses); + $sql = implode(' AND ', $filterClauses); + return $sql ? "(" . $sql . ")" : ""; } } diff --git a/lib/Doctrine/ORM/Persisters/OneToManyPersister.php b/lib/Doctrine/ORM/Persisters/OneToManyPersister.php index 2fe1d5acb..b78d0e561 100644 --- a/lib/Doctrine/ORM/Persisters/OneToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/OneToManyPersister.php @@ -1,7 +1,5 @@ _em->getFilters()->getEnabledFilters() as $filter) { - if ('' !== $filterExpr = $filter->addFilterConstraint($targetClass, 't')) { + if ($filterExpr = $filter->addFilterConstraint($targetClass, 't')) { $whereClauses[] = '(' . $filterExpr . ')'; } } diff --git a/lib/Doctrine/ORM/Persisters/SingleTablePersister.php b/lib/Doctrine/ORM/Persisters/SingleTablePersister.php index 39a6b4954..c2687c109 100644 --- a/lib/Doctrine/ORM/Persisters/SingleTablePersister.php +++ b/lib/Doctrine/ORM/Persisters/SingleTablePersister.php @@ -137,11 +137,9 @@ class SingleTablePersister extends AbstractEntityInheritancePersister protected function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias) { // Ensure that the filters are applied to the root entity of the inheritance tree - $realTargetEntity = $targetEntity; - if ($targetEntity->name !== $targetEntity->rootEntityName) { - $realTargetEntity = $this->_em->getClassMetadata($targetEntity->rootEntityName); - } + $targetEntity = $this->_em->getClassMetadata($targetEntity->rootEntityName); + // we dont care about the $targetTableAlias, in a STI there is only one table. - return parent::generateFilterConditionSQL($realTargetEntity, $targetTableAlias); + return parent::generateFilterConditionSQL($targetEntity, $targetTableAlias); } } diff --git a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php index 772ef683b..1250b16d7 100644 --- a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php +++ b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php @@ -66,7 +66,6 @@ abstract class SQLFilter */ final public function setParameter($name, $value, $type) { - // @todo: check for a valid type? $this->parameters[$name] = array('value' => $value, 'type' => $type); // Keep the parameters sorted for the hash From b6d776f75de2820a40ad2dd0150ce0c08d75a2c2 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 11 Dec 2011 21:14:09 +0100 Subject: [PATCH 50/85] DDC-551 - rework walker filtering --- lib/Doctrine/ORM/Query/SqlWalker.php | 43 +++++++++++++--------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 69bf903be..8b6a61827 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -269,7 +269,7 @@ class SqlWalker implements TreeWalker } // Add filters on the root class - if ('' !== $filterSql = $this->generateFilterConditionSQL($parentClass, $tableAlias)) { + if ($filterSql = $this->generateFilterConditionSQL($parentClass, $tableAlias)) { $sqlParts[] = $filterSql; } @@ -853,10 +853,6 @@ class SqlWalker implements TreeWalker } } - // Apply the filters - if ('' !== $filterExpr = $this->generateFilterConditionSQL($targetClass, $targetTableAlias)) { - $sql .= ' AND ' . $filterExpr; - } } else if ($assoc['type'] == ClassMetadata::MANY_TO_MANY) { // Join relation table $joinTable = $assoc['joinTable']; @@ -920,11 +916,11 @@ class SqlWalker implements TreeWalker $sql .= $targetTableAlias . '.' . $quotedTargetColumn . ' = ' . $joinTableAlias . '.' . $relationColumn; } } + } - // Apply the filters - if ('' !== $filterExpr = $this->generateFilterConditionSQL($targetClass, $targetTableAlias)) { - $sql .= ' AND ' . $filterExpr; - } + // Apply the filters + if ($filterExpr = $this->generateFilterConditionSQL($targetClass, $targetTableAlias)) { + $sql .= ' AND ' . $filterExpr; } // Handle WITH clause @@ -1527,23 +1523,24 @@ class SqlWalker implements TreeWalker $condSql = null !== $whereClause ? $this->walkConditionalExpression($whereClause->conditionalExpression) : ''; $discrSql = $this->_generateDiscriminatorColumnConditionSql($this->_rootAliases); - // Apply the filters for all entities in FROM - $filterClauses = array(); - foreach ($this->_rootAliases as $dqlAlias) { - $class = $this->_queryComponents[$dqlAlias]['metadata']; - $tableAlias = $this->getSQLTableAlias($class->table['name'], $dqlAlias); + if ($this->_em->hasFilters()) { + $filterClauses = array(); + foreach ($this->_rootAliases as $dqlAlias) { + $class = $this->_queryComponents[$dqlAlias]['metadata']; + $tableAlias = $this->getSQLTableAlias($class->table['name'], $dqlAlias); - if ('' !== $filterExpr = $this->generateFilterConditionSQL($class, $tableAlias)) { - $filterClauses[] = $filterExpr; - } - } - - if (count($filterClauses)) { - if ($condSql) { - $condSql .= ' AND '; + if ($filterExpr = $this->generateFilterConditionSQL($class, $tableAlias)) { + $filterClauses[] = $filterExpr; + } } - $condSql .= implode(' AND ', $filterClauses); + if (count($filterClauses)) { + if ($condSql) { + $condSql .= ' AND '; + } + + $condSql .= implode(' AND ', $filterClauses); + } } if ($condSql) { From 2fdb55a87801191e6931b7f9edf7a1ec7a09c46c Mon Sep 17 00:00:00 2001 From: Andrew Mackrodt Date: Sun, 11 Dec 2011 20:52:29 +0000 Subject: [PATCH 51/85] Added absolute namespace paths to phpdoc annotations - issue DDC-1025. --- lib/Doctrine/ORM/AbstractQuery.php | 32 ++++++------- lib/Doctrine/ORM/EntityManager.php | 46 +++++++++---------- lib/Doctrine/ORM/EntityRepository.php | 2 +- lib/Doctrine/ORM/Id/AbstractIdGenerator.php | 2 +- lib/Doctrine/ORM/Id/SequenceGenerator.php | 2 +- .../Internal/Hydration/AbstractHydrator.php | 2 +- .../ORM/Internal/Hydration/IterableResult.php | 4 +- .../ORM/Mapping/ClassMetadataFactory.php | 18 ++++---- .../ORM/Mapping/ClassMetadataInfo.php | 4 +- lib/Doctrine/ORM/PersistentCollection.php | 4 +- .../AbstractCollectionPersister.php | 6 +-- .../ORM/Persisters/BasicEntityPersister.php | 22 ++++----- .../Persisters/JoinedSubclassPersister.php | 2 +- lib/Doctrine/ORM/Query.php | 22 ++++----- .../ORM/Query/Exec/AbstractSqlExecutor.php | 4 +- .../ORM/Query/ParameterTypeInferer.php | 4 +- lib/Doctrine/ORM/Query/Parser.php | 22 ++++----- lib/Doctrine/ORM/Query/QueryException.php | 2 +- lib/Doctrine/ORM/Query/SqlWalker.php | 2 +- lib/Doctrine/ORM/Query/TreeWalkerAdapter.php | 4 +- .../ORM/Tools/Console/Command/InfoCommand.php | 2 +- .../Tools/Export/Driver/AbstractExporter.php | 2 +- lib/Doctrine/ORM/Tools/SchemaTool.php | 4 +- lib/Doctrine/ORM/UnitOfWork.php | 16 +++---- 24 files changed, 115 insertions(+), 115 deletions(-) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index 9a812f446..7010136c8 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -77,7 +77,7 @@ abstract class AbstractQuery protected $_resultSetMapping; /** - * @var Doctrine\ORM\EntityManager The entity manager used by this query object. + * @var \Doctrine\ORM\EntityManager The entity manager used by this query object. */ protected $_em; @@ -104,7 +104,7 @@ abstract class AbstractQuery /** * Initializes a new instance of a class derived from AbstractQuery. * - * @param Doctrine\ORM\EntityManager $entityManager + * @param \Doctrine\ORM\EntityManager $entityManager */ public function __construct(EntityManager $em) { @@ -114,7 +114,7 @@ abstract class AbstractQuery /** * Retrieves the associated EntityManager of this Query instance. * - * @return Doctrine\ORM\EntityManager + * @return \Doctrine\ORM\EntityManager */ public function getEntityManager() { @@ -202,7 +202,7 @@ abstract class AbstractQuery * @param string $type The parameter type. If specified, the given value will be run through * the type conversion of this type. This is usually not needed for * strings and numeric types. - * @return Doctrine\ORM\AbstractQuery This query instance. + * @return \Doctrine\ORM\AbstractQuery This query instance. */ public function setParameter($key, $value, $type = null) { @@ -223,7 +223,7 @@ abstract class AbstractQuery * * @param array $params * @param array $types - * @return Doctrine\ORM\AbstractQuery This query instance. + * @return \Doctrine\ORM\AbstractQuery This query instance. */ public function setParameters(array $params, array $types = array()) { @@ -238,7 +238,7 @@ abstract class AbstractQuery * Sets the ResultSetMapping that should be used for hydration. * * @param ResultSetMapping $rsm - * @return Doctrine\ORM\AbstractQuery + * @return \Doctrine\ORM\AbstractQuery */ public function setResultSetMapping(Query\ResultSetMapping $rsm) { @@ -250,8 +250,8 @@ abstract class AbstractQuery /** * Defines a cache driver to be used for caching result sets and implictly enables caching. * - * @param Doctrine\Common\Cache\Cache $driver Cache driver - * @return Doctrine\ORM\AbstractQuery + * @param \Doctrine\Common\Cache\Cache $driver Cache driver + * @return \Doctrine\ORM\AbstractQuery */ public function setResultCacheDriver($resultCacheDriver = null) { @@ -270,7 +270,7 @@ abstract class AbstractQuery * Returns the cache driver used for caching result sets. * * @deprecated - * @return Doctrine\Common\Cache\Cache Cache driver + * @return \Doctrine\Common\Cache\Cache Cache driver */ public function getResultCacheDriver() { @@ -288,7 +288,7 @@ abstract class AbstractQuery * @param boolean $bool * @param integer $lifetime * @param string $resultCacheId - * @return Doctrine\ORM\AbstractQuery This query instance. + * @return \Doctrine\ORM\AbstractQuery This query instance. */ public function useResultCache($bool, $lifetime = null, $resultCacheId = null) { @@ -308,7 +308,7 @@ abstract class AbstractQuery * Defines how long the result cache will be active before expire. * * @param integer $lifetime How long the cache entry is valid. - * @return Doctrine\ORM\AbstractQuery This query instance. + * @return \Doctrine\ORM\AbstractQuery This query instance. */ public function setResultCacheLifetime($lifetime) { @@ -336,7 +336,7 @@ abstract class AbstractQuery * Defines if the result cache is active or not. * * @param boolean $expire Whether or not to force resultset cache expiration. - * @return Doctrine\ORM\AbstractQuery This query instance. + * @return \Doctrine\ORM\AbstractQuery This query instance. */ public function expireResultCache($expire = true) { @@ -389,7 +389,7 @@ abstract class AbstractQuery * * @param integer $hydrationMode Doctrine processing mode to be used during hydration process. * One of the Query::HYDRATE_* constants. - * @return Doctrine\ORM\AbstractQuery This query instance. + * @return \Doctrine\ORM\AbstractQuery This query instance. */ public function setHydrationMode($hydrationMode) { @@ -520,7 +520,7 @@ abstract class AbstractQuery * * @param string $name The name of the hint. * @param mixed $value The value of the hint. - * @return Doctrine\ORM\AbstractQuery + * @return \Doctrine\ORM\AbstractQuery */ public function setHint($name, $value) { @@ -609,7 +609,7 @@ abstract class AbstractQuery * generated for you. * * @param string $id - * @return Doctrine\ORM\AbstractQuery This query instance. + * @return \Doctrine\ORM\AbstractQuery This query instance. */ public function setResultCacheId($id) { @@ -634,7 +634,7 @@ abstract class AbstractQuery /** * Executes the query and returns a the resulting Statement object. * - * @return Doctrine\DBAL\Driver\Statement The executed database statement that holds the results. + * @return \Doctrine\DBAL\Driver\Statement The executed database statement that holds the results. */ abstract protected function _doExecute(); diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 9033c178c..cec076d8d 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -43,21 +43,21 @@ class EntityManager implements ObjectManager /** * The used Configuration. * - * @var Doctrine\ORM\Configuration + * @var \Doctrine\ORM\Configuration */ private $config; /** * The database connection used by the EntityManager. * - * @var Doctrine\DBAL\Connection + * @var \Doctrine\DBAL\Connection */ private $conn; /** * The metadata factory, used to retrieve the ORM metadata of entity classes. * - * @var Doctrine\ORM\Mapping\ClassMetadataFactory + * @var \Doctrine\ORM\Mapping\ClassMetadataFactory */ private $metadataFactory; @@ -71,14 +71,14 @@ class EntityManager implements ObjectManager /** * The UnitOfWork used to coordinate object-level transactions. * - * @var Doctrine\ORM\UnitOfWork + * @var \Doctrine\ORM\UnitOfWork */ private $unitOfWork; /** * The event manager that is the central point of the event system. * - * @var Doctrine\Common\EventManager + * @var \Doctrine\Common\EventManager */ private $eventManager; @@ -92,14 +92,14 @@ class EntityManager implements ObjectManager /** * The proxy factory used to create dynamic proxies. * - * @var Doctrine\ORM\Proxy\ProxyFactory + * @var \Doctrine\ORM\Proxy\ProxyFactory */ private $proxyFactory; /** * The expression builder instance used to generate query expressions. * - * @var Doctrine\ORM\Query\Expr + * @var \Doctrine\ORM\Query\Expr */ private $expressionBuilder; @@ -114,9 +114,9 @@ class EntityManager implements ObjectManager * Creates a new EntityManager that operates on the given database connection * and uses the given Configuration and EventManager implementations. * - * @param Doctrine\DBAL\Connection $conn - * @param Doctrine\ORM\Configuration $config - * @param Doctrine\Common\EventManager $eventManager + * @param \Doctrine\DBAL\Connection $conn + * @param \Doctrine\ORM\Configuration $config + * @param \Doctrine\Common\EventManager $eventManager */ protected function __construct(Connection $conn, Configuration $config, EventManager $eventManager) { @@ -141,7 +141,7 @@ class EntityManager implements ObjectManager /** * Gets the database connection object used by the EntityManager. * - * @return Doctrine\DBAL\Connection + * @return \Doctrine\DBAL\Connection */ public function getConnection() { @@ -151,7 +151,7 @@ class EntityManager implements ObjectManager /** * Gets the metadata factory used to gather the metadata of classes. * - * @return Doctrine\ORM\Mapping\ClassMetadataFactory + * @return \Doctrine\ORM\Mapping\ClassMetadataFactory */ public function getMetadataFactory() { @@ -170,7 +170,7 @@ class EntityManager implements ObjectManager * ->where($expr->orX($expr->eq('u.id', 1), $expr->eq('u.id', 2))); * * - * @return Doctrine\ORM\Query\Expr + * @return \Doctrine\ORM\Query\Expr */ public function getExpressionBuilder() { @@ -253,7 +253,7 @@ class EntityManager implements ObjectManager * MyProject\Domain\User * sales:PriceRequest * - * @return Doctrine\ORM\Mapping\ClassMetadata + * @return \Doctrine\ORM\Mapping\ClassMetadata * @internal Performance-sensitive method. */ public function getClassMetadata($className) @@ -265,7 +265,7 @@ class EntityManager implements ObjectManager * Creates a new Query object. * * @param string The DQL string. - * @return Doctrine\ORM\Query + * @return \Doctrine\ORM\Query */ public function createQuery($dql = "") { @@ -282,7 +282,7 @@ class EntityManager implements ObjectManager * Creates a Query from a named query. * * @param string $name - * @return Doctrine\ORM\Query + * @return \Doctrine\ORM\Query */ public function createNamedQuery($name) { @@ -309,7 +309,7 @@ class EntityManager implements ObjectManager * Creates a NativeQuery from a named native query. * * @param string $name - * @return Doctrine\ORM\NativeQuery + * @return \Doctrine\ORM\NativeQuery */ public function createNamedNativeQuery($name) { @@ -337,7 +337,7 @@ class EntityManager implements ObjectManager * the cascade-persist semantics + scheduled inserts/removals are synchronized. * * @param object $entity - * @throws Doctrine\ORM\OptimisticLockException If a version check on an entity that + * @throws \Doctrine\ORM\OptimisticLockException If a version check on an entity that * makes use of optimistic locking fails. */ public function flush($entity = null) @@ -632,7 +632,7 @@ class EntityManager implements ObjectManager /** * Gets the EventManager used by the EntityManager. * - * @return Doctrine\Common\EventManager + * @return \Doctrine\Common\EventManager */ public function getEventManager() { @@ -642,7 +642,7 @@ class EntityManager implements ObjectManager /** * Gets the Configuration used by the EntityManager. * - * @return Doctrine\ORM\Configuration + * @return \Doctrine\ORM\Configuration */ public function getConfiguration() { @@ -674,7 +674,7 @@ class EntityManager implements ObjectManager /** * Gets the UnitOfWork used by the EntityManager to coordinate operations. * - * @return Doctrine\ORM\UnitOfWork + * @return \Doctrine\ORM\UnitOfWork */ public function getUnitOfWork() { @@ -688,7 +688,7 @@ class EntityManager implements ObjectManager * selectively iterate over the result. * * @param int $hydrationMode - * @return Doctrine\ORM\Internal\Hydration\AbstractHydrator + * @return \Doctrine\ORM\Internal\Hydration\AbstractHydrator */ public function getHydrator($hydrationMode) { @@ -703,7 +703,7 @@ class EntityManager implements ObjectManager * Create a new instance for the given hydration mode. * * @param int $hydrationMode - * @return Doctrine\ORM\Internal\Hydration\AbstractHydrator + * @return \Doctrine\ORM\Internal\Hydration\AbstractHydrator */ public function newHydrator($hydrationMode) { diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index 3261d7e61..1b0619efe 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -48,7 +48,7 @@ class EntityRepository implements ObjectRepository protected $_em; /** - * @var Doctrine\ORM\Mapping\ClassMetadata + * @var \Doctrine\ORM\Mapping\ClassMetadata */ protected $_class; diff --git a/lib/Doctrine/ORM/Id/AbstractIdGenerator.php b/lib/Doctrine/ORM/Id/AbstractIdGenerator.php index cfe3b5daf..677238289 100644 --- a/lib/Doctrine/ORM/Id/AbstractIdGenerator.php +++ b/lib/Doctrine/ORM/Id/AbstractIdGenerator.php @@ -26,7 +26,7 @@ abstract class AbstractIdGenerator /** * Generates an identifier for an entity. * - * @param Doctrine\ORM\Entity $entity + * @param \Doctrine\ORM\Entity $entity * @return mixed */ abstract public function generate(EntityManager $em, $entity); diff --git a/lib/Doctrine/ORM/Id/SequenceGenerator.php b/lib/Doctrine/ORM/Id/SequenceGenerator.php index b02331e6b..79240610e 100644 --- a/lib/Doctrine/ORM/Id/SequenceGenerator.php +++ b/lib/Doctrine/ORM/Id/SequenceGenerator.php @@ -37,7 +37,7 @@ class SequenceGenerator extends AbstractIdGenerator implements Serializable /** * Initializes a new sequence generator. * - * @param Doctrine\ORM\EntityManager $em The EntityManager to use. + * @param \Doctrine\ORM\EntityManager $em The EntityManager to use. * @param string $sequenceName The name of the sequence. * @param integer $allocationSize The allocation size of the sequence. */ diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index 6c095c9e3..fdb52953c 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -60,7 +60,7 @@ abstract class AbstractHydrator /** * Initializes a new instance of a class derived from AbstractHydrator. * - * @param Doctrine\ORM\EntityManager $em The EntityManager to use. + * @param \Doctrine\ORM\EntityManager $em The EntityManager to use. */ public function __construct(EntityManager $em) { diff --git a/lib/Doctrine/ORM/Internal/Hydration/IterableResult.php b/lib/Doctrine/ORM/Internal/Hydration/IterableResult.php index 530873bcc..6243886b0 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/IterableResult.php +++ b/lib/Doctrine/ORM/Internal/Hydration/IterableResult.php @@ -29,7 +29,7 @@ namespace Doctrine\ORM\Internal\Hydration; class IterableResult implements \Iterator { /** - * @var Doctrine\ORM\Internal\Hydration\AbstractHydrator + * @var \Doctrine\ORM\Internal\Hydration\AbstractHydrator */ private $_hydrator; @@ -49,7 +49,7 @@ class IterableResult implements \Iterator private $_current = null; /** - * @param Doctrine\ORM\Internal\Hydration\AbstractHydrator $hydrator + * @param \Doctrine\ORM\Internal\Hydration\AbstractHydrator $hydrator */ public function __construct($hydrator) { diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 9bc3ca054..9fdd1eb06 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -85,7 +85,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface /** * Sets the cache driver used by the factory to cache ClassMetadata instances. * - * @param Doctrine\Common\Cache\Cache $cacheDriver + * @param \Doctrine\Common\Cache\Cache $cacheDriver */ public function setCacheDriver($cacheDriver) { @@ -95,7 +95,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface /** * Gets the cache driver used by the factory to cache ClassMetadata instances. * - * @return Doctrine\Common\Cache\Cache + * @return \Doctrine\Common\Cache\Cache */ public function getCacheDriver() { @@ -143,7 +143,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface * Gets the class metadata descriptor for a class. * * @param string $className The name of the class. - * @return Doctrine\ORM\Mapping\ClassMetadata + * @return \Doctrine\ORM\Mapping\ClassMetadata */ public function getMetadataFor($className) { @@ -377,7 +377,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface * Creates a new ClassMetadata instance for the given class name. * * @param string $className - * @return Doctrine\ORM\Mapping\ClassMetadata + * @return \Doctrine\ORM\Mapping\ClassMetadata */ protected function newClassMetadataInstance($className) { @@ -387,8 +387,8 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface /** * Adds inherited fields to the subclass mapping. * - * @param Doctrine\ORM\Mapping\ClassMetadata $subClass - * @param Doctrine\ORM\Mapping\ClassMetadata $parentClass + * @param \Doctrine\ORM\Mapping\ClassMetadata $subClass + * @param \Doctrine\ORM\Mapping\ClassMetadata $parentClass */ private function addInheritedFields(ClassMetadata $subClass, ClassMetadata $parentClass) { @@ -409,8 +409,8 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface /** * Adds inherited association mappings to the subclass mapping. * - * @param Doctrine\ORM\Mapping\ClassMetadata $subClass - * @param Doctrine\ORM\Mapping\ClassMetadata $parentClass + * @param \Doctrine\ORM\Mapping\ClassMetadata $subClass + * @param \Doctrine\ORM\Mapping\ClassMetadata $parentClass */ private function addInheritedRelations(ClassMetadata $subClass, ClassMetadata $parentClass) { @@ -456,7 +456,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface * Completes the ID generator mapping. If "auto" is specified we choose the generator * most appropriate for the targeted database platform. * - * @param Doctrine\ORM\Mapping\ClassMetadata $class + * @param \Doctrine\ORM\Mapping\ClassMetadata $class */ private function completeIdGeneratorMapping(ClassMetadataInfo $class) { diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 1f54a095b..d845e6f59 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -1250,7 +1250,7 @@ class ClassMetadataInfo implements ClassMetadata * Gets the type of a field. * * @param string $fieldName - * @return Doctrine\DBAL\Types\Type + * @return \Doctrine\DBAL\Types\Type */ public function getTypeOfField($fieldName) { @@ -1261,7 +1261,7 @@ class ClassMetadataInfo implements ClassMetadata /** * Gets the type of a column. * - * @return Doctrine\DBAL\Types\Type + * @return \Doctrine\DBAL\Types\Type */ public function getTypeOfColumn($columnName) { diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index d8a53f2f1..bca07fdf0 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -67,7 +67,7 @@ final class PersistentCollection implements Collection /** * The EntityManager that manages the persistence of the collection. * - * @var Doctrine\ORM\EntityManager + * @var \Doctrine\ORM\EntityManager */ private $em; @@ -284,7 +284,7 @@ final class PersistentCollection implements Collection /** * INTERNAL: Gets the association mapping of the collection. * - * @return Doctrine\ORM\Mapping\AssociationMapping + * @return \Doctrine\ORM\Mapping\AssociationMapping */ public function getMapping() { diff --git a/lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php b/lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php index a4fc4b92d..3ee81f0d4 100644 --- a/lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php +++ b/lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php @@ -36,19 +36,19 @@ abstract class AbstractCollectionPersister protected $_em; /** - * @var Doctrine\DBAL\Connection + * @var \Doctrine\DBAL\Connection */ protected $_conn; /** - * @var Doctrine\ORM\UnitOfWork + * @var \Doctrine\ORM\UnitOfWork */ protected $_uow; /** * Initializes a new instance of a class derived from AbstractCollectionPersister. * - * @param Doctrine\ORM\EntityManager $em + * @param \Doctrine\ORM\EntityManager $em */ public function __construct(EntityManager $em) { diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 92ce37ac6..e94e91575 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -79,28 +79,28 @@ class BasicEntityPersister /** * Metadata object that describes the mapping of the mapped entity class. * - * @var Doctrine\ORM\Mapping\ClassMetadata + * @var \Doctrine\ORM\Mapping\ClassMetadata */ protected $_class; /** * The underlying DBAL Connection of the used EntityManager. * - * @var Doctrine\DBAL\Connection $conn + * @var \Doctrine\DBAL\Connection $conn */ protected $_conn; /** * The database platform. * - * @var Doctrine\DBAL\Platforms\AbstractPlatform + * @var \Doctrine\DBAL\Platforms\AbstractPlatform */ protected $_platform; /** * The EntityManager instance. * - * @var Doctrine\ORM\EntityManager + * @var \Doctrine\ORM\EntityManager */ protected $_em; @@ -172,8 +172,8 @@ class BasicEntityPersister * Initializes a new BasicEntityPersister that uses the given EntityManager * and persists instances of the class described by the given ClassMetadata descriptor. * - * @param Doctrine\ORM\EntityManager $em - * @param Doctrine\ORM\Mapping\ClassMetadata $class + * @param \Doctrine\ORM\EntityManager $em + * @param \Doctrine\ORM\Mapping\ClassMetadata $class */ public function __construct(EntityManager $em, ClassMetadata $class) { @@ -184,7 +184,7 @@ class BasicEntityPersister } /** - * @return Doctrine\ORM\Mapping\ClassMetadata + * @return \Doctrine\ORM\Mapping\ClassMetadata */ public function getClassMetadata() { @@ -272,7 +272,7 @@ class BasicEntityPersister /** * Fetch the current version value of a versioned entity. * - * @param Doctrine\ORM\Mapping\ClassMetadata $versionedClass + * @param \Doctrine\ORM\Mapping\ClassMetadata $versionedClass * @param mixed $id * @return mixed */ @@ -750,7 +750,7 @@ class BasicEntityPersister * Load an array of entities from a given dbal statement. * * @param array $assoc - * @param Doctrine\DBAL\Statement $stmt + * @param \Doctrine\DBAL\Statement $stmt * * @return array */ @@ -774,7 +774,7 @@ class BasicEntityPersister * Hydrate a collection from a given dbal statement. * * @param array $assoc - * @param Doctrine\DBAL\Statement $stmt + * @param \Doctrine\DBAL\Statement $stmt * @param PersistentCollection $coll * * @return array @@ -1368,7 +1368,7 @@ class BasicEntityPersister * @param object $sourceEntity * @param int|null $offset * @param int|null $limit - * @return Doctrine\DBAL\Statement + * @return \Doctrine\DBAL\Statement */ private function getOneToManyStatement(array $assoc, $sourceEntity, $offset = null, $limit = null) { diff --git a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php index fb60d5e32..795ab4c3e 100644 --- a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php @@ -67,7 +67,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister * This function finds the ClassMetadata instance in an inheritance hierarchy * that is responsible for enabling versioning. * - * @return Doctrine\ORM\Mapping\ClassMetadata + * @return \Doctrine\ORM\Mapping\ClassMetadata */ private function _getVersionedClassMetadata() { diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index 0aa22df41..d6f05e15b 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -81,7 +81,7 @@ final class Query extends AbstractQuery const HINT_INCLUDE_META_COLUMNS = 'doctrine.includeMetaColumns'; /** - * An array of class names that implement Doctrine\ORM\Query\TreeWalker and + * An array of class names that implement \Doctrine\ORM\Query\TreeWalker and * are iterated and executed after the DQL has been parsed into an AST. * * @var string @@ -89,7 +89,7 @@ final class Query extends AbstractQuery const HINT_CUSTOM_TREE_WALKERS = 'doctrine.customTreeWalkers'; /** - * A string with a class name that implements Doctrine\ORM\Query\TreeWalker + * A string with a class name that implements \Doctrine\ORM\Query\TreeWalker * and is used for generating the target SQL from any DQL AST tree. * * @var string @@ -119,7 +119,7 @@ final class Query extends AbstractQuery private $_dql = null; /** - * @var Doctrine\ORM\Query\ParserResult The parser result that holds DQL => SQL information. + * @var \Doctrine\ORM\Query\ParserResult The parser result that holds DQL => SQL information. */ private $_parserResult; @@ -158,7 +158,7 @@ final class Query extends AbstractQuery /** * Initializes a new Query instance. * - * @param Doctrine\ORM\EntityManager $entityManager + * @param \Doctrine\ORM\EntityManager $entityManager */ /*public function __construct(EntityManager $entityManager) { @@ -179,9 +179,9 @@ final class Query extends AbstractQuery /** * Returns the corresponding AST for this DQL query. * - * @return Doctrine\ORM\Query\AST\SelectStatement | - * Doctrine\ORM\Query\AST\UpdateStatement | - * Doctrine\ORM\Query\AST\DeleteStatement + * @return \Doctrine\ORM\Query\AST\SelectStatement | + * \Doctrine\ORM\Query\AST\UpdateStatement | + * \Doctrine\ORM\Query\AST\DeleteStatement */ public function getAST() { @@ -194,7 +194,7 @@ final class Query extends AbstractQuery * * Note: Populates $this->_parserResult as a side-effect. * - * @return Doctrine\ORM\Query\ParserResult + * @return \Doctrine\ORM\Query\ParserResult */ private function _parse() { @@ -441,7 +441,7 @@ final class Query extends AbstractQuery * Sets a DQL query string. * * @param string $dqlQuery DQL Query - * @return Doctrine\ORM\AbstractQuery + * @return \Doctrine\ORM\AbstractQuery */ public function setDQL($dqlQuery) { @@ -577,7 +577,7 @@ final class Query extends AbstractQuery /** * Set the lock mode for this Query. * - * @see Doctrine\DBAL\LockMode + * @see \Doctrine\DBAL\LockMode * @param int $lockMode * @return Query */ @@ -639,4 +639,4 @@ final class Query extends AbstractQuery $this->_state = self::STATE_DIRTY; } -} \ No newline at end of file +} diff --git a/lib/Doctrine/ORM/Query/Exec/AbstractSqlExecutor.php b/lib/Doctrine/ORM/Query/Exec/AbstractSqlExecutor.php index f44e383b9..d63922348 100644 --- a/lib/Doctrine/ORM/Query/Exec/AbstractSqlExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/AbstractSqlExecutor.php @@ -61,10 +61,10 @@ abstract class AbstractSqlExecutor /** * Executes all sql statements. * - * @param Doctrine\DBAL\Connection $conn The database connection that is used to execute the queries. + * @param \Doctrine\DBAL\Connection $conn The database connection that is used to execute the queries. * @param array $params The parameters. * @param array $types The parameter types. - * @return Doctrine\DBAL\Driver\Statement + * @return \Doctrine\DBAL\Driver\Statement */ abstract public function execute(Connection $conn, array $params, array $types); } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Query/ParameterTypeInferer.php b/lib/Doctrine/ORM/Query/ParameterTypeInferer.php index d0e3e24b5..8664f8670 100644 --- a/lib/Doctrine/ORM/Query/ParameterTypeInferer.php +++ b/lib/Doctrine/ORM/Query/ParameterTypeInferer.php @@ -37,8 +37,8 @@ class ParameterTypeInferer { /** * Infer type of a given value, returning a compatible constant: - * - Type (Doctrine\DBAL\Types\Type::*) - * - Connection (Doctrine\DBAL\Connection::PARAM_*) + * - Type (\Doctrine\DBAL\Types\Type::*) + * - Connection (\Doctrine\DBAL\Connection::PARAM_*) * * @param mixed $value Parameter value * diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 6c8f515f6..e46f85b6c 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -76,14 +76,14 @@ class Parser /** * The lexer. * - * @var Doctrine\ORM\Query\Lexer + * @var \Doctrine\ORM\Query\Lexer */ private $_lexer; /** * The parser result. * - * @var Doctrine\ORM\Query\ParserResult + * @var \Doctrine\ORM\Query\ParserResult */ private $_parserResult; @@ -171,7 +171,7 @@ class Parser /** * Gets the lexer used by the parser. * - * @return Doctrine\ORM\Query\Lexer + * @return \Doctrine\ORM\Query\Lexer */ public function getLexer() { @@ -181,7 +181,7 @@ class Parser /** * Gets the ParserResult that is being filled with information during parsing. * - * @return Doctrine\ORM\Query\ParserResult + * @return \Doctrine\ORM\Query\ParserResult */ public function getParserResult() { @@ -1457,7 +1457,7 @@ class Parser /** * RangeVariableDeclaration ::= AbstractSchemaName ["AS"] AliasIdentificationVariable * - * @return Doctrine\ORM\Query\AST\RangeVariableDeclaration + * @return \Doctrine\ORM\Query\AST\RangeVariableDeclaration */ public function RangeVariableDeclaration() { @@ -1531,7 +1531,7 @@ class Parser * Join ::= ["LEFT" ["OUTER"] | "INNER"] "JOIN" JoinAssociationPathExpression * ["AS"] AliasIdentificationVariable ["WITH" ConditionalExpression] * - * @return Doctrine\ORM\Query\AST\Join + * @return \Doctrine\ORM\Query\AST\Join */ public function Join() { @@ -1611,7 +1611,7 @@ class Parser /** * IndexBy ::= "INDEX" "BY" StateFieldPathExpression * - * @return Doctrine\ORM\Query\AST\IndexBy + * @return \Doctrine\ORM\Query\AST\IndexBy */ public function IndexBy() { @@ -1737,7 +1737,7 @@ class Parser /** * CoalesceExpression ::= "COALESCE" "(" ScalarExpression {"," ScalarExpression}* ")" * - * @return Doctrine\ORM\Query\AST\CoalesceExpression + * @return \Doctrine\ORM\Query\AST\CoalesceExpression */ public function CoalesceExpression() { @@ -1762,7 +1762,7 @@ class Parser /** * NullIfExpression ::= "NULLIF" "(" ScalarExpression "," ScalarExpression ")" * - * @return Doctrine\ORM\Query\AST\NullIfExpression + * @return \Doctrine\ORM\Query\AST\NullIfExpression */ public function NullIfExpression() { @@ -1858,7 +1858,7 @@ class Parser * PartialObjectExpression | "(" Subselect ")" | CaseExpression * ) [["AS"] ["HIDDEN"] AliasResultVariable] * - * @return Doctrine\ORM\Query\AST\SelectExpression + * @return \Doctrine\ORM\Query\AST\SelectExpression */ public function SelectExpression() { @@ -2133,7 +2133,7 @@ class Parser /** * ConditionalPrimary ::= SimpleConditionalExpression | "(" ConditionalExpression ")" * - * @return Doctrine\ORM\Query\AST\ConditionalPrimary + * @return \Doctrine\ORM\Query\AST\ConditionalPrimary */ public function ConditionalPrimary() { diff --git a/lib/Doctrine/ORM/Query/QueryException.php b/lib/Doctrine/ORM/Query/QueryException.php index f581ecc56..cd74f3567 100644 --- a/lib/Doctrine/ORM/Query/QueryException.php +++ b/lib/Doctrine/ORM/Query/QueryException.php @@ -94,7 +94,7 @@ class QueryException extends \Doctrine\ORM\ORMException } /** - * @param Doctrine\ORM\Mapping\AssociationMapping $assoc + * @param \Doctrine\ORM\Mapping\AssociationMapping $assoc */ public static function iterateWithFetchJoinCollectionNotAllowed($assoc) { diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 6d0f926ad..1e01e0f8b 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -60,7 +60,7 @@ class SqlWalker implements TreeWalker private $_em; /** - * @var Doctrine\DBAL\Connection + * @var \Doctrine\DBAL\Connection */ private $_conn; diff --git a/lib/Doctrine/ORM/Query/TreeWalkerAdapter.php b/lib/Doctrine/ORM/Query/TreeWalkerAdapter.php index 530b98c50..5907aa94b 100644 --- a/lib/Doctrine/ORM/Query/TreeWalkerAdapter.php +++ b/lib/Doctrine/ORM/Query/TreeWalkerAdapter.php @@ -55,7 +55,7 @@ abstract class TreeWalkerAdapter implements TreeWalker /** * Retrieve Query Instance reponsible for the current walkers execution. * - * @return Doctrine\ORM\Query + * @return \Doctrine\ORM\Query */ protected function _getQuery() { @@ -65,7 +65,7 @@ abstract class TreeWalkerAdapter implements TreeWalker /** * Retrieve ParserResult * - * @return Doctrine\ORM\Query\ParserResult + * @return \Doctrine\ORM\Query\ParserResult */ protected function _getParserResult() { diff --git a/lib/Doctrine/ORM/Tools/Console/Command/InfoCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/InfoCommand.php index 74d5ee2b4..77458cf13 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/InfoCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/InfoCommand.php @@ -50,7 +50,7 @@ EOT protected function execute(InputInterface $input, OutputInterface $output) { - /* @var $entityManager Doctrine\ORM\EntityManager */ + /* @var $entityManager \Doctrine\ORM\EntityManager */ $entityManager = $this->getHelper('em')->getEntityManager(); $entityClassNames = $entityManager->getConfiguration() diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php index 467332b64..75302717e 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php @@ -27,7 +27,7 @@ use Doctrine\ORM\Tools\Export\ExportException; /** * Abstract base class which is to be used for the Exporter drivers - * which can be found in Doctrine\ORM\Tools\Export\Driver + * which can be found in \Doctrine\ORM\Tools\Export\Driver * * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.doctrine-project.org diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index e052c69d7..2c1236a1f 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -56,7 +56,7 @@ class SchemaTool * Initializes a new SchemaTool instance that uses the connection of the * provided EntityManager. * - * @param Doctrine\ORM\EntityManager $em + * @param \Doctrine\ORM\EntityManager $em */ public function __construct(EntityManager $em) { @@ -180,7 +180,7 @@ class SchemaTool $this->addDiscriminatorColumnDefinition($class, $table); } else { // Add an ID FK column to child tables - /* @var Doctrine\ORM\Mapping\ClassMetadata $class */ + /* @var \Doctrine\ORM\Mapping\ClassMetadata $class */ $idMapping = $class->fieldMappings[$class->identifier[0]]; $this->_gatherColumn($class, $idMapping, $table); $columnName = $class->getQuotedColumnName($class->identifier[0], $this->_platform); diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index eb3111fb8..df33e9e5e 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -177,7 +177,7 @@ class UnitOfWork implements PropertyChangedListener /** * The EntityManager that "owns" this UnitOfWork instance. * - * @var Doctrine\ORM\EntityManager + * @var \Doctrine\ORM\EntityManager */ private $em; @@ -185,7 +185,7 @@ class UnitOfWork implements PropertyChangedListener * The calculator used to calculate the order in which changes to * entities need to be written to the database. * - * @var Doctrine\ORM\Internal\CommitOrderCalculator + * @var \Doctrine\ORM\Internal\CommitOrderCalculator */ private $commitOrderCalculator; @@ -234,7 +234,7 @@ class UnitOfWork implements PropertyChangedListener /** * Initializes a new UnitOfWork instance, bound to the given EntityManager. * - * @param Doctrine\ORM\EntityManager $em + * @param \Doctrine\ORM\EntityManager $em */ public function __construct(EntityManager $em) { @@ -842,7 +842,7 @@ class UnitOfWork implements PropertyChangedListener /** * Executes all entity insertions for entities of the specified type. * - * @param Doctrine\ORM\Mapping\ClassMetadata $class + * @param \Doctrine\ORM\Mapping\ClassMetadata $class */ private function executeInserts($class) { @@ -899,7 +899,7 @@ class UnitOfWork implements PropertyChangedListener /** * Executes all entity updates for entities of the specified type. * - * @param Doctrine\ORM\Mapping\ClassMetadata $class + * @param \Doctrine\ORM\Mapping\ClassMetadata $class */ private function executeUpdates($class) { @@ -949,7 +949,7 @@ class UnitOfWork implements PropertyChangedListener /** * Executes all entity deletions for entities of the specified type. * - * @param Doctrine\ORM\Mapping\ClassMetadata $class + * @param \Doctrine\ORM\Mapping\ClassMetadata $class */ private function executeDeletions($class) { @@ -2140,7 +2140,7 @@ class UnitOfWork implements PropertyChangedListener /** * Gets the CommitOrderCalculator used by the UnitOfWork to order commits. * - * @return Doctrine\ORM\Internal\CommitOrderCalculator + * @return \Doctrine\ORM\Internal\CommitOrderCalculator */ public function getCommitOrderCalculator() { @@ -2652,7 +2652,7 @@ class UnitOfWork implements PropertyChangedListener * * @param string $entityName The name of the Entity. * - * @return Doctrine\ORM\Persisters\BasicEntityPersister + * @return \Doctrine\ORM\Persisters\BasicEntityPersister */ public function getEntityPersister($entityName) { From ef12a09ae0569e3cf67df06ad493d238fdd9dba2 Mon Sep 17 00:00:00 2001 From: Andrew Mackrodt Date: Sun, 11 Dec 2011 21:46:24 +0000 Subject: [PATCH 52/85] Added remaining absolute namespace paths to phpdoc annotations - issue DDC-1025. --- lib/Doctrine/ORM/Configuration.php | 2 +- lib/Doctrine/ORM/Event/EntityEventDelegator.php | 2 +- lib/Doctrine/ORM/Event/LifecycleEventArgs.php | 6 +++--- .../ORM/Event/LoadClassMetadataEventArgs.php | 12 ++++++------ lib/Doctrine/ORM/Event/OnClearEventArgs.php | 6 +++--- lib/Doctrine/ORM/Event/OnFlushEventArgs.php | 4 ++-- lib/Doctrine/ORM/Event/PostFlushEventArgs.php | 6 +++--- lib/Doctrine/ORM/Event/PreUpdateEventArgs.php | 2 +- .../ORM/Internal/Hydration/AbstractHydrator.php | 2 +- .../ORM/Internal/Hydration/ArrayHydrator.php | 2 +- lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php | 4 ++-- lib/Doctrine/ORM/Mapping/JoinColumns.php | 2 +- lib/Doctrine/ORM/Mapping/JoinTable.php | 4 ++-- lib/Doctrine/ORM/Mapping/NamedQueries.php | 2 +- lib/Doctrine/ORM/Mapping/Table.php | 4 ++-- lib/Doctrine/ORM/PersistentCollection.php | 2 +- lib/Doctrine/ORM/Persisters/ManyToManyPersister.php | 2 +- lib/Doctrine/ORM/Query/Expr.php | 6 +++--- lib/Doctrine/ORM/Query/Parser.php | 6 +++--- 19 files changed, 38 insertions(+), 38 deletions(-) diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index eaa4df562..7a7b1792d 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -501,7 +501,7 @@ class Configuration extends \Doctrine\DBAL\Configuration * * @since 2.2 * @param string $className - * @throws ORMException If not is a Doctrine\ORM\EntityRepository + * @throws ORMException If not is a \Doctrine\ORM\EntityRepository */ public function setDefaultRepositoryClassName($className) { diff --git a/lib/Doctrine/ORM/Event/EntityEventDelegator.php b/lib/Doctrine/ORM/Event/EntityEventDelegator.php index 09532bc4b..247c08239 100644 --- a/lib/Doctrine/ORM/Event/EntityEventDelegator.php +++ b/lib/Doctrine/ORM/Event/EntityEventDelegator.php @@ -80,7 +80,7 @@ class EntityEventDelegator implements EventSubscriber * Adds an EventSubscriber. The subscriber is asked for all the events he is * interested in and added as a listener for these events. * - * @param Doctrine\Common\EventSubscriber $subscriber The subscriber. + * @param \Doctrine\Common\EventSubscriber $subscriber The subscriber. * @param array $entities */ public function addEventSubscriber(EventSubscriber $subscriber, $entities) diff --git a/lib/Doctrine/ORM/Event/LifecycleEventArgs.php b/lib/Doctrine/ORM/Event/LifecycleEventArgs.php index 0c91d8475..320b03572 100644 --- a/lib/Doctrine/ORM/Event/LifecycleEventArgs.php +++ b/lib/Doctrine/ORM/Event/LifecycleEventArgs.php @@ -34,7 +34,7 @@ use Doctrine\ORM\EntityManager; class LifecycleEventArgs extends EventArgs { /** - * @var Doctrine\ORM\EntityManager + * @var \Doctrine\ORM\EntityManager */ private $em; @@ -47,7 +47,7 @@ class LifecycleEventArgs extends EventArgs * Constructor * * @param object $entity - * @param Doctrine\ORM\EntityManager $em + * @param \Doctrine\ORM\EntityManager $em */ public function __construct($entity, EntityManager $em) { @@ -68,7 +68,7 @@ class LifecycleEventArgs extends EventArgs /** * Retrieve associated EntityManager. * - * @return Doctrine\ORM\EntityManager + * @return \Doctrine\ORM\EntityManager */ public function getEntityManager() { diff --git a/lib/Doctrine/ORM/Event/LoadClassMetadataEventArgs.php b/lib/Doctrine/ORM/Event/LoadClassMetadataEventArgs.php index a87f45cc3..2cd25933b 100644 --- a/lib/Doctrine/ORM/Event/LoadClassMetadataEventArgs.php +++ b/lib/Doctrine/ORM/Event/LoadClassMetadataEventArgs.php @@ -32,20 +32,20 @@ use Doctrine\ORM\EntityManager; class LoadClassMetadataEventArgs extends EventArgs { /** - * @var Doctrine\ORM\Mapping\ClassMetadata + * @var \Doctrine\ORM\Mapping\ClassMetadata */ private $classMetadata; /** - * @var Doctrine\ORM\EntityManager + * @var \Doctrine\ORM\EntityManager */ private $em; /** * Constructor. * - * @param Doctrine\ORM\Mapping\ClassMetadataInfo $classMetadata - * @param Doctrine\ORM\EntityManager $em + * @param \Doctrine\ORM\Mapping\ClassMetadataInfo $classMetadata + * @param \Doctrine\ORM\EntityManager $em */ public function __construct(ClassMetadataInfo $classMetadata, EntityManager $em) { @@ -56,7 +56,7 @@ class LoadClassMetadataEventArgs extends EventArgs /** * Retrieve associated ClassMetadata. * - * @return Doctrine\ORM\Mapping\ClassMetadataInfo + * @return \Doctrine\ORM\Mapping\ClassMetadataInfo */ public function getClassMetadata() { @@ -66,7 +66,7 @@ class LoadClassMetadataEventArgs extends EventArgs /** * Retrieve associated EntityManager. * - * @return Doctrine\ORM\EntityManager + * @return \Doctrine\ORM\EntityManager */ public function getEntityManager() { diff --git a/lib/Doctrine/ORM/Event/OnClearEventArgs.php b/lib/Doctrine/ORM/Event/OnClearEventArgs.php index 49b5e8695..07f5c4711 100644 --- a/lib/Doctrine/ORM/Event/OnClearEventArgs.php +++ b/lib/Doctrine/ORM/Event/OnClearEventArgs.php @@ -31,7 +31,7 @@ namespace Doctrine\ORM\Event; class OnClearEventArgs extends \Doctrine\Common\EventArgs { /** - * @var Doctrine\ORM\EntityManager + * @var \Doctrine\ORM\EntityManager */ private $em; @@ -43,7 +43,7 @@ class OnClearEventArgs extends \Doctrine\Common\EventArgs /** * Constructor. * - * @param Doctrine\ORM\EntityManager $em + * @param \Doctrine\ORM\EntityManager $em * @param string $entityClass Optional entity class */ public function __construct($em, $entityClass = null) @@ -55,7 +55,7 @@ class OnClearEventArgs extends \Doctrine\Common\EventArgs /** * Retrieve associated EntityManager. * - * @return Doctrine\ORM\EntityManager + * @return \Doctrine\ORM\EntityManager */ public function getEntityManager() { diff --git a/lib/Doctrine/ORM/Event/OnFlushEventArgs.php b/lib/Doctrine/ORM/Event/OnFlushEventArgs.php index 5e6e839fe..fd8545b21 100644 --- a/lib/Doctrine/ORM/Event/OnFlushEventArgs.php +++ b/lib/Doctrine/ORM/Event/OnFlushEventArgs.php @@ -45,7 +45,7 @@ class OnFlushEventArgs extends \Doctrine\Common\EventArgs /** * Constructor. * - * @param Doctrine\ORM\EntityManager $em + * @param \Doctrine\ORM\EntityManager $em */ public function __construct(EntityManager $em) { @@ -55,7 +55,7 @@ class OnFlushEventArgs extends \Doctrine\Common\EventArgs /** * Retrieve associated EntityManager. * - * @return Doctrine\ORM\EntityManager + * @return \Doctrine\ORM\EntityManager */ public function getEntityManager() { diff --git a/lib/Doctrine/ORM/Event/PostFlushEventArgs.php b/lib/Doctrine/ORM/Event/PostFlushEventArgs.php index f500ad92f..e10d600df 100644 --- a/lib/Doctrine/ORM/Event/PostFlushEventArgs.php +++ b/lib/Doctrine/ORM/Event/PostFlushEventArgs.php @@ -35,14 +35,14 @@ use Doctrine\Common\EventArgs; class PostFlushEventArgs extends EventArgs { /** - * @var Doctrine\ORM\EntityManager + * @var \Doctrine\ORM\EntityManager */ private $em; /** * Constructor. * - * @param Doctrine\ORM\EntityManager $em + * @param \Doctrine\ORM\EntityManager $em */ public function __construct(EntityManager $em) { @@ -52,7 +52,7 @@ class PostFlushEventArgs extends EventArgs /** * Retrieve associated EntityManager. * - * @return Doctrine\ORM\EntityManager + * @return \Doctrine\ORM\EntityManager */ public function getEntityManager() { diff --git a/lib/Doctrine/ORM/Event/PreUpdateEventArgs.php b/lib/Doctrine/ORM/Event/PreUpdateEventArgs.php index 35539591a..4d7e3ef38 100644 --- a/lib/Doctrine/ORM/Event/PreUpdateEventArgs.php +++ b/lib/Doctrine/ORM/Event/PreUpdateEventArgs.php @@ -43,7 +43,7 @@ class PreUpdateEventArgs extends LifecycleEventArgs * Constructor. * * @param object $entity - * @param Doctrine\ORM\EntityManager $em + * @param \Doctrine\ORM\EntityManager $em * @param array $changeSet */ public function __construct($entity, EntityManager $em, array &$changeSet) diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index fdb52953c..0a6ab8657 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -344,7 +344,7 @@ abstract class AbstractHydrator /** * Register entity as managed in UnitOfWork. * - * @param Doctrine\ORM\Mapping\ClassMetadata $class + * @param \Doctrine\ORM\Mapping\ClassMetadata $class * @param object $entity * @param array $data * diff --git a/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php index f2869baa2..20c2b5785 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php @@ -276,7 +276,7 @@ class ArrayHydrator extends AbstractHydrator * * @param string $className * - * @return Doctrine\ORM\Mapping\ClassMetadata + * @return \Doctrine\ORM\Mapping\ClassMetadata */ private function getClassMetadata($className) { diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 9fdd1eb06..82ff14531 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -437,8 +437,8 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface * Adds inherited named queries to the subclass mapping. * * @since 2.2 - * @param Doctrine\ORM\Mapping\ClassMetadata $subClass - * @param Doctrine\ORM\Mapping\ClassMetadata $parentClass + * @param \Doctrine\ORM\Mapping\ClassMetadata $subClass + * @param \Doctrine\ORM\Mapping\ClassMetadata $parentClass */ private function addInheritedNamedQueries(ClassMetadata $subClass, ClassMetadata $parentClass) { diff --git a/lib/Doctrine/ORM/Mapping/JoinColumns.php b/lib/Doctrine/ORM/Mapping/JoinColumns.php index 7cf663bc7..525105fab 100644 --- a/lib/Doctrine/ORM/Mapping/JoinColumns.php +++ b/lib/Doctrine/ORM/Mapping/JoinColumns.php @@ -25,6 +25,6 @@ namespace Doctrine\ORM\Mapping; */ final class JoinColumns implements Annotation { - /** @var array */ + /** @var array<\Doctrine\ORM\Mapping\JoinColumn> */ public $value; } diff --git a/lib/Doctrine/ORM/Mapping/JoinTable.php b/lib/Doctrine/ORM/Mapping/JoinTable.php index 75f8e271b..9ff9d4511 100644 --- a/lib/Doctrine/ORM/Mapping/JoinTable.php +++ b/lib/Doctrine/ORM/Mapping/JoinTable.php @@ -29,8 +29,8 @@ final class JoinTable implements Annotation public $name; /** @var string */ public $schema; - /** @var array */ + /** @var array<\Doctrine\ORM\Mapping\JoinColumn> */ public $joinColumns = array(); - /** @var array */ + /** @var array<\Doctrine\ORM\Mapping\JoinColumn> */ public $inverseJoinColumns = array(); } diff --git a/lib/Doctrine/ORM/Mapping/NamedQueries.php b/lib/Doctrine/ORM/Mapping/NamedQueries.php index 04e0ebfaa..1ab2bf233 100644 --- a/lib/Doctrine/ORM/Mapping/NamedQueries.php +++ b/lib/Doctrine/ORM/Mapping/NamedQueries.php @@ -25,6 +25,6 @@ namespace Doctrine\ORM\Mapping; */ final class NamedQueries implements Annotation { - /** @var array */ + /** @var array<\Doctrine\ORM\Mapping\NamedQuery> */ public $value; } diff --git a/lib/Doctrine/ORM/Mapping/Table.php b/lib/Doctrine/ORM/Mapping/Table.php index a68e3673b..41db294de 100644 --- a/lib/Doctrine/ORM/Mapping/Table.php +++ b/lib/Doctrine/ORM/Mapping/Table.php @@ -29,8 +29,8 @@ final class Table implements Annotation public $name; /** @var string */ public $schema; - /** @var array */ + /** @var array<\Doctrine\ORM\Mapping\Index> */ public $indexes; - /** @var array */ + /** @var array<\Doctrine\ORM\Mapping\UniqueConstraint> */ public $uniqueConstraints; } diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index bca07fdf0..66dca2bbd 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -728,7 +728,7 @@ final class PersistentCollection implements Collection /** * Retrieves the wrapped Collection instance. * - * @return Doctrine\Common\Collections\Collection + * @return \Doctrine\Common\Collections\Collection */ public function unwrap() { diff --git a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php index e94cb3443..bd147343f 100644 --- a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php @@ -279,7 +279,7 @@ class ManyToManyPersister extends AbstractCollectionPersister } /** - * @param Doctrine\ORM\PersistentCollection $coll + * @param \Doctrine\ORM\PersistentCollection $coll * @param object $element * @return array */ diff --git a/lib/Doctrine/ORM/Query/Expr.php b/lib/Doctrine/ORM/Query/Expr.php index 6ba6a5d73..dce4c6044 100644 --- a/lib/Doctrine/ORM/Query/Expr.php +++ b/lib/Doctrine/ORM/Query/Expr.php @@ -42,9 +42,9 @@ class Expr * // (u.type = ?1) AND (u.role = ?2) * $expr->andX($expr->eq('u.type', ':1'), $expr->eq('u.role', ':2')); * - * @param Doctrine\ORM\Query\Expr\Comparison | - * Doctrine\ORM\Query\Expr\Func | - * Doctrine\ORM\Query\Expr\Orx + * @param \Doctrine\ORM\Query\Expr\Comparison | + * \Doctrine\ORM\Query\Expr\Func | + * \Doctrine\ORM\Query\Expr\Orx * $x Optional clause. Defaults = null, but requires at least one defined when converting to string. * @return Expr\Andx */ diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index e46f85b6c..4c1bd50e1 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -1781,7 +1781,7 @@ class Parser /** * GeneralCaseExpression ::= "CASE" WhenClause {WhenClause}* "ELSE" ScalarExpression "END" * - * @return Doctrine\ORM\Query\AST\GeneralExpression + * @return \Doctrine\ORM\Query\AST\GeneralExpression */ public function GeneralCaseExpression() { @@ -1827,7 +1827,7 @@ class Parser /** * WhenClause ::= "WHEN" ConditionalExpression "THEN" ScalarExpression * - * @return Doctrine\ORM\Query\AST\WhenExpression + * @return \Doctrine\ORM\Query\AST\WhenExpression */ public function WhenClause() { @@ -1841,7 +1841,7 @@ class Parser /** * SimpleWhenClause ::= "WHEN" ScalarExpression "THEN" ScalarExpression * - * @return Doctrine\ORM\Query\AST\SimpleWhenExpression + * @return \Doctrine\ORM\Query\AST\SimpleWhenExpression */ public function SimpleWhenClause() { From 43ef8765fd9a3ee6bab5ff8d90af8056c8870d8d Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Mon, 12 Dec 2011 16:39:52 +0100 Subject: [PATCH 53/85] DDC-1527 - Port bugfix for master branch --- lib/Doctrine/ORM/Persisters/BasicEntityPersister.php | 6 +++--- tests/Doctrine/Tests/ORM/Functional/TypeTest.php | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index e94e91575..08f316fb3 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -1433,7 +1433,7 @@ class BasicEntityPersister { switch (true) { case (isset($this->_class->fieldMappings[$field])): - $type = Type::getType($this->_class->fieldMappings[$field]['type'])->getBindingType(); + $type = $this->_class->fieldMappings[$field]['type']; break; case (isset($this->_class->associationMappings[$field])): @@ -1448,7 +1448,7 @@ class BasicEntityPersister $type = null; if (isset($targetClass->fieldNames[$targetColumn])) { - $type = Type::getType($targetClass->fieldMappings[$targetClass->fieldNames[$targetColumn]]['type'])->getBindingType(); + $type = $targetClass->fieldMappings[$targetClass->fieldNames[$targetColumn]]['type']; } break; @@ -1456,8 +1456,8 @@ class BasicEntityPersister default: $type = null; } - if (is_array($value)) { + $type = Type::getType( $type )->getBindingType(); $type += Connection::ARRAY_PARAM_OFFSET; } diff --git a/tests/Doctrine/Tests/ORM/Functional/TypeTest.php b/tests/Doctrine/Tests/ORM/Functional/TypeTest.php index 8a2eab70e..9ed8cf050 100644 --- a/tests/Doctrine/Tests/ORM/Functional/TypeTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/TypeTest.php @@ -125,6 +125,9 @@ class TypeTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertInstanceOf('DateTime', $dateTimeDb->datetime); $this->assertEquals('2009-10-02 20:10:52', $dateTimeDb->datetime->format('Y-m-d H:i:s')); + + $articles = $this->_em->getRepository( 'Doctrine\Tests\Models\Generic\DateTimeModel' )->findBy( array( 'datetime' => new \DateTime( "now" ) ) ); + $this->assertEquals( 0, count( $articles ) ); } public function testDqlQueryBindDateTimeInstance() @@ -176,4 +179,4 @@ class TypeTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertInstanceOf('DateTime', $dateTime->time); $this->assertEquals('19:27:20', $dateTime->time->format('H:i:s')); } -} \ No newline at end of file +} From f7ede572e00369f895caf2d88fb3076711bb7199 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Mon, 12 Dec 2011 16:46:53 +0100 Subject: [PATCH 54/85] DDC-1415 - Remove EntityEventDelegatee, the API sucks and we need another approach. --- .../ORM/Event/EntityEventDelegator.php | 122 ------------------ 1 file changed, 122 deletions(-) delete mode 100644 lib/Doctrine/ORM/Event/EntityEventDelegator.php diff --git a/lib/Doctrine/ORM/Event/EntityEventDelegator.php b/lib/Doctrine/ORM/Event/EntityEventDelegator.php deleted file mode 100644 index 247c08239..000000000 --- a/lib/Doctrine/ORM/Event/EntityEventDelegator.php +++ /dev/null @@ -1,122 +0,0 @@ -. -*/ - -namespace Doctrine\ORM\Event; - -use Doctrine\Common\EventSubscriber; -use LogicException; - -/** - * Delegate events only for certain entities they are registered for. - * - * @link www.doctrine-project.org - * @author Benjamin Eberlei - * @author Guilherme Blanco - * @since 2.2 - */ -class EntityEventDelegator implements EventSubscriber -{ - /** - * Keeps track of all the event listeners. - * - * @var array - */ - private $listeners = array(); - - /** - * If frozen no new event listeners can be added. - * - * @var bool - */ - private $frozen = false; - - /** - * Adds an event listener that listens on the specified events. - * - * @param string|array $events The event(s) to listen on. - * @param string|array $entities The entities to trigger this listener for - * @param object $listener The listener object. - */ - public function addEventListener($events, $entities, $listener) - { - if ($this->frozen) { - throw new LogicException( - "Cannot add event listeners after EntityEventDelegator::getSubscribedEvents() " . - "is called once. This happens when you register the delegator with the event manager." - ); - } - - // Picks the hash code related to that listener - $hash = spl_object_hash($listener); - $entities = array_flip((array) $entities); - - foreach ((array) $events as $event) { - // Overrides listener if a previous one was associated already - // Prevents duplicate listeners on same event (same instance only) - $this->listeners[$event][$hash] = array( - 'listener' => $listener, - 'entities' => $entities - ); - } - } - - /** - * Adds an EventSubscriber. The subscriber is asked for all the events he is - * interested in and added as a listener for these events. - * - * @param \Doctrine\Common\EventSubscriber $subscriber The subscriber. - * @param array $entities - */ - public function addEventSubscriber(EventSubscriber $subscriber, $entities) - { - $this->addEventListener($subscriber->getSubscribedEvents(), $entities, $subscriber); - } - - /** - * Returns an array of events this subscriber wants to listen to. - * - * @return array - */ - public function getSubscribedEvents() - { - $this->frozen = true; - - return array_keys($this->listeners); - } - - /** - * Delegate the event to an appropriate listener - * - * @param string $eventName - * @param array $args - * @return void - */ - public function __call($eventName, $args) - { - $event = $args[0]; - - foreach ($this->listeners[$eventName] AS $listenerData) { - $class = get_class($event->getEntity()); - - if ( ! isset($listenerData['entities'][$class])) continue; - - $listenerData['listener']->$eventName($event); - } - } -} From 65c2b498ad2b8764f1fd6e5ab714c98bbe73ad11 Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Mon, 12 Dec 2011 23:40:48 -0500 Subject: [PATCH 55/85] Removed broken test. --- .../ORM/Event/EntityEventDelegateeTest.php | 91 ------------------- 1 file changed, 91 deletions(-) delete mode 100644 tests/Doctrine/Tests/ORM/Event/EntityEventDelegateeTest.php diff --git a/tests/Doctrine/Tests/ORM/Event/EntityEventDelegateeTest.php b/tests/Doctrine/Tests/ORM/Event/EntityEventDelegateeTest.php deleted file mode 100644 index 5c4db0101..000000000 --- a/tests/Doctrine/Tests/ORM/Event/EntityEventDelegateeTest.php +++ /dev/null @@ -1,91 +0,0 @@ -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 From 99e46a23c630a3081abbaa372de0712cfbb07ede Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Tue, 13 Dec 2011 21:24:02 +0100 Subject: [PATCH 56/85] Bugfix in UnitOfWorklib/Doctrine/ORM/UnitOfWork.phptriggerEagerLoads() --- lib/Doctrine/ORM/UnitOfWork.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index df33e9e5e..f02083d0d 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -2499,9 +2499,11 @@ class UnitOfWork implements PropertyChangedListener foreach ($eagerLoadingEntities as $entityName => $ids) { $class = $this->em->getClassMetadata($entityName); - $this->getEntityPersister($entityName)->loadAll( - array_combine($class->identifier, array(array_values($ids))) - ); + if ($ids) { + $this->getEntityPersister($entityName)->loadAll( + array_combine($class->identifier, array(array_values($ids))) + ); + } } } From 017a7d889f109d9501808080d1b13961348c87f9 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Thu, 15 Dec 2011 17:12:01 -0200 Subject: [PATCH 57/85] Fixed DDC-1468 --- .../ORM/Mapping/Driver/AbstractFileDriver.php | 3 +++ lib/Doctrine/ORM/Mapping/MappingException.php | 5 +++++ .../Tests/ORM/Mapping/XmlMappingDriverTest.php | 11 +++++++++++ .../Tests/ORM/Mapping/YamlMappingDriverTest.php | 11 +++++++++++ ...ts.Models.Generic.SerializationModel.dcm.xml | 17 +++++++++++++++++ ...ts.Models.Generic.SerializationModel.dcm.yml | 13 +++++++++++++ 6 files changed, 60 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml create mode 100644 tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.Generic.SerializationModel.dcm.yml diff --git a/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php index 457b7cda7..a92432db8 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php @@ -118,6 +118,9 @@ abstract class AbstractFileDriver implements Driver { $result = $this->_loadMappingFile($this->_findMappingFile($className)); + if(!isset($result[$className])){ + throw MappingException::invalidMappingFile($className, str_replace('\\', '.', $className) . $this->_fileExtension); + } return $result[$className]; } diff --git a/lib/Doctrine/ORM/Mapping/MappingException.php b/lib/Doctrine/ORM/Mapping/MappingException.php index 014714bf8..bf8da82e6 100644 --- a/lib/Doctrine/ORM/Mapping/MappingException.php +++ b/lib/Doctrine/ORM/Mapping/MappingException.php @@ -67,6 +67,11 @@ class MappingException extends \Doctrine\ORM\ORMException { return new self("No mapping file found named '$fileName' for class '$entityName'."); } + + public static function invalidMappingFile($entityName, $fileName) + { + return new self("Invalid mapping file '$fileName' for class '$entityName'."); + } public static function mappingNotFound($className, $fieldName) { diff --git a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php index 9ba8748f4..980a720df 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php @@ -51,6 +51,17 @@ class XmlMappingDriverTest extends AbstractMappingDriverTest $this->assertTrue($class->associationMappings['article']['id']); } + /** + * @group DDC-1468 + * + * @expectedException Doctrine\ORM\Mapping\MappingException + * @expectedExceptionMessage Invalid mapping file 'Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml' for class 'Doctrine\Tests\Models\Generic\SerializationModel'. + */ + public function testInvalidMappingFileException() + { + $this->createClassMetadata('Doctrine\Tests\Models\Generic\SerializationModel'); + } + /** * @param string $xmlMappingFile * @dataProvider dataValidSchema diff --git a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php index 34c3fa810..2757259a4 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php @@ -43,4 +43,15 @@ class YamlMappingDriverTest extends AbstractMappingDriverTest $this->assertEquals('Doctrine\Tests\Models\DirectoryTree\Directory', $classDirectory->associationMappings['parentDirectory']['sourceEntity']); } + /** + * @group DDC-1468 + * + * @expectedException Doctrine\ORM\Mapping\MappingException + * @expectedExceptionMessage Invalid mapping file 'Doctrine.Tests.Models.Generic.SerializationModel.dcm.yml' for class 'Doctrine\Tests\Models\Generic\SerializationModel'. + */ + public function testInvalidMappingFileException() + { + $this->createClassMetadata('Doctrine\Tests\Models\Generic\SerializationModel'); + } + } diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml new file mode 100644 index 000000000..36af855f2 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.Generic.SerializationModel.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.Generic.SerializationModel.dcm.yml new file mode 100644 index 000000000..64f74b55f --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.Generic.SerializationModel.dcm.yml @@ -0,0 +1,13 @@ +\stdClass: + type: entity + id: + id: + type: integer + unsigned: true + generator: + strategy: AUTO + fields: + array: + type: array + object: + type: object \ No newline at end of file From e8a47b3921a9bd1a432d3423fef26e83c04cce18 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Thu, 15 Dec 2011 20:49:25 +0100 Subject: [PATCH 58/85] DDC-1519 - Fix bug in merging of entities that contain foreign identifiers --- lib/Doctrine/ORM/EntityRepository.php | 2 +- lib/Doctrine/ORM/UnitOfWork.php | 17 +++++++++++++++-- .../Tests/ORM/Functional/Ticket/DDC117Test.php | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index 1b0619efe..17cc29807 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -117,7 +117,7 @@ class EntityRepository implements ObjectRepository } $sortedId[$identifier] = $id[$identifier]; } - + // Check identity map first if ($entity = $this->_em->getUnitOfWork()->tryGetById($sortedId, $this->_class->rootEntityName)) { if ( ! ($entity instanceof $this->_class->name)) { diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index f02083d0d..a026d001a 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1647,7 +1647,20 @@ class UnitOfWork implements PropertyChangedListener $this->persistNew($class, $managedCopy); } else { - $managedCopy = $this->tryGetById($id, $class->rootEntityName); + $flatId = $id; + if ($class->containsForeignIdentifier) { + // convert foreign identifiers into scalar foreign key + // values to avoid object to string conversion failures. + foreach ($id as $idField => $idValue) { + if (isset($class->associationMappings[$idField])) { + $targetClassMetadata = $this->em->getClassMetadata($class->associationMappings[$idField]['targetEntity']); + $associatedId = $this->getEntityIdentifier($idValue); + $flatId[$idField] = $associatedId[$targetClassMetadata->identifier[0]]; + } + } + } + + $managedCopy = $this->tryGetById($flatId, $class->rootEntityName); if ($managedCopy) { // We have the entity in-memory already, just make sure its not removed. @@ -1657,7 +1670,7 @@ class UnitOfWork implements PropertyChangedListener } } else { // We need to fetch the managed copy in order to merge. - $managedCopy = $this->em->find($class->name, $id); + $managedCopy = $this->em->find($class->name, $flatId); } if ($managedCopy === null) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php index 9e1b5b074..c79bd2f46 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php @@ -417,4 +417,20 @@ class DDC117Test extends \Doctrine\Tests\OrmFunctionalTestCase return $this->_em->find(get_class($editor), $editor->id); } + + /** + * @group DDC-1519 + */ + public function testMergeForeignKeyIdentifierEntity() + { + $idCriteria = array('source' => $this->article1->id(), 'target' => $this->article2->id()); + + $refRep = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Reference", $idCriteria); + + $this->_em->detach($refRep); + $refRep = $this->_em->merge($refRep); + + $this->assertEquals($this->article1->id(), $refRep->source()->id()); + $this->assertEquals($this->article2->id(), $refRep->target()->id()); + } } From 5b5fb2b732842ff78a5ad60bb0d84c54b9e40fea Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Thu, 15 Dec 2011 23:00:01 +0100 Subject: [PATCH 59/85] DDC-1514 - Fix complex self-referencing + proxy hydration problem. --- .../ORM/Internal/Hydration/ObjectHydrator.php | 8 +- .../ORM/Functional/Ticket/DDC1514Test.php | 111 ++++++++++++++++++ 2 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1514Test.php diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index 36dbfa46a..f7de28538 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -26,7 +26,8 @@ use PDO, Doctrine\ORM\Event\LifecycleEventArgs, Doctrine\ORM\Events, Doctrine\Common\Collections\ArrayCollection, - Doctrine\Common\Collections\Collection; + Doctrine\Common\Collections\Collection, + Doctrine\ORM\Proxy\Proxy; /** * The ObjectHydrator constructs an object graph out of an SQL result set. @@ -358,6 +359,7 @@ class ObjectHydrator extends AbstractHydrator continue; } + $parentClass = $this->_ce[$this->_rsm->aliasMap[$parentAlias]]; $oid = spl_object_hash($parentObject); $relationField = $this->_rsm->relationMap[$dqlAlias]; @@ -412,7 +414,9 @@ class ObjectHydrator extends AbstractHydrator } else { // PATH B: Single-valued association $reflFieldValue = $reflField->getValue($parentObject); - if ( ! $reflFieldValue || isset($this->_hints[Query::HINT_REFRESH])) { + if ( ! $reflFieldValue || isset($this->_hints[Query::HINT_REFRESH]) || ($reflFieldValue instanceof Proxy && !$reflFieldValue->__isInitialized__)) { + // we only need to take action if this value is null, + // we refresh the entity or its an unitialized proxy. if (isset($nonemptyComponents[$dqlAlias])) { $element = $this->_getEntity($data, $dqlAlias); $reflField->setValue($parentObject, $element); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1514Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1514Test.php new file mode 100644 index 000000000..c905d0048 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1514Test.php @@ -0,0 +1,111 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1514EntityA'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1514EntityB'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1514EntityC'), + )); + } catch (\Exception $ignored) { + } + } + + public function testIssue() + { + $a1 = new DDC1514EntityA(); + $a1->title = "foo"; + + $a2 = new DDC1514EntityA(); + $a2->title = "bar"; + + $b1 = new DDC1514EntityB(); + $b1->entityAFrom = $a1; + $b1->entityATo = $a2; + + $b2 = new DDC1514EntityB(); + $b2->entityAFrom = $a2; + $b2->entityATo = $a1; + + $c = new DDC1514EntityC(); + $c->title = "baz"; + $a2->entityC = $c; + + $this->_em->persist($a1); + $this->_em->persist($a2); + $this->_em->persist($b1); + $this->_em->persist($b2); + $this->_em->persist($c); + $this->_em->flush(); + $this->_em->clear(); + + $dql = "SELECT a, b, ba, c FROM " . __NAMESPACE__ . "\DDC1514EntityA AS a LEFT JOIN a.entitiesB AS b LEFT JOIN b.entityATo AS ba LEFT JOIN a.entityC AS c"; + $results = $this->_em->createQuery($dql)->getResult(); + + $this->assertEquals($c->title, $results[1]->entityC->title); + } +} + +/** + * @Entity + */ +class DDC1514EntityA +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; + /** @Column */ + public $title; + /** @ManyToMany(targetEntity="DDC1514EntityB", mappedBy="entityAFrom") */ + public $entitiesB; + /** @ManyToOne(targetEntity="DDC1514EntityC") */ + public $entityC; + + public function __construct() + { + $this->entitiesB = new ArrayCollection(); + } +} + +/** + * @Entity + */ +class DDC1514EntityB +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; + + /** + * @ManyToOne(targetEntity="DDC1514EntityA", inversedBy="entitiesB") + */ + public $entityAFrom; + /** + * @ManyToOne(targetEntity="DDC1514EntityA") + */ + public $entityATo; +} + +/** + * @Entity + */ +class DDC1514EntityC +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; + /** @Column */ + public $title; +} From cac9928f2853208603a75d835d20ff2a35da9326 Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Fri, 16 Dec 2011 16:16:22 -0500 Subject: [PATCH 60/85] Incorporated setAssociationTargetClass, which solves biggest problem of modular system in ZF. Any questions, pelase forward to @EvanDotPro. --- lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index d845e6f59..0c3a339eb 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -1849,6 +1849,21 @@ class ClassMetadataInfo implements ClassMetadata } } + /** + * Refine an association targetEntity class pointer to be consumed through loadMetadata event. + * + * @param string $assoc + * @param string $class + */ + public function setAssociationTargetClass($assocName, $class) + { + if ( ! isset($this->associationMappings[$assocName])) { + throw new \InvalidArgumentException("Association name expected, '" . $assocName ."' is not an association."); + } + + $this->associationMappings[$assocName]['targetEntity'] = $class; + } + /** * Sets whether this class is to be versioned for optimistic locking. * From 98bd5cae64560aea670069833c10b22d25df2b8b Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 17 Dec 2011 11:36:23 +0100 Subject: [PATCH 61/85] Revert "Incorporated setAssociationTargetClass, which solves biggest problem of modular system in ZF. Any questions, pelase forward to @EvanDotPro." This reverts commit cac9928f2853208603a75d835d20ff2a35da9326. --- lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 0c3a339eb..d845e6f59 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -1849,21 +1849,6 @@ class ClassMetadataInfo implements ClassMetadata } } - /** - * Refine an association targetEntity class pointer to be consumed through loadMetadata event. - * - * @param string $assoc - * @param string $class - */ - public function setAssociationTargetClass($assocName, $class) - { - if ( ! isset($this->associationMappings[$assocName])) { - throw new \InvalidArgumentException("Association name expected, '" . $assocName ."' is not an association."); - } - - $this->associationMappings[$assocName]['targetEntity'] = $class; - } - /** * Sets whether this class is to be versioned for optimistic locking. * From 60152530646aef7029ddaed0fb338b0454604652 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 17 Dec 2011 12:35:22 +0100 Subject: [PATCH 62/85] DDC-1524 - Add validation and error messages for annotation named query code. --- lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index d469fd66e..bee84159f 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -192,7 +192,14 @@ class AnnotationDriver implements Driver if (isset($classAnnotations['Doctrine\ORM\Mapping\NamedQueries'])) { $namedQueriesAnnot = $classAnnotations['Doctrine\ORM\Mapping\NamedQueries']; + if (!is_array($namedQueriesAnnot->value)) { + throw new \UnexpectedValueException("@NamedQueries should contain an array of @NamedQuery annotations."); + } + foreach ($namedQueriesAnnot->value as $namedQuery) { + if (!($namedQuery instanceof \Doctrine\ORM\Mapping\NamedQuery)) { + throw new \UnexpectedValueException("@NamedQueries should contain an array of @NamedQuery annotations."); + } $metadata->addNamedQuery(array( 'name' => $namedQuery->name, 'query' => $namedQuery->query From cfe125940092e4c7403201703ae0428b943432f5 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 17 Dec 2011 12:39:44 +0100 Subject: [PATCH 63/85] DDC-1541 - Fix wrong references in ClassMetadataBuilder --- .../ORM/Mapping/Builder/ClassMetadataBuilder.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/Builder/ClassMetadataBuilder.php b/lib/Doctrine/ORM/Mapping/Builder/ClassMetadataBuilder.php index f7d5031cd..3765fbd93 100644 --- a/lib/Doctrine/ORM/Mapping/Builder/ClassMetadataBuilder.php +++ b/lib/Doctrine/ORM/Mapping/Builder/ClassMetadataBuilder.php @@ -298,7 +298,7 @@ class ClassMetadataBuilder $builder = $this->createManyToOne($name, $targetEntity); if ($inversedBy) { - $builder->setInversedBy($inversedBy); + $builder->inversedBy($inversedBy); } return $builder->build(); @@ -355,7 +355,7 @@ class ClassMetadataBuilder public function addInverseOneToOne($name, $targetEntity, $mappedBy) { $builder = $this->createOneToOne($name, $targetEntity); - $builder->setMappedBy($mappedBy); + $builder->mappedBy($mappedBy); return $builder->build(); } @@ -373,7 +373,7 @@ class ClassMetadataBuilder $builder = $this->createOneToOne($name, $targetEntity); if ($inversedBy) { - $builder->setInversedBy($inversedBy); + $builder->inversedBy($inversedBy); } return $builder->build(); @@ -411,7 +411,7 @@ class ClassMetadataBuilder $builder = $this->createManyToMany($name, $targetEntity); if ($inversedBy) { - $builder->setInversedBy($inversedBy); + $builder->inversedBy($inversedBy); } return $builder->build(); @@ -428,7 +428,7 @@ class ClassMetadataBuilder public function addInverseManyToMany($name, $targetEntity, $mappedBy) { $builder = $this->createManyToMany($name, $targetEntity); - $builder->setMappedBy($mappedBy); + $builder->mappedBy($mappedBy); return $builder->build(); } @@ -463,7 +463,7 @@ class ClassMetadataBuilder public function addOneToMany($name, $targetEntity, $mappedBy) { $builder = $this->createOneToMany($name, $targetEntity); - $builder->setMappedBy($mappedBy); + $builder->mappedBy($mappedBy); return $builder->build(); } From 267ce7df889eb971e2e27e260ce03b110ce1f7a3 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 17 Dec 2011 19:35:10 +0100 Subject: [PATCH 64/85] DDC-1544 - Add ResolveTargetEntityListener --- .../ORM/Tools/ResolveTargetEntityListener.php | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 lib/Doctrine/ORM/Tools/ResolveTargetEntityListener.php diff --git a/lib/Doctrine/ORM/Tools/ResolveTargetEntityListener.php b/lib/Doctrine/ORM/Tools/ResolveTargetEntityListener.php new file mode 100644 index 000000000..6151763da --- /dev/null +++ b/lib/Doctrine/ORM/Tools/ResolveTargetEntityListener.php @@ -0,0 +1,92 @@ +. + */ + +namespace Doctrine\ORM\Tools; + +use Doctrine\ORM\Events\LoadClassMetadataEventArgs; + +/** + * ResolveTargetEntityListener + * + * Mechanism to overwrite interfaces or classes specified as association + * targets. + * + * @author Benjamin Eberlei + * @since 2.2 + */ +class ResolveTargetEntityListener +{ + /** + * @var array + */ + private $resolveTargetEntities = array(); + + /** + * Add a target-entity class name to resolve to a new class name. + * + * @param string $originalEntity + * @param string $newEntity + * @param array $mapping + * @return void + */ + public function addResolveTargetEntity($originalEntity, $newEntity, array $mapping) + { + $mapping['targetEntity'] = ltrim($newEntity, "\\"); + $this->resolveTargetEntities[ltrim($originalEntity, "\\")] = $mapping; + } + + /** + * Process event and resolve new target entity names. + * + * @param LoadClassMetadataEventArgs $args + * @return void + */ + public function loadClassMetadata(LoadClassMetadataEventArgs $args) + { + $cm = $args->getClassMetadata(); + foreach ($cm->associationMappings as $assocName => $mapping) { + if (isset($this->resolveTargetEntities[$mapping['targetEntity']])) { + $this->remapAssociation($cm, $mapping); + } + } + } + + private function remapAssocation($classMetadata, $mapping) + { + $newMapping = $this->resolveTargetEntities[$mapping['targetEntity']]; + $newMapping['fieldName'] = $mapping['fieldName']; + unset($cm->associationMappings[$mapping['fieldName']]); + + switch ($mapping['type']) { + case ClassMetadata::MANY_TO_MANY: + $cm->mapManyToMany($newMapping); + break; + case ClassMetadata::MANY_TO_ONE: + $cm->mapManyToOne($newMapping); + break; + case ClassMetadata::ONE_TO_MANY: + $cm->mapOneToMany($newMapping); + break; + case ClassMetadata::ONE_TO_ONE: + $cm->mapOneToOne($newMapping); + break; + } + } +} + From 36a47e391cffa9a65b8fb80ce6f82b4a94d2d9dc Mon Sep 17 00:00:00 2001 From: Evan Coury Date: Sat, 17 Dec 2011 15:00:05 -0700 Subject: [PATCH 65/85] DDC-1544 - Add unit test and assertions for ResolveTargetEntityListener --- .../ORM/Tools/ResolveTargetEntityListener.php | 16 ++- .../Tools/ResolveTargetEntityListenerTest.php | 129 ++++++++++++++++++ 2 files changed, 138 insertions(+), 7 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Tools/ResolveTargetEntityListenerTest.php diff --git a/lib/Doctrine/ORM/Tools/ResolveTargetEntityListener.php b/lib/Doctrine/ORM/Tools/ResolveTargetEntityListener.php index 6151763da..621214fdd 100644 --- a/lib/Doctrine/ORM/Tools/ResolveTargetEntityListener.php +++ b/lib/Doctrine/ORM/Tools/ResolveTargetEntityListener.php @@ -19,7 +19,8 @@ namespace Doctrine\ORM\Tools; -use Doctrine\ORM\Events\LoadClassMetadataEventArgs; +use Doctrine\ORM\Event\LoadClassMetadataEventArgs; +use Doctrine\ORM\Mapping\ClassMetadata; /** * ResolveTargetEntityListener @@ -67,24 +68,25 @@ class ResolveTargetEntityListener } } - private function remapAssocation($classMetadata, $mapping) + private function remapAssociation($classMetadata, $mapping) { $newMapping = $this->resolveTargetEntities[$mapping['targetEntity']]; + $newMapping = array_replace_recursive($mapping, $newMapping); $newMapping['fieldName'] = $mapping['fieldName']; - unset($cm->associationMappings[$mapping['fieldName']]); + unset($classMetadata->associationMappings[$mapping['fieldName']]); switch ($mapping['type']) { case ClassMetadata::MANY_TO_MANY: - $cm->mapManyToMany($newMapping); + $classMetadata->mapManyToMany($newMapping); break; case ClassMetadata::MANY_TO_ONE: - $cm->mapManyToOne($newMapping); + $classMetadata->mapManyToOne($newMapping); break; case ClassMetadata::ONE_TO_MANY: - $cm->mapOneToMany($newMapping); + $classMetadata->mapOneToMany($newMapping); break; case ClassMetadata::ONE_TO_ONE: - $cm->mapOneToOne($newMapping); + $classMetadata->mapOneToOne($newMapping); break; } } diff --git a/tests/Doctrine/Tests/ORM/Tools/ResolveTargetEntityListenerTest.php b/tests/Doctrine/Tests/ORM/Tools/ResolveTargetEntityListenerTest.php new file mode 100644 index 000000000..b794474a8 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Tools/ResolveTargetEntityListenerTest.php @@ -0,0 +1,129 @@ +createAnnotationDriver(); + + $this->em = $this->_getTestEntityManager(); + $this->em->getConfiguration()->setMetadataDriverImpl($annotationDriver); + $this->factory = new ClassMetadataFactory; + $this->factory->setEntityManager($this->em); + $this->listener = new ResolveTargetEntityListener; + } + + /** + * @group DDC-1544 + */ + public function testResolveTargetEntityListenerCanResolveTargetEntity() + { + $evm = $this->em->getEventManager(); + $this->listener->addResolveTargetEntity( + 'Doctrine\Tests\ORM\Tools\ResolveTargetInterface', + 'Doctrine\Tests\ORM\Tools\ResolveTargetEntity', + array() + ); + $this->listener->addResolveTargetEntity( + 'Doctrine\Tests\ORM\Tools\TargetInterface', + 'Doctrine\Tests\ORM\Tools\TargetEntity', + array() + ); + $evm->addEventListener(Events::loadClassMetadata, $this->listener); + $cm = $this->factory->getMetadataFor('Doctrine\Tests\ORM\Tools\ResolveTargetEntity'); + $meta = $cm->associationMappings; + $this->assertSame('Doctrine\Tests\ORM\Tools\TargetEntity', $meta['manyToMany']['targetEntity']); + $this->assertSame('Doctrine\Tests\ORM\Tools\ResolveTargetEntity', $meta['manyToOne']['targetEntity']); + $this->assertSame('Doctrine\Tests\ORM\Tools\ResolveTargetEntity', $meta['oneToMany']['targetEntity']); + $this->assertSame('Doctrine\Tests\ORM\Tools\TargetEntity', $meta['oneToOne']['targetEntity']); + } +} + +interface ResolveTargetInterface +{ + public function getId(); +} + +interface TargetInterface extends ResolveTargetInterface +{ +} + +/** + * @Entity + */ +class ResolveTargetEntity implements ResolveTargetInterface +{ + /** + * @Id + * @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + */ + private $id; + + /** + * @ManyToMany(targetEntity="Doctrine\Tests\ORM\Tools\TargetInterface") + */ + private $manyToMany; + + /** + * @ManyToOne(targetEntity="Doctrine\Tests\ORM\Tools\ResolveTargetInterface", inversedBy="oneToMany") + */ + private $manyToOne; + + /** + * @OneToMany(targetEntity="Doctrine\Tests\ORM\Tools\ResolveTargetInterface", mappedBy="manyToOne") + */ + private $oneToMany; + + /** + * @OneToOne(targetEntity="Doctrine\Tests\ORM\Tools\TargetInterface") + * @JoinColumn(name="target_entity_id", referencedColumnName="id") + */ + private $oneToOne; + + public function getId() + { + return $this->id; + } +} + +/** + * @Entity + */ +class TargetEntity implements TargetInterface +{ + /** + * @Id + * @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + */ + private $id; + + public function getId() + { + return $this->id; + } +} From 170271fd72a276a06308693060d7752b3f221a8b Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 17 Dec 2011 23:27:39 +0100 Subject: [PATCH 66/85] DDC-1368 - Improve schema validator --- lib/Doctrine/ORM/Tools/SchemaValidator.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Tools/SchemaValidator.php b/lib/Doctrine/ORM/Tools/SchemaValidator.php index cb3c9e515..f94234487 100644 --- a/lib/Doctrine/ORM/Tools/SchemaValidator.php +++ b/lib/Doctrine/ORM/Tools/SchemaValidator.php @@ -28,7 +28,6 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo; * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.doctrine-project.com * @since 1.0 - * @version $Revision$ * @author Benjamin Eberlei * @author Guilherme Blanco * @author Jonathan Wage @@ -139,6 +138,19 @@ class SchemaValidator $assoc['targetEntity'] . "#" . $assoc['inversedBy'] . " are ". "incosistent with each other."; } + + // Verify inverse side/owning side match each other + $targetAssoc = $targetMetadata->associationMappings[$assoc['inversedBy']]; + if ($assoc['type'] == ClassMetadata::ONE_TO_ONE && $targetAssoc['type'] !== ClassMetadata::ONE_TO_ONE){ + $ce[] = "If association " . $class->name . "#" . $fieldName . " is one-to-one, then the inversed " . + "side " . $targetMetadata->name . "#" . $assoc['inversedBy'] . " has to be one-to-one as well."; + } else if ($assoc['type'] == ClassMetadata::MANY_TO_ONE && $targetAssoc['type'] !== ClassMetadata::ONE_TO_MANY){ + $ce[] = "If association " . $class->name . "#" . $fieldName . " is many-to-one, then the inversed " . + "side " . $targetMetadata->name . "#" . $assoc['inversedBy'] . " has to be one-to-many."; + } else if ($assoc['type'] == ClassMetadata::MANY_TO_MANY && $targetAssoc['type'] !== ClassMetadata::MANY_TO_MANY){ + $ce[] = "If association " . $class->name . "#" . $fieldName . " is many-to-many, then the inversed " . + "side " . $targetMetadata->name . "#" . $assoc['inversedBy'] . " has to be many-to-many as well."; + } } if ($assoc['isOwningSide']) { From 072094f72252beda25dc20ab9597427907db2f92 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 17 Dec 2011 23:38:39 +0100 Subject: [PATCH 67/85] DDC-1368 - Fix tests --- lib/Doctrine/ORM/Tools/SchemaValidator.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/SchemaValidator.php b/lib/Doctrine/ORM/Tools/SchemaValidator.php index f94234487..93a5013be 100644 --- a/lib/Doctrine/ORM/Tools/SchemaValidator.php +++ b/lib/Doctrine/ORM/Tools/SchemaValidator.php @@ -141,13 +141,13 @@ class SchemaValidator // Verify inverse side/owning side match each other $targetAssoc = $targetMetadata->associationMappings[$assoc['inversedBy']]; - if ($assoc['type'] == ClassMetadata::ONE_TO_ONE && $targetAssoc['type'] !== ClassMetadata::ONE_TO_ONE){ + if ($assoc['type'] == ClassMetadataInfo::ONE_TO_ONE && $targetAssoc['type'] !== ClassMetadataInfo::ONE_TO_ONE){ $ce[] = "If association " . $class->name . "#" . $fieldName . " is one-to-one, then the inversed " . "side " . $targetMetadata->name . "#" . $assoc['inversedBy'] . " has to be one-to-one as well."; - } else if ($assoc['type'] == ClassMetadata::MANY_TO_ONE && $targetAssoc['type'] !== ClassMetadata::ONE_TO_MANY){ + } else if ($assoc['type'] == ClassMetadataInfo::MANY_TO_ONE && $targetAssoc['type'] !== ClassMetadataInfo::ONE_TO_MANY){ $ce[] = "If association " . $class->name . "#" . $fieldName . " is many-to-one, then the inversed " . "side " . $targetMetadata->name . "#" . $assoc['inversedBy'] . " has to be one-to-many."; - } else if ($assoc['type'] == ClassMetadata::MANY_TO_MANY && $targetAssoc['type'] !== ClassMetadata::MANY_TO_MANY){ + } else if ($assoc['type'] == ClassMetadataInfo::MANY_TO_MANY && $targetAssoc['type'] !== ClassMetadataInfo::MANY_TO_MANY){ $ce[] = "If association " . $class->name . "#" . $fieldName . " is many-to-many, then the inversed " . "side " . $targetMetadata->name . "#" . $assoc['inversedBy'] . " has to be many-to-many as well."; } From 9cd8f85a8cef8d97c3d9dfe03d45b580998e0032 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 18 Dec 2011 00:32:35 +0100 Subject: [PATCH 68/85] DDC-1456 - Disallow setting id generators on composite identifiers. --- lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php | 4 ++++ lib/Doctrine/ORM/Mapping/MappingException.php | 5 +++++ tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php | 4 +--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 82ff14531..8801344ff 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -371,6 +371,10 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface // second condition is necessary for mapped superclasses in the middle of an inheritance hierachy throw MappingException::noInheritanceOnMappedSuperClass($class->name); } + + if ($class->usesIdGenerator() && $class->isIdentifierComposite) { + throw MappingException::compositeKeyAssignedIdGeneratorRequired($class->name); + } } /** diff --git a/lib/Doctrine/ORM/Mapping/MappingException.php b/lib/Doctrine/ORM/Mapping/MappingException.php index 014714bf8..82b6f138b 100644 --- a/lib/Doctrine/ORM/Mapping/MappingException.php +++ b/lib/Doctrine/ORM/Mapping/MappingException.php @@ -314,4 +314,9 @@ class MappingException extends \Doctrine\ORM\ORMException { return new self("Entity '" . $className . "' has a mapping with invalid fetch mode '" . $annotation . "'"); } + + public static function compositeKeyAssignedIdGeneratorRequired($className) + { + return new self("Entity '". $className . "' has a composite identifier but uses an ID generator other than manually assigning (Identity, Sequence). This is not supported."); + } } diff --git a/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php b/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php index 0fc3bb636..1d68a9bcb 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php @@ -141,13 +141,11 @@ class InvalidEntity2 { /** * @Id @Column - * @GeneratedValue(strategy="AUTO") */ protected $key3; /** * @Id @Column - * @GeneratedValue(strategy="AUTO") */ protected $key4; @@ -155,4 +153,4 @@ class InvalidEntity2 * @ManyToOne(targetEntity="InvalidEntity1") */ protected $assoc; -} \ No newline at end of file +} From 9b877499c778ef01379d8f391ab15f1c19c484ec Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Sun, 18 Dec 2011 12:13:58 +0100 Subject: [PATCH 69/85] Added test case for DDC-1545 --- .../ORM/Functional/Ticket/DDC1545Test.php | 203 ++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1545Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1545Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1545Test.php new file mode 100644 index 000000000..6c028b5ac --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1545Test.php @@ -0,0 +1,203 @@ +useModelSet('cms'); + parent::setUp(); + } + + private function initDb($link) + { + $article = new CmsArticle(); + $article->topic = 'foo'; + $article->text = 'foo'; + + $user = new CmsUser(); + $user->status = 'foo'; + $user->username = 'foo'; + $user->name = 'foo'; + + $user2 = new CmsUser(); + $user2->status = 'bar'; + $user2->username = 'bar'; + $user2->name = 'bar'; + + if ($link) { + $article->user = $user; + } + + $this->_em->persist($article); + $this->_em->persist($user); + $this->_em->persist($user2); + $this->_em->flush(); + $this->_em->clear(); + + $this->articleId = $article->id; + $this->userId = $user->id; + $this->user2Id = $user2->id; + } + + public function testLinkObjects() + { + $this->initDb(false); + + // don't join association + $article = $this->_em->find('Doctrine\Tests\Models\Cms\CmsArticle', $this->articleId); + + $user = $this->_em->find('Doctrine\Tests\Models\Cms\CmsUser', $this->userId); + + $article->user = $user; + + $this->_em->flush(); + $this->_em->clear(); + + $article = $this->_em + ->createQuery('SELECT a, u FROM Doctrine\Tests\Models\Cms\CmsArticle a LEFT JOIN a.user u WHERE a.id = :id') + ->setParameter('id', $this->articleId) + ->getOneOrNullResult(); + + $this->assertNotNull($article->user); + $this->assertEquals($user->id, $article->user->id); + } + + public function testLinkObjectsWithAssociationLoaded() + { + $this->initDb(false); + + // join association + $article = $this->_em + ->createQuery('SELECT a, u FROM Doctrine\Tests\Models\Cms\CmsArticle a LEFT JOIN a.user u WHERE a.id = :id') + ->setParameter('id', $this->articleId) + ->getOneOrNullResult(); + + $user = $this->_em->find('Doctrine\Tests\Models\Cms\CmsUser', $this->userId); + + $article->user = $user; + + $this->_em->flush(); + $this->_em->clear(); + + $article = $this->_em + ->createQuery('SELECT a, u FROM Doctrine\Tests\Models\Cms\CmsArticle a LEFT JOIN a.user u WHERE a.id = :id') + ->setParameter('id', $this->articleId) + ->getOneOrNullResult(); + + $this->assertNotNull($article->user); + $this->assertEquals($user->id, $article->user->id); + } + + public function testUnlinkObjects() + { + $this->initDb(true); + + // don't join association + $article = $this->_em->find('Doctrine\Tests\Models\Cms\CmsArticle', $this->articleId); + + $article->user = null; + + $this->_em->flush(); + $this->_em->clear(); + + $article = $this->_em + ->createQuery('SELECT a, u FROM Doctrine\Tests\Models\Cms\CmsArticle a LEFT JOIN a.user u WHERE a.id = :id') + ->setParameter('id', $this->articleId) + ->getOneOrNullResult(); + + $this->assertNull($article->user); + } + + public function testUnlinkObjectsWithAssociationLoaded() + { + $this->initDb(true); + + // join association + $article = $this->_em + ->createQuery('SELECT a, u FROM Doctrine\Tests\Models\Cms\CmsArticle a LEFT JOIN a.user u WHERE a.id = :id') + ->setParameter('id', $this->articleId) + ->getOneOrNullResult(); + + $article->user = null; + + $this->_em->flush(); + $this->_em->clear(); + + $article = $this->_em + ->createQuery('SELECT a, u FROM Doctrine\Tests\Models\Cms\CmsArticle a LEFT JOIN a.user u WHERE a.id = :id') + ->setParameter('id', $this->articleId) + ->getOneOrNullResult(); + + $this->assertNull($article->user); + } + + public function testChangeLink() + { + $this->initDb(false); + + // don't join association + $article = $this->_em->find('Doctrine\Tests\Models\Cms\CmsArticle', $this->articleId); + + $user2 = $this->_em->find('Doctrine\Tests\Models\Cms\CmsUser', $this->user2Id); + + $article->user = $user2; + + $this->_em->flush(); + $this->_em->clear(); + + $article = $this->_em + ->createQuery('SELECT a, u FROM Doctrine\Tests\Models\Cms\CmsArticle a LEFT JOIN a.user u WHERE a.id = :id') + ->setParameter('id', $this->articleId) + ->getOneOrNullResult(); + + $this->assertNotNull($article->user); + $this->assertEquals($user2->id, $article->user->id); + } + + public function testChangeLinkWithAssociationLoaded() + { + $this->initDb(false); + + // join association + $article = $this->_em + ->createQuery('SELECT a, u FROM Doctrine\Tests\Models\Cms\CmsArticle a LEFT JOIN a.user u WHERE a.id = :id') + ->setParameter('id', $this->articleId) + ->getOneOrNullResult(); + + $user2 = $this->_em->find('Doctrine\Tests\Models\Cms\CmsUser', $this->user2Id); + + $article->user = $user2; + + $this->_em->flush(); + $this->_em->clear(); + + $article = $this->_em + ->createQuery('SELECT a, u FROM Doctrine\Tests\Models\Cms\CmsArticle a LEFT JOIN a.user u WHERE a.id = :id') + ->setParameter('id', $this->articleId) + ->getOneOrNullResult(); + + $this->assertNotNull($article->user); + $this->assertEquals($user2->id, $article->user->id); + } +} \ No newline at end of file From 5160bdc1a8278d79acd0732f1bceaebec1ea8c0c Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 18 Dec 2011 19:58:32 +0100 Subject: [PATCH 70/85] [DDC-551] Fix testcase on pgsql --- tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index d56ddb99b..1a20344a9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -594,7 +594,8 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $conf = $this->_em->getConfiguration(); $conf->addFilter("completed_contract", "\Doctrine\Tests\ORM\Functional\CompletedContractFilter"); $this->_em->getFilters() - ->enable("completed_contract"); + ->enable("completed_contract") + ->setParameter("completed", true, \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::BOOLEAN)->getBindingType()); $this->assertEquals(1, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyFlexUltraContract')->findAll())); $this->assertEquals(1, count($this->_em->createQuery("SELECT cfc FROM Doctrine\Tests\Models\Company\CompanyFlexUltraContract cfc")->getResult())); @@ -610,7 +611,8 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $conf = $this->_em->getConfiguration(); $conf->addFilter("completed_contract", "\Doctrine\Tests\ORM\Functional\CompletedContractFilter"); $this->_em->getFilters() - ->enable("completed_contract"); + ->enable("completed_contract") + ->setParameter("completed", true, \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::BOOLEAN)->getBindingType()); $this->assertEquals(2, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyFlexContract')->findAll())); $this->assertEquals(2, count($this->_em->createQuery("SELECT cfc FROM Doctrine\Tests\Models\Company\CompanyFlexContract cfc")->getResult())); @@ -715,6 +717,6 @@ class CompletedContractFilter extends SQLFilter return ""; } - return $targetTableAlias.'.completed = 1'; + return $targetTableAlias.'.completed = ' . $this->getParameter('completed'); } } From de769c6c3c0b55d4637cab2deba952cd98f5b0e7 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 18 Dec 2011 21:33:38 +0100 Subject: [PATCH 71/85] [DDC-1505] joinColumn "nullable" should be handled true by default --- .../ORM/Persisters/BasicEntityPersister.php | 2 +- .../Functional/OneToOneEagerLoadingTest.php | 23 ++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 6bb3d74da..6845d984a 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -1563,7 +1563,7 @@ class BasicEntityPersister { // if one of the join columns is nullable, return left join foreach ($joinColumns as $joinColumn) { - if (isset($joinColumn['nullable']) && $joinColumn['nullable']) { + if (!isset($joinColumn['nullable']) || $joinColumn['nullable']) { return 'LEFT JOIN'; } } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneEagerLoadingTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneEagerLoadingTest.php index 5fa55036c..8257176ab 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneEagerLoadingTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneEagerLoadingTest.php @@ -143,14 +143,27 @@ class OneToOneEagerLoadingTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testEagerLoadWithNonNullableColumnsGeneratesInnerJoinOnOwningSide() { $waggon = new Waggon(); - $this->_em->persist($waggon); + + // It should have a train + $train = new Train(new TrainOwner("Alexander")); + $train->addWaggon($waggon); + + $this->_em->persist($train); $this->_em->flush(); $this->_em->clear(); $waggon = $this->_em->find(get_class($waggon), $waggon->id); + + // The last query is the eager loading of the owner of the train + $this->assertEquals( + "SELECT t0.id AS id1, t0.name AS name2, t3.id AS id4, t3.driver_id AS driver_id5, t3.owner_id AS owner_id6 FROM TrainOwner t0 LEFT JOIN Train t3 ON t3.owner_id = t0.id WHERE t0.id IN (?)", + $this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery]['sql'] + ); + + // The one before is the fetching of the waggon and train $this->assertEquals( "SELECT t0.id AS id1, t0.train_id AS train_id2, t3.id AS id4, t3.driver_id AS driver_id5, t3.owner_id AS owner_id6 FROM Waggon t0 INNER JOIN Train t3 ON t0.train_id = t3.id WHERE t0.id = ?", - $this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery]['sql'] + $this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery - 1]['sql'] ); } @@ -189,6 +202,7 @@ class Train /** * Owning side * @OneToOne(targetEntity="TrainOwner", inversedBy="train", fetch="EAGER", cascade={"persist"}) + * @JoinColumn(nullable=false) */ public $owner; /** @@ -280,7 +294,10 @@ class Waggon { /** @id @generatedValue @column(type="integer") */ public $id; - /** @ManyToOne(targetEntity="Train", inversedBy="waggons", fetch="EAGER") */ + /** + * @ManyToOne(targetEntity="Train", inversedBy="waggons", fetch="EAGER") + * @JoinColumn(nullable=false) + */ public $train; public function setTrain($train) From a8478d5766e2cc4185612af680b7f6bcd83af61e Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Mon, 19 Dec 2011 01:39:48 -0500 Subject: [PATCH 72/85] Fixed issue with fetched association not being considered during changeSet calculation. Fixes DDC-1545. --- lib/Doctrine/ORM/Query/SqlWalker.php | 6 +---- lib/Doctrine/ORM/UnitOfWork.php | 27 +++++++++++-------- .../Doctrine/Tests/Models/CMS/CmsArticle.php | 2 +- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 0bc437a98..753669f92 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -978,17 +978,13 @@ class SqlWalker implements TreeWalker */ public function walkCoalesceExpression($coalesceExpression) { - $sql = 'COALESCE('; - $scalarExpressions = array(); foreach ($coalesceExpression->scalarExpressions as $scalarExpression) { $scalarExpressions[] = $this->walkSimpleArithmeticExpression($scalarExpression); } - $sql .= implode(', ', $scalarExpressions) . ')'; - - return $sql; + return 'COALESCE(' . implode(', ', $scalarExpressions) . ')'; } /** diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index a026d001a..1db6caa0c 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -705,7 +705,6 @@ class UnitOfWork implements PropertyChangedListener foreach ($unwrappedValue as $key => $entry) { $state = $this->getEntityState($entry, self::STATE_NEW); - $oid = spl_object_hash($entry); switch ($state) { case self::STATE_NEW: @@ -2293,13 +2292,14 @@ class UnitOfWork implements PropertyChangedListener $id = array($class->identifier[0] => $idHash); } + $overrideLocalValues = true; + if (isset($this->identityMap[$class->rootEntityName][$idHash])) { $entity = $this->identityMap[$class->rootEntityName][$idHash]; $oid = spl_object_hash($entity); if ($entity instanceof Proxy && ! $entity->__isInitialized__) { $entity->__isInitialized__ = true; - $overrideLocalValues = true; if ($entity instanceof NotifyPropertyChanged) { $entity->addPropertyChangedListener($this); @@ -2308,7 +2308,7 @@ class UnitOfWork implements PropertyChangedListener $overrideLocalValues = isset($hints[Query::HINT_REFRESH]); // If only a specific entity is set to refresh, check that it's the one - if(isset($hints[Query::HINT_REFRESH_ENTITY])) { + if (isset($hints[Query::HINT_REFRESH_ENTITY])) { $overrideLocalValues = $hints[Query::HINT_REFRESH_ENTITY] === $entity; // inject ObjectManager into just loaded proxies. @@ -2333,8 +2333,6 @@ class UnitOfWork implements PropertyChangedListener if ($entity instanceof NotifyPropertyChanged) { $entity->addPropertyChangedListener($this); } - - $overrideLocalValues = true; } if ( ! $overrideLocalValues) { @@ -2362,6 +2360,10 @@ class UnitOfWork implements PropertyChangedListener foreach ($class->associationMappings as $field => $assoc) { // Check if the association is not among the fetch-joined associations already. if (isset($hints['fetchAlias']) && isset($hints['fetched'][$hints['fetchAlias']][$field])) { + // DDC-1545: Fetched associations must have original entity data set. + // Define NULL value right now, since next iteration may fill it with actual value. + $this->originalEntityData[$oid][$field] = null; + continue; } @@ -2382,12 +2384,15 @@ class UnitOfWork implements PropertyChangedListener foreach ($assoc['targetToSourceKeyColumns'] as $targetColumn => $srcColumn) { $joinColumnValue = isset($data[$srcColumn]) ? $data[$srcColumn] : null; - if ($joinColumnValue !== null) { - if ($targetClass->containsForeignIdentifier) { - $associatedId[$targetClass->getFieldForColumn($targetColumn)] = $joinColumnValue; - } else { - $associatedId[$targetClass->fieldNames[$targetColumn]] = $joinColumnValue; - } + // Skip is join column value is null + if ($joinColumnValue === null) { + continue; + } + + if ($targetClass->containsForeignIdentifier) { + $associatedId[$targetClass->getFieldForColumn($targetColumn)] = $joinColumnValue; + } else { + $associatedId[$targetClass->fieldNames[$targetColumn]] = $joinColumnValue; } } diff --git a/tests/Doctrine/Tests/Models/CMS/CmsArticle.php b/tests/Doctrine/Tests/Models/CMS/CmsArticle.php index 5cc516735..266cbc662 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsArticle.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsArticle.php @@ -36,7 +36,7 @@ class CmsArticle * @Version @column(type="integer") */ public $version; - + public function setAuthor(CmsUser $author) { $this->user = $author; } From bd07f8d3dd303891fa9c662c46fb702a8cac6bf9 Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 19 Dec 2011 08:43:42 +0100 Subject: [PATCH 73/85] [DDC-551] Add type inference to SQLFilter::setParameter() + cleaned tests --- lib/Doctrine/ORM/Query/Filter/SQLFilter.php | 15 +++-- .../Tests/ORM/Functional/SQLFilterTest.php | 61 +++++++++++++------ 2 files changed, 55 insertions(+), 21 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php index 1250b16d7..a87dd841e 100644 --- a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php +++ b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php @@ -19,8 +19,9 @@ namespace Doctrine\ORM\Query\Filter; -use Doctrine\ORM\Mapping\ClassMetaData; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManager, + Doctrine\ORM\Mapping\ClassMetaData, + Doctrine\ORM\Query\ParameterTypeInferer; /** * The base class that user defined filters should extend. @@ -60,12 +61,18 @@ abstract class SQLFilter * * @param string $name Name of the parameter. * @param string $value Value of the parameter. - * @param string $type Type of the parameter. + * @param string $type The parameter type. If specified, the given value will be run through + * the type conversion of this type. This is usually not needed for + * strings and numeric types. * * @return SQLFilter The current SQL filter. */ - final public function setParameter($name, $value, $type) + final public function setParameter($name, $value, $type = null) { + if (null === $type) { + $type = ParameterTypeInferer::inferType($value); + } + $this->parameters[$name] = array('value' => $value, 'type' => $type); // Keep the parameters sorted for the hash diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index 1a20344a9..ebb2c66cc 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\DBAL\Types\Type; use Doctrine\ORM\Query\Filter\SQLFilter; use Doctrine\ORM\Mapping\ClassMetaData; use Doctrine\Common\Cache\ArrayCache; @@ -213,7 +214,33 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $filter = new MyLocaleFilter($em); - $filter->setParameter('locale', 'en', \Doctrine\DBAL\Types\Type::STRING); + $filter->setParameter('locale', 'en', Type::STRING); + + $this->assertEquals("'en'", $filter->getParameter('locale')); + } + + public function testSQLFilterSetParameterInfersType() + { + // Setup mock connection + $conn = $this->getMockConnection(); + $conn->expects($this->once()) + ->method('quote') + ->with($this->equalTo('en')) + ->will($this->returnValue("'en'")); + + $em = $this->getMockEntityManager($conn); + $em->expects($this->once()) + ->method('getConnection') + ->will($this->returnValue($conn)); + + $filterCollection = $this->addMockFilterCollection($em); + $filterCollection + ->expects($this->once()) + ->method('setFiltersStateDirty'); + + $filter = new MyLocaleFilter($em); + + $filter->setParameter('locale', 'en'); $this->assertEquals("'en'", $filter->getParameter('locale')); } @@ -243,16 +270,16 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $filterCollection = $this->addMockFilterCollection($em); $filter = new MyLocaleFilter($em); - $filter->setParameter('locale', 'en', \Doctrine\DBAL\Types\Type::STRING); - $filter->setParameter('foo', 'bar', \Doctrine\DBAL\Types\Type::STRING); + $filter->setParameter('locale', 'en', Type::STRING); + $filter->setParameter('foo', 'bar', Type::STRING); $filter2 = new MyLocaleFilter($em); - $filter2->setParameter('foo', 'bar', \Doctrine\DBAL\Types\Type::STRING); - $filter2->setParameter('locale', 'en', \Doctrine\DBAL\Types\Type::STRING); + $filter2->setParameter('foo', 'bar', Type::STRING); + $filter2->setParameter('locale', 'en', Type::STRING); $parameters = array( - 'foo' => array('value' => 'bar', 'type' => \Doctrine\DBAL\Types\Type::STRING), - 'locale' => array('value' => 'en', 'type' => \Doctrine\DBAL\Types\Type::STRING), + 'foo' => array('value' => 'bar', 'type' => Type::STRING), + 'locale' => array('value' => 'en', 'type' => Type::STRING), ); $this->assertEquals(serialize($parameters), ''.$filter); @@ -292,7 +319,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $conf = $this->_em->getConfiguration(); $conf->addFilter("country", "\Doctrine\Tests\ORM\Functional\CMSCountryFilter"); $this->_em->getFilters()->enable("country") - ->setParameter("country", "en", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); + ->setParameter("country", "en", Type::STRING); $this->assertNotEquals($firstSQLQuery, $query->getSQL()); } @@ -309,7 +336,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $conf = $this->_em->getConfiguration(); $conf->addFilter("country", "\Doctrine\Tests\ORM\Functional\CMSCountryFilter"); - $this->_em->getFilters()->enable("country")->setParameter("country", "Germany", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); + $this->_em->getFilters()->enable("country")->setParameter("country", "Germany", Type::STRING); // We get one user after enabling the filter $this->assertEquals(1, count($query->getResult())); @@ -325,7 +352,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $conf = $this->_em->getConfiguration(); $conf->addFilter("group_prefix", "\Doctrine\Tests\ORM\Functional\CMSGroupPrefixFilter"); - $this->_em->getFilters()->enable("group_prefix")->setParameter("prefix", "bar_%", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); + $this->_em->getFilters()->enable("group_prefix")->setParameter("prefix", "bar_%", Type::STRING); // We get one user after enabling the filter $this->assertEquals(1, count($query->getResult())); @@ -342,7 +369,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $conf = $this->_em->getConfiguration(); $conf->addFilter("group_prefix", "\Doctrine\Tests\ORM\Functional\CMSGroupPrefixFilter"); - $this->_em->getFilters()->enable("group_prefix")->setParameter("prefix", "bar_%", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); + $this->_em->getFilters()->enable("group_prefix")->setParameter("prefix", "bar_%", Type::STRING); // We get one user after enabling the filter $this->assertEquals(1, count($query->getResult())); @@ -361,7 +388,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase { $conf = $this->_em->getConfiguration(); $conf->addFilter("article_topic", "\Doctrine\Tests\ORM\Functional\CMSArticleTopicFilter"); - $this->_em->getFilters()->enable("article_topic")->setParameter("topic", "Test1", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); + $this->_em->getFilters()->enable("article_topic")->setParameter("topic", "Test1", Type::STRING); } public function testOneToMany_ExtraLazyCountWithFilter() @@ -408,7 +435,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase { $conf = $this->_em->getConfiguration(); $conf->addFilter("group_prefix", "\Doctrine\Tests\ORM\Functional\CMSGroupPrefixFilter"); - $this->_em->getFilters()->enable("group_prefix")->setParameter("prefix", "foo%", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); + $this->_em->getFilters()->enable("group_prefix")->setParameter("prefix", "foo%", Type::STRING); } public function testManyToMany_ExtraLazyCountWithFilter() @@ -529,7 +556,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $conf->addFilter("person_name", "\Doctrine\Tests\ORM\Functional\CompanyPersonNameFilter"); $this->_em->getFilters() ->enable("person_name") - ->setParameter("name", "Guilh%", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); + ->setParameter("name", "Guilh%", Type::STRING); $managers = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll(); $this->assertEquals(1, count($managers)); @@ -549,7 +576,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $conf->addFilter("person_name", "\Doctrine\Tests\ORM\Functional\CompanyPersonNameFilter"); $this->_em->getFilters() ->enable("person_name") - ->setParameter("name", "Guilh%", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); + ->setParameter("name", "Guilh%", Type::STRING); $persons = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyPerson')->findAll(); $this->assertEquals(1, count($persons)); @@ -595,7 +622,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $conf->addFilter("completed_contract", "\Doctrine\Tests\ORM\Functional\CompletedContractFilter"); $this->_em->getFilters() ->enable("completed_contract") - ->setParameter("completed", true, \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::BOOLEAN)->getBindingType()); + ->setParameter("completed", true, Type::BOOLEAN); $this->assertEquals(1, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyFlexUltraContract')->findAll())); $this->assertEquals(1, count($this->_em->createQuery("SELECT cfc FROM Doctrine\Tests\Models\Company\CompanyFlexUltraContract cfc")->getResult())); @@ -612,7 +639,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $conf->addFilter("completed_contract", "\Doctrine\Tests\ORM\Functional\CompletedContractFilter"); $this->_em->getFilters() ->enable("completed_contract") - ->setParameter("completed", true, \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::BOOLEAN)->getBindingType()); + ->setParameter("completed", true, Type::BOOLEAN); $this->assertEquals(2, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyFlexContract')->findAll())); $this->assertEquals(2, count($this->_em->createQuery("SELECT cfc FROM Doctrine\Tests\Models\Company\CompanyFlexContract cfc")->getResult())); From 8c6c49a6ee33e4d6932149df753e8baea11eb634 Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 19 Dec 2011 09:55:49 +0100 Subject: [PATCH 74/85] Fixed testsuite --- .../Tests/ORM/Functional/SQLFilterTest.php | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index ebb2c66cc..98b3fafd4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -2,7 +2,7 @@ namespace Doctrine\Tests\ORM\Functional; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\ORM\Query\Filter\SQLFilter; use Doctrine\ORM\Mapping\ClassMetaData; use Doctrine\Common\Cache\ArrayCache; @@ -214,7 +214,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $filter = new MyLocaleFilter($em); - $filter->setParameter('locale', 'en', Type::STRING); + $filter->setParameter('locale', 'en', DBALType::STRING); $this->assertEquals("'en'", $filter->getParameter('locale')); } @@ -270,16 +270,16 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $filterCollection = $this->addMockFilterCollection($em); $filter = new MyLocaleFilter($em); - $filter->setParameter('locale', 'en', Type::STRING); - $filter->setParameter('foo', 'bar', Type::STRING); + $filter->setParameter('locale', 'en', DBALType::STRING); + $filter->setParameter('foo', 'bar', DBALType::STRING); $filter2 = new MyLocaleFilter($em); - $filter2->setParameter('foo', 'bar', Type::STRING); - $filter2->setParameter('locale', 'en', Type::STRING); + $filter2->setParameter('foo', 'bar', DBALType::STRING); + $filter2->setParameter('locale', 'en', DBALType::STRING); $parameters = array( - 'foo' => array('value' => 'bar', 'type' => Type::STRING), - 'locale' => array('value' => 'en', 'type' => Type::STRING), + 'foo' => array('value' => 'bar', 'type' => DBALType::STRING), + 'locale' => array('value' => 'en', 'type' => DBALType::STRING), ); $this->assertEquals(serialize($parameters), ''.$filter); @@ -319,7 +319,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $conf = $this->_em->getConfiguration(); $conf->addFilter("country", "\Doctrine\Tests\ORM\Functional\CMSCountryFilter"); $this->_em->getFilters()->enable("country") - ->setParameter("country", "en", Type::STRING); + ->setParameter("country", "en", DBALType::STRING); $this->assertNotEquals($firstSQLQuery, $query->getSQL()); } @@ -336,7 +336,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $conf = $this->_em->getConfiguration(); $conf->addFilter("country", "\Doctrine\Tests\ORM\Functional\CMSCountryFilter"); - $this->_em->getFilters()->enable("country")->setParameter("country", "Germany", Type::STRING); + $this->_em->getFilters()->enable("country")->setParameter("country", "Germany", DBALType::STRING); // We get one user after enabling the filter $this->assertEquals(1, count($query->getResult())); @@ -352,7 +352,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $conf = $this->_em->getConfiguration(); $conf->addFilter("group_prefix", "\Doctrine\Tests\ORM\Functional\CMSGroupPrefixFilter"); - $this->_em->getFilters()->enable("group_prefix")->setParameter("prefix", "bar_%", Type::STRING); + $this->_em->getFilters()->enable("group_prefix")->setParameter("prefix", "bar_%", DBALType::STRING); // We get one user after enabling the filter $this->assertEquals(1, count($query->getResult())); @@ -369,7 +369,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $conf = $this->_em->getConfiguration(); $conf->addFilter("group_prefix", "\Doctrine\Tests\ORM\Functional\CMSGroupPrefixFilter"); - $this->_em->getFilters()->enable("group_prefix")->setParameter("prefix", "bar_%", Type::STRING); + $this->_em->getFilters()->enable("group_prefix")->setParameter("prefix", "bar_%", DBALType::STRING); // We get one user after enabling the filter $this->assertEquals(1, count($query->getResult())); @@ -388,7 +388,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase { $conf = $this->_em->getConfiguration(); $conf->addFilter("article_topic", "\Doctrine\Tests\ORM\Functional\CMSArticleTopicFilter"); - $this->_em->getFilters()->enable("article_topic")->setParameter("topic", "Test1", Type::STRING); + $this->_em->getFilters()->enable("article_topic")->setParameter("topic", "Test1", DBALType::STRING); } public function testOneToMany_ExtraLazyCountWithFilter() @@ -435,7 +435,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase { $conf = $this->_em->getConfiguration(); $conf->addFilter("group_prefix", "\Doctrine\Tests\ORM\Functional\CMSGroupPrefixFilter"); - $this->_em->getFilters()->enable("group_prefix")->setParameter("prefix", "foo%", Type::STRING); + $this->_em->getFilters()->enable("group_prefix")->setParameter("prefix", "foo%", DBALType::STRING); } public function testManyToMany_ExtraLazyCountWithFilter() @@ -556,7 +556,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $conf->addFilter("person_name", "\Doctrine\Tests\ORM\Functional\CompanyPersonNameFilter"); $this->_em->getFilters() ->enable("person_name") - ->setParameter("name", "Guilh%", Type::STRING); + ->setParameter("name", "Guilh%", DBALType::STRING); $managers = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll(); $this->assertEquals(1, count($managers)); @@ -576,7 +576,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $conf->addFilter("person_name", "\Doctrine\Tests\ORM\Functional\CompanyPersonNameFilter"); $this->_em->getFilters() ->enable("person_name") - ->setParameter("name", "Guilh%", Type::STRING); + ->setParameter("name", "Guilh%", DBALType::STRING); $persons = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyPerson')->findAll(); $this->assertEquals(1, count($persons)); @@ -622,7 +622,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $conf->addFilter("completed_contract", "\Doctrine\Tests\ORM\Functional\CompletedContractFilter"); $this->_em->getFilters() ->enable("completed_contract") - ->setParameter("completed", true, Type::BOOLEAN); + ->setParameter("completed", true, DBALType::BOOLEAN); $this->assertEquals(1, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyFlexUltraContract')->findAll())); $this->assertEquals(1, count($this->_em->createQuery("SELECT cfc FROM Doctrine\Tests\Models\Company\CompanyFlexUltraContract cfc")->getResult())); @@ -639,7 +639,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $conf->addFilter("completed_contract", "\Doctrine\Tests\ORM\Functional\CompletedContractFilter"); $this->_em->getFilters() ->enable("completed_contract") - ->setParameter("completed", true, Type::BOOLEAN); + ->setParameter("completed", true, DBALType::BOOLEAN); $this->assertEquals(2, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyFlexContract')->findAll())); $this->assertEquals(2, count($this->_em->createQuery("SELECT cfc FROM Doctrine\Tests\Models\Company\CompanyFlexContract cfc")->getResult())); From 40800bd3cdbb0e932ae71bf050d158e965d8d808 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Mon, 19 Dec 2011 10:10:56 +0100 Subject: [PATCH 75/85] DDC-1530 - Validate field types in SchemaValidator --- lib/Doctrine/ORM/Tools/SchemaValidator.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/Doctrine/ORM/Tools/SchemaValidator.php b/lib/Doctrine/ORM/Tools/SchemaValidator.php index 93a5013be..f6bcadb72 100644 --- a/lib/Doctrine/ORM/Tools/SchemaValidator.php +++ b/lib/Doctrine/ORM/Tools/SchemaValidator.php @@ -21,6 +21,7 @@ namespace Doctrine\ORM\Tools; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\DBAL\Types\Type; /** * Performs strict validation of the mapping schema @@ -87,6 +88,12 @@ class SchemaValidator $ce = array(); $cmf = $this->em->getMetadataFactory(); + foreach ($class->fieldMappings as $fieldName => $mapping) { + if (!Type::hasType($mapping['type'])) { + $ce[] = "The field '" . $class->name . "#" . $fieldName."' uses a non-existant type '" . $mapping['type'] . "'."; + } + } + foreach ($class->associationMappings AS $fieldName => $assoc) { if (!$cmf->hasMetadataFor($assoc['targetEntity'])) { $ce[] = "The target entity '" . $assoc['targetEntity'] . "' specified on " . $class->name . '#' . $fieldName . ' is unknown.'; From e035fe7949851a2162794467f7d236368f6d5ee7 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Mon, 19 Dec 2011 11:20:37 +0100 Subject: [PATCH 76/85] Fixed class name of test for DDC-1545 --- tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1545Test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1545Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1545Test.php index 6c028b5ac..e7b55eb1f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1545Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1545Test.php @@ -13,9 +13,9 @@ use Doctrine\Tests\Models\CMS\CmsUser; require_once __DIR__ . '/../../../TestInit.php'; /** - * @group DDC-1040 + * @group DDC-1545 */ -class ATest extends \Doctrine\Tests\OrmFunctionalTestCase +class DDC1545Test extends \Doctrine\Tests\OrmFunctionalTestCase { private $articleId; From b1b10042d2762501b90c9df3d24458da8bbe8d83 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Mon, 19 Dec 2011 16:31:26 +0100 Subject: [PATCH 77/85] Revert "Fixed issue with fetched association not being considered during changeSet calculation. Fixes DDC-1545." This reverts commit a8478d5766e2cc4185612af680b7f6bcd83af61e. --- lib/Doctrine/ORM/Query/SqlWalker.php | 6 ++++- lib/Doctrine/ORM/UnitOfWork.php | 27 ++++++++----------- .../Doctrine/Tests/Models/CMS/CmsArticle.php | 2 +- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 753669f92..0bc437a98 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -978,13 +978,17 @@ class SqlWalker implements TreeWalker */ public function walkCoalesceExpression($coalesceExpression) { + $sql = 'COALESCE('; + $scalarExpressions = array(); foreach ($coalesceExpression->scalarExpressions as $scalarExpression) { $scalarExpressions[] = $this->walkSimpleArithmeticExpression($scalarExpression); } - return 'COALESCE(' . implode(', ', $scalarExpressions) . ')'; + $sql .= implode(', ', $scalarExpressions) . ')'; + + return $sql; } /** diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 1db6caa0c..a026d001a 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -705,6 +705,7 @@ class UnitOfWork implements PropertyChangedListener foreach ($unwrappedValue as $key => $entry) { $state = $this->getEntityState($entry, self::STATE_NEW); + $oid = spl_object_hash($entry); switch ($state) { case self::STATE_NEW: @@ -2292,14 +2293,13 @@ class UnitOfWork implements PropertyChangedListener $id = array($class->identifier[0] => $idHash); } - $overrideLocalValues = true; - if (isset($this->identityMap[$class->rootEntityName][$idHash])) { $entity = $this->identityMap[$class->rootEntityName][$idHash]; $oid = spl_object_hash($entity); if ($entity instanceof Proxy && ! $entity->__isInitialized__) { $entity->__isInitialized__ = true; + $overrideLocalValues = true; if ($entity instanceof NotifyPropertyChanged) { $entity->addPropertyChangedListener($this); @@ -2308,7 +2308,7 @@ class UnitOfWork implements PropertyChangedListener $overrideLocalValues = isset($hints[Query::HINT_REFRESH]); // If only a specific entity is set to refresh, check that it's the one - if (isset($hints[Query::HINT_REFRESH_ENTITY])) { + if(isset($hints[Query::HINT_REFRESH_ENTITY])) { $overrideLocalValues = $hints[Query::HINT_REFRESH_ENTITY] === $entity; // inject ObjectManager into just loaded proxies. @@ -2333,6 +2333,8 @@ class UnitOfWork implements PropertyChangedListener if ($entity instanceof NotifyPropertyChanged) { $entity->addPropertyChangedListener($this); } + + $overrideLocalValues = true; } if ( ! $overrideLocalValues) { @@ -2360,10 +2362,6 @@ class UnitOfWork implements PropertyChangedListener foreach ($class->associationMappings as $field => $assoc) { // Check if the association is not among the fetch-joined associations already. if (isset($hints['fetchAlias']) && isset($hints['fetched'][$hints['fetchAlias']][$field])) { - // DDC-1545: Fetched associations must have original entity data set. - // Define NULL value right now, since next iteration may fill it with actual value. - $this->originalEntityData[$oid][$field] = null; - continue; } @@ -2384,15 +2382,12 @@ class UnitOfWork implements PropertyChangedListener foreach ($assoc['targetToSourceKeyColumns'] as $targetColumn => $srcColumn) { $joinColumnValue = isset($data[$srcColumn]) ? $data[$srcColumn] : null; - // Skip is join column value is null - if ($joinColumnValue === null) { - continue; - } - - if ($targetClass->containsForeignIdentifier) { - $associatedId[$targetClass->getFieldForColumn($targetColumn)] = $joinColumnValue; - } else { - $associatedId[$targetClass->fieldNames[$targetColumn]] = $joinColumnValue; + if ($joinColumnValue !== null) { + if ($targetClass->containsForeignIdentifier) { + $associatedId[$targetClass->getFieldForColumn($targetColumn)] = $joinColumnValue; + } else { + $associatedId[$targetClass->fieldNames[$targetColumn]] = $joinColumnValue; + } } } diff --git a/tests/Doctrine/Tests/Models/CMS/CmsArticle.php b/tests/Doctrine/Tests/Models/CMS/CmsArticle.php index 266cbc662..5cc516735 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsArticle.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsArticle.php @@ -36,7 +36,7 @@ class CmsArticle * @Version @column(type="integer") */ public $version; - + public function setAuthor(CmsUser $author) { $this->user = $author; } From 68663fac4b5619643b8a140d6bbe7031e4fa2ad5 Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Mon, 19 Dec 2011 10:55:29 -0500 Subject: [PATCH 78/85] Fixed issue when one to one badly populated when containing null values. Fixed DDC-1548. --- .../Internal/Hydration/AbstractHydrator.php | 2 +- .../ORM/Functional/Ticket/DDC1548Test.php | 80 +++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1548Test.php diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index 0a6ab8657..a0a71922a 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -243,7 +243,7 @@ abstract class AbstractHydrator } if (isset($cache[$key]['isMetaColumn'])) { - if ( ! isset($rowData[$dqlAlias][$cache[$key]['fieldName']]) || $value !== null) { + if ( ! isset($rowData[$dqlAlias][$cache[$key]['fieldName']]) && $value !== null) { $rowData[$dqlAlias][$cache[$key]['fieldName']] = $value; if ($cache[$key]['isIdentifier']) { $nonemptyComponents[$dqlAlias] = true; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1548Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1548Test.php new file mode 100644 index 000000000..0baeca2f7 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1548Test.php @@ -0,0 +1,80 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1548E1'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1548E2'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1548Rel'), + )); + } + + public function testIssue() + { + $rel = new DDC1548Rel(); + $this->_em->persist($rel); + $this->_em->flush(); + + $e1 = new DDC1548E1(); + $e1->rel = $rel; + $this->_em->persist($e1); + $this->_em->flush(); + $this->_em->clear(); + + $obt = $this->_em->find(__NAMESPACE__ . '\DDC1548Rel', $rel->id); + + $this->assertNull($obt->e2); + } +} + +/** + * @Entity + */ +class DDC1548E1 +{ + /** + * @Id + * @OneToOne(targetEntity="DDC1548Rel", inversedBy="e1") + */ + public $rel; +} +/** + * @Entity + */ +class DDC1548E2 +{ + /** + * @Id + * @OneToOne(targetEntity="DDC1548Rel", inversedBy="e2") + */ + public $rel; +} + +/** + * @Entity + */ +class DDC1548Rel +{ + /** + * @Id @GeneratedValue + * @Column(type="integer") + */ + public $id; + + /** + * @OneToOne(targetEntity="DDC1548E1", mappedBy="rel") + */ + public $e1; + /** + * @OneToOne(targetEntity="DDC1548E2", mappedBy="rel") + */ + public $e2; +} \ No newline at end of file From bf32125badc78b2749e1d47470bc2df2d4adec7a Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Mon, 19 Dec 2011 17:55:19 +0100 Subject: [PATCH 79/85] DDC-1545 - Fix issue with changing values from null to something new. This issue was introduced by a side-effect in 2.1.3 with d9f9228d95c5ab2a200b3e2d2b358c598267afb1. In this commit read-only objects where prevented to be updated. This lead to an invalid check not being performed in UnitOfWork#computeChangeSet which was present before where an association that was null would be injected into the originalEntityData using the UnitOfWork#setOriginalEntityProperty() method in the AbstractHydrator. This commit now explicitly sets this field to null using the same API so that is present during UnitOfWork#computeChangeSet. --- lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index f7de28538..1935e901d 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -443,6 +443,8 @@ class ObjectHydrator extends AbstractHydrator } // Update result pointer $this->_resultPointers[$dqlAlias] = $element; + } else { + $this->_uow->setOriginalEntityProperty($oid, $relationField, null); } // else leave $reflFieldValue null for single-valued associations } else { From b545525e133ffc799edbf0b39e0969a25dea1e34 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Mon, 19 Dec 2011 18:03:53 +0100 Subject: [PATCH 80/85] Update ORM to Doctrine Common master --- lib/Doctrine/ORM/Mapping/ClassMetadata.php | 3 ++- lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php | 3 +-- lib/vendor/doctrine-common | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadata.php b/lib/Doctrine/ORM/Mapping/ClassMetadata.php index 808e58552..4e31f5578 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadata.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadata.php @@ -20,6 +20,7 @@ namespace Doctrine\ORM\Mapping; use ReflectionClass, ReflectionProperty; +use Doctrine\Common\Persistence\Mapping\ClassMetadata AS IClassMetadata; /** * A ClassMetadata instance holds all the object-relational mapping metadata @@ -39,7 +40,7 @@ use ReflectionClass, ReflectionProperty; * @author Jonathan H. Wage * @since 2.0 */ -class ClassMetadata extends ClassMetadataInfo +class ClassMetadata extends ClassMetadataInfo implements IClassMetadata { /** * The ReflectionProperty instances of the mapped class. diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index d845e6f59..6fbf8b3c6 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -19,7 +19,6 @@ namespace Doctrine\ORM\Mapping; -use Doctrine\Common\Persistence\Mapping\ClassMetadata; use Doctrine\DBAL\Types\Type; use ReflectionClass; @@ -41,7 +40,7 @@ use ReflectionClass; * @author Jonathan H. Wage * @since 2.0 */ -class ClassMetadataInfo implements ClassMetadata +class ClassMetadataInfo { /* The inheritance mapping types */ /** diff --git a/lib/vendor/doctrine-common b/lib/vendor/doctrine-common index 9c880cf9a..ef7382756 160000 --- a/lib/vendor/doctrine-common +++ b/lib/vendor/doctrine-common @@ -1 +1 @@ -Subproject commit 9c880cf9ae2c14102568520b5ee885b03bda93e4 +Subproject commit ef7382756672d99c92b746aea56f10295edfc96b From 568698e3215d1e5981c692f8ed045cc2c0b2c1f9 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Mon, 19 Dec 2011 19:16:26 +0100 Subject: [PATCH 81/85] Add dependency to doctrine-build-common and refactor build.xml and build.properties --- .gitignore | 1 - .gitmodules | 3 + build.properties | 11 ++ build.xml | 222 +++---------------------------- lib/vendor/doctrine-build-common | 1 + 5 files changed, 33 insertions(+), 205 deletions(-) create mode 100644 build.properties create mode 160000 lib/vendor/doctrine-build-common diff --git a/.gitignore b/.gitignore index 329249d72..a91841777 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -build.properties build/ logs/ reports/ diff --git a/.gitmodules b/.gitmodules index ef840b0b9..21a1fb2fa 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "lib/vendor/Symfony/Component/Yaml"] path = lib/vendor/Symfony/Component/Yaml url = git://github.com/symfony/Yaml.git +[submodule "lib/vendor/doctrine-build-common"] + path = lib/vendor/doctrine-build-common + url = https://github.com/doctrine/doctrine-build-common.git diff --git a/build.properties b/build.properties new file mode 100644 index 000000000..6b45548c0 --- /dev/null +++ b/build.properties @@ -0,0 +1,11 @@ +# Project Name +project.name=DoctrineORM + +# Dependency minimum versions +dependencies.common=2.1.0 +dependencies.dbal=2.1.0 +dependencies.sfconsole=2.0.0 + +# Version class and file +project.version_class = Doctrine\ORM\Version +project.version_file = lib/Doctrine/ORM/Version.php diff --git a/build.xml b/build.xml index b36457f3d..6bfe35a6d 100644 --- a/build.xml +++ b/build.xml @@ -1,11 +1,7 @@ - - - - + + @@ -14,6 +10,8 @@ --> + + + - - - - - - - - - - - - - - - - - - - - - - - - - + + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + DoctrineORM Doctrine Object Relational Mapper pear.doctrine-project.org @@ -172,129 +86,29 @@ LGPL - - + + - - - + + script Doctrine/Common/ Doctrine/DBAL/ - Symfony/Component/Yaml/ + Symfony/Component/Yaml/ Symfony/Component/Console/ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - DoctrineSymfonyConsole - Symfony Console Component - pear.doctrine-project.org - A command line interface tool from the Symfony project. Packaged for shipping with Doctrine projects using ORM version numbers. - - NewBSD License - - - - - - - - - bin/ - Doctrine/Common/ - Doctrine/DBAL/ - Doctrine/ORM/ - Symfony/Component/Yaml/ - - - - - - DoctrineSymfonyYaml - Symfony Yaml Component - pear.doctrine-project.org - A YAML Parser from the Symfony project. Packaged for shipping with Doctrine projects using ORM version numbers. - - NewBSD License - - - - - - - - - bin/ - Doctrine/Common/ - Doctrine/DBAL/ - Doctrine/ORM/ - Symfony/Component/Console/ - - - - - - - - diff --git a/lib/vendor/doctrine-build-common b/lib/vendor/doctrine-build-common new file mode 160000 index 000000000..5c43f26f8 --- /dev/null +++ b/lib/vendor/doctrine-build-common @@ -0,0 +1 @@ +Subproject commit 5c43f26f82bde0234c0645e349fb12a48bd39c7f From 5c89d7ffcb0e89115ae6e3ad90ceb202f311c80f Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Sun, 18 Dec 2011 14:56:57 -0200 Subject: [PATCH 82/85] support for bit comparison --- .../Query/AST/Functions/BitAndFunction.php | 63 +++++++++++++++++++ .../ORM/Query/AST/Functions/BitOrFunction.php | 63 +++++++++++++++++++ lib/Doctrine/ORM/Query/Parser.php | 2 + .../ORM/Functional/QueryDqlFunctionTest.php | 48 ++++++++++++++ .../ORM/Query/SelectSqlGenerationTest.php | 23 +++++++ 5 files changed, 199 insertions(+) create mode 100644 lib/Doctrine/ORM/Query/AST/Functions/BitAndFunction.php create mode 100644 lib/Doctrine/ORM/Query/AST/Functions/BitOrFunction.php diff --git a/lib/Doctrine/ORM/Query/AST/Functions/BitAndFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/BitAndFunction.php new file mode 100644 index 000000000..1ee823337 --- /dev/null +++ b/lib/Doctrine/ORM/Query/AST/Functions/BitAndFunction.php @@ -0,0 +1,63 @@ +. + */ + +namespace Doctrine\ORM\Query\AST\Functions; + +use Doctrine\ORM\Query\Lexer; + +/** + * "BIT_AND" "(" ArithmeticPrimary "," ArithmeticPrimary ")" + * + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.doctrine-project.org + * @since 2.2 + * @author Fabio B. Silva + */ +class BitAndFunction extends FunctionNode +{ + public $firstArithmetic; + public $secondArithmetic; + + /** + * @override + */ + public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) + { + $platform = $sqlWalker->getConnection()->getDatabasePlatform(); + return $platform->getBitAndComparisonExpression( + $this->firstArithmetic->dispatch($sqlWalker), + $this->secondArithmetic->dispatch($sqlWalker) + ); + } + + /** + * @override + */ + public function parse(\Doctrine\ORM\Query\Parser $parser) + { + $parser->match(Lexer::T_IDENTIFIER); + $parser->match(Lexer::T_OPEN_PARENTHESIS); + + $this->firstArithmetic = $parser->ArithmeticPrimary(); + $parser->match(Lexer::T_COMMA); + $this->secondArithmetic = $parser->ArithmeticPrimary(); + + $parser->match(Lexer::T_CLOSE_PARENTHESIS); + } +} \ No newline at end of file diff --git a/lib/Doctrine/ORM/Query/AST/Functions/BitOrFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/BitOrFunction.php new file mode 100644 index 000000000..ba36e97aa --- /dev/null +++ b/lib/Doctrine/ORM/Query/AST/Functions/BitOrFunction.php @@ -0,0 +1,63 @@ +. + */ + +namespace Doctrine\ORM\Query\AST\Functions; + +use Doctrine\ORM\Query\Lexer; + +/** + * "BIT_OR" "(" ArithmeticPrimary "," ArithmeticPrimary ")" + * + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.doctrine-project.org + * @since 2.2 + * @author Fabio B. Silva + */ +class BitOrFunction extends FunctionNode +{ + public $firstArithmetic; + public $secondArithmetic; + + /** + * @override + */ + public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) + { + $platform = $sqlWalker->getConnection()->getDatabasePlatform(); + return $platform->getBitOrComparisonExpression( + $this->firstArithmetic->dispatch($sqlWalker), + $this->secondArithmetic->dispatch($sqlWalker) + ); + } + + /** + * @override + */ + public function parse(\Doctrine\ORM\Query\Parser $parser) + { + $parser->match(Lexer::T_IDENTIFIER); + $parser->match(Lexer::T_OPEN_PARENTHESIS); + + $this->firstArithmetic = $parser->ArithmeticPrimary(); + $parser->match(Lexer::T_COMMA); + $this->secondArithmetic = $parser->ArithmeticPrimary(); + + $parser->match(Lexer::T_CLOSE_PARENTHESIS); + } +} \ No newline at end of file diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 4c1bd50e1..234444226 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -53,6 +53,8 @@ class Parser 'mod' => 'Doctrine\ORM\Query\AST\Functions\ModFunction', 'size' => 'Doctrine\ORM\Query\AST\Functions\SizeFunction', 'date_diff' => 'Doctrine\ORM\Query\AST\Functions\DateDiffFunction', + 'bit_and' => 'Doctrine\ORM\Query\AST\Functions\BitAndFunction', + 'bit_or' => 'Doctrine\ORM\Query\AST\Functions\BitOrFunction', ); /** READ-ONLY: Maps BUILT-IN datetime function names to AST class names. */ diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php index e37ea9f62..9841dfeb7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php @@ -317,6 +317,54 @@ class QueryDqlFunctionTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertTrue(strtotime($arg[0]['add']) > 0); } + /** + * @group DDC-1213 + */ + public function testBitOrComparison() + { + $dql = 'SELECT m, ' . + 'BIT_OR(4, 2) AS bit_or,' . + 'BIT_OR( (m.salary/100000) , 2 ) AS salary_bit_or ' . + 'FROM Doctrine\Tests\Models\Company\CompanyManager m ' . + 'ORDER BY ' . + 'm.id ' ; + $result = $this->_em->createQuery($dql)->getArrayResult(); + + $this->assertEquals(4 | 2, $result[0]['bit_or']); + $this->assertEquals(4 | 2, $result[1]['bit_or']); + $this->assertEquals(4 | 2, $result[2]['bit_or']); + $this->assertEquals(4 | 2, $result[3]['bit_or']); + + $this->assertEquals(($result[0][0]['salary']/100000) | 2, $result[0]['salary_bit_or']); + $this->assertEquals(($result[1][0]['salary']/100000) | 2, $result[1]['salary_bit_or']); + $this->assertEquals(($result[2][0]['salary']/100000) | 2, $result[2]['salary_bit_or']); + $this->assertEquals(($result[3][0]['salary']/100000) | 2, $result[3]['salary_bit_or']); + } + + /** + * @group DDC-1213 + */ + public function testBitAndComparison() + { + $dql = 'SELECT m, ' . + 'BIT_AND(4, 2) AS bit_and,' . + 'BIT_AND( (m.salary/100000) , 2 ) AS salary_bit_and ' . + 'FROM Doctrine\Tests\Models\Company\CompanyManager m ' . + 'ORDER BY ' . + 'm.id ' ; + $result = $this->_em->createQuery($dql)->getArrayResult(); + + $this->assertEquals(4 & 2, $result[0]['bit_and']); + $this->assertEquals(4 & 2, $result[1]['bit_and']); + $this->assertEquals(4 & 2, $result[2]['bit_and']); + $this->assertEquals(4 & 2, $result[3]['bit_and']); + + $this->assertEquals(($result[0][0]['salary']/100000) & 2, $result[0]['salary_bit_and']); + $this->assertEquals(($result[1][0]['salary']/100000) & 2, $result[1]['salary_bit_and']); + $this->assertEquals(($result[2][0]['salary']/100000) & 2, $result[2]['salary_bit_and']); + $this->assertEquals(($result[3][0]['salary']/100000) & 2, $result[3]['salary_bit_and']); + } + protected function generateFixture() { $manager1 = new CompanyManager(); diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 7a7b7cd3f..a71f9f25d 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -1392,6 +1392,29 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ); } + /** + * @group DDC-1213 + */ + public function testSupportsBitComparison() + { + $this->assertSqlGeneration( + 'SELECT BIT_OR(4,2), BIT_AND(4,2), u FROM Doctrine\Tests\Models\CMS\CmsUser u', + 'SELECT (4 | 2) AS sclr0, (4 & 2) AS sclr1, c0_.id AS id2, c0_.status AS status3, c0_.username AS username4, c0_.name AS name5 FROM cms_users c0_' + ); + $this->assertSqlGeneration( + 'SELECT BIT_OR(u.id,2), BIT_AND(u.id,2) FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE BIT_OR(u.id,2) > 0', + 'SELECT (c0_.id | 2) AS sclr0, (c0_.id & 2) AS sclr1 FROM cms_users c0_ WHERE (c0_.id | 2) > 0' + ); + $this->assertSqlGeneration( + 'SELECT BIT_OR(u.id,2), BIT_AND(u.id,2) FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE BIT_AND(u.id , 4) > 0', + 'SELECT (c0_.id | 2) AS sclr0, (c0_.id & 2) AS sclr1 FROM cms_users c0_ WHERE (c0_.id & 4) > 0' + ); + $this->assertSqlGeneration( + 'SELECT BIT_OR(u.id,2), BIT_AND(u.id,2) FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE BIT_OR(u.id , 2) > 0 OR BIT_AND(u.id , 4) > 0', + 'SELECT (c0_.id | 2) AS sclr0, (c0_.id & 2) AS sclr1 FROM cms_users c0_ WHERE (c0_.id | 2) > 0 OR (c0_.id & 4) > 0' + ); + } + public function testCustomTypeValueSql() { if (DBALType::hasType('negative_to_positive')) { From ea5108ea0f35fc0f7ed3a740995a590926045c6e Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Mon, 19 Dec 2011 16:25:31 -0200 Subject: [PATCH 83/85] rebase upstream/master --- lib/vendor/doctrine-dbal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vendor/doctrine-dbal b/lib/vendor/doctrine-dbal index 537de7ea6..4410e4cec 160000 --- a/lib/vendor/doctrine-dbal +++ b/lib/vendor/doctrine-dbal @@ -1 +1 @@ -Subproject commit 537de7ea6a34edbcc40bc6ca92e0a3f816b59330 +Subproject commit 4410e4cec20b0f1f209578320e5b7d111e90c2a0 From f2d8102bbf5f58b6b56f311cb033a390440e900a Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Mon, 19 Dec 2011 22:32:50 +0100 Subject: [PATCH 84/85] Fix bug in test, removed an assertion that is not necessary and violates sqlites autoincrement assumptions --- tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php index feef41c76..77c964eea 100644 --- a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php @@ -812,7 +812,6 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testOneToOneOrphanRemoval() { - //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); $user = new CmsUser(); $user->username = "beberlei"; $user->name = "Benjamin E."; @@ -858,7 +857,6 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->flush(); $this->assertEquals(1, $this->_em->getConnection()->fetchColumn("select count(*) from cms_addresses")); - $this->assertEquals(0, $this->_em->getConnection()->fetchColumn("select count(*) from cms_addresses where id=".$addressId."")); } public function testGetPartialReferenceToUpdateObjectWithoutLoadingIt() From cd6131c9b8ae442b9de5c7e3f59610c17f485a7f Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Mon, 19 Dec 2011 22:56:19 +0100 Subject: [PATCH 85/85] Remove all trailing whitespaces --- lib/Doctrine/ORM/AbstractQuery.php | 2 +- lib/Doctrine/ORM/Configuration.php | 6 +- lib/Doctrine/ORM/Event/LifecycleEventArgs.php | 12 +- .../ORM/Event/LoadClassMetadataEventArgs.php | 6 +- lib/Doctrine/ORM/Event/OnClearEventArgs.php | 4 +- lib/Doctrine/ORM/Event/OnFlushEventArgs.php | 22 +- lib/Doctrine/ORM/Event/PostFlushEventArgs.php | 4 +- lib/Doctrine/ORM/Event/PreUpdateEventArgs.php | 14 +- lib/Doctrine/ORM/Events.php | 52 ++-- lib/Doctrine/ORM/Id/AbstractIdGenerator.php | 2 +- lib/Doctrine/ORM/Id/AssignedGenerator.php | 10 +- lib/Doctrine/ORM/Id/TableGenerator.php | 8 +- .../ORM/Internal/CommitOrderCalculator.php | 20 +- .../ORM/Internal/Hydration/ObjectHydrator.php | 8 +- .../ORM/Internal/Hydration/ScalarHydrator.php | 8 +- .../Hydration/SimpleObjectHydrator.php | 42 ++-- .../Hydration/SingleScalarHydrator.php | 10 +- .../Mapping/Builder/AssociationBuilder.php | 2 +- .../Mapping/Builder/ClassMetadataBuilder.php | 2 +- .../ORM/Mapping/Builder/FieldBuilder.php | 4 +- lib/Doctrine/ORM/Mapping/ClassMetadata.php | 2 +- .../ORM/Mapping/ClassMetadataFactory.php | 28 +-- .../ORM/Mapping/Driver/AbstractFileDriver.php | 36 +-- .../ORM/Mapping/Driver/AnnotationDriver.php | 10 +- .../ORM/Mapping/Driver/DatabaseDriver.php | 10 +- lib/Doctrine/ORM/Mapping/Driver/Driver.php | 8 +- .../ORM/Mapping/Driver/DriverChain.php | 2 +- .../ORM/Mapping/Driver/StaticPHPDriver.php | 10 +- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 2 +- .../ORM/Mapping/Driver/YamlDriver.php | 2 +- lib/Doctrine/ORM/Mapping/MappingException.php | 2 +- lib/Doctrine/ORM/NoResultException.php | 2 +- lib/Doctrine/ORM/NonUniqueResultException.php | 2 +- lib/Doctrine/ORM/ORMException.php | 2 +- .../AbstractCollectionPersister.php | 22 +- .../AbstractEntityInheritancePersister.php | 10 +- .../ORM/Persisters/BasicEntityPersister.php | 4 +- .../ORM/Persisters/ManyToManyPersister.php | 58 ++--- .../ORM/Persisters/OneToManyPersister.php | 22 +- .../ORM/Persisters/SingleTablePersister.php | 22 +- .../ORM/Persisters/UnionSubclassPersister.php | 2 +- lib/Doctrine/ORM/Proxy/Proxy.php | 2 +- lib/Doctrine/ORM/Query.php | 2 +- .../ORM/Query/AST/ArithmeticFactor.php | 2 +- .../ORM/Query/AST/CoalesceExpression.php | 6 +- .../Query/AST/CollectionMemberExpression.php | 2 +- .../ORM/Query/AST/DeleteStatement.php | 2 +- .../EmptyCollectionComparisonExpression.php | 2 +- lib/Doctrine/ORM/Query/AST/FromClause.php | 4 +- .../ORM/Query/AST/Functions/AbsFunction.php | 4 +- .../AST/Functions/CurrentDateFunction.php | 2 +- .../Query/AST/Functions/IdentityFunction.php | 10 +- .../Query/AST/Functions/LengthFunction.php | 4 +- .../Query/AST/Functions/LocateFunction.php | 12 +- .../ORM/Query/AST/Functions/LowerFunction.php | 4 +- .../ORM/Query/AST/Functions/ModFunction.php | 8 +- .../ORM/Query/AST/Functions/SizeFunction.php | 12 +- .../ORM/Query/AST/Functions/SqrtFunction.php | 4 +- .../Query/AST/Functions/SubstringFunction.php | 6 +- .../ORM/Query/AST/Functions/UpperFunction.php | 4 +- .../ORM/Query/AST/GeneralCaseExpression.php | 6 +- .../AST/IdentificationVariableDeclaration.php | 2 +- lib/Doctrine/ORM/Query/AST/IndexBy.php | 4 +- .../ORM/Query/AST/InstanceOfExpression.php | 2 +- lib/Doctrine/ORM/Query/AST/Join.php | 4 +- .../AST/JoinAssociationPathExpression.php | 2 +- .../ORM/Query/AST/JoinVariableDeclaration.php | 2 +- lib/Doctrine/ORM/Query/AST/Literal.php | 6 +- lib/Doctrine/ORM/Query/AST/Node.php | 26 +- .../Query/AST/NullComparisonExpression.php | 2 +- .../ORM/Query/AST/NullIfExpression.php | 6 +- lib/Doctrine/ORM/Query/AST/OrderByItem.php | 2 +- .../ORM/Query/AST/PartialObjectExpression.php | 2 +- lib/Doctrine/ORM/Query/AST/PathExpression.php | 10 +- .../Query/AST/RangeVariableDeclaration.php | 4 +- lib/Doctrine/ORM/Query/AST/SelectClause.php | 2 +- .../ORM/Query/AST/SelectExpression.php | 4 +- .../ORM/Query/AST/SelectStatement.php | 4 +- .../ORM/Query/AST/SimpleCaseExpression.php | 6 +- .../ORM/Query/AST/SimpleSelectClause.php | 2 +- .../ORM/Query/AST/SimpleSelectExpression.php | 4 +- .../ORM/Query/AST/SimpleWhenClause.php | 6 +- lib/Doctrine/ORM/Query/AST/Subselect.php | 4 +- .../ORM/Query/AST/SubselectFromClause.php | 4 +- .../ORM/Query/AST/UpdateStatement.php | 2 +- lib/Doctrine/ORM/Query/AST/WhenClause.php | 6 +- .../Query/Exec/MultiTableDeleteExecutor.php | 6 +- .../Query/Exec/MultiTableUpdateExecutor.php | 28 +-- .../Exec/SingleTableDeleteUpdateExecutor.php | 2 +- lib/Doctrine/ORM/Query/Expr/Comparison.php | 2 +- lib/Doctrine/ORM/Query/Expr/From.php | 14 +- lib/Doctrine/ORM/Query/Expr/Join.php | 4 +- lib/Doctrine/ORM/Query/Expr/Math.php | 8 +- .../ORM/Query/ParameterTypeInferer.php | 4 +- lib/Doctrine/ORM/Query/ParserResult.php | 20 +- lib/Doctrine/ORM/Query/ResultSetMapping.php | 18 +- .../Command/ClearCache/MetadataCommand.php | 12 +- .../Command/ClearCache/QueryCommand.php | 12 +- .../Command/ClearCache/ResultCommand.php | 12 +- .../Command/ConvertDoctrine1SchemaCommand.php | 4 +- .../Command/GenerateEntitiesCommand.php | 4 +- .../Command/GenerateProxiesCommand.php | 2 +- .../Command/GenerateRepositoriesCommand.php | 2 +- .../Command/SchemaTool/UpdateCommand.php | 2 +- .../ORM/Tools/Console/ConsoleRunner.php | 2 +- .../ORM/Tools/Console/MetadataFilter.php | 2 +- .../ORM/Tools/ConvertDoctrine1Schema.php | 2 +- .../ORM/Tools/DebugUnitOfWorkListener.php | 2 +- .../DisconnectedClassMetadataFactory.php | 2 +- .../Tools/Export/Driver/AbstractExporter.php | 22 +- .../Export/Driver/AnnotationExporter.php | 2 +- .../ORM/Tools/Export/Driver/PhpExporter.php | 12 +- .../ORM/Tools/Export/Driver/XmlExporter.php | 8 +- .../ORM/Tools/Export/Driver/YamlExporter.php | 4 +- lib/Doctrine/ORM/Tools/Setup.php | 56 ++--- lib/Doctrine/ORM/Version.php | 4 +- .../Tests/Mocks/ClassMetadataMock.php | 4 +- tests/Doctrine/Tests/Mocks/DriverMock.php | 2 +- .../Tests/Mocks/EntityManagerMock.php | 10 +- .../Tests/Mocks/EntityPersisterMock.php | 12 +- .../Tests/Mocks/HydratorMockStatement.php | 2 +- tests/Doctrine/Tests/Mocks/MockTreeWalker.php | 2 +- .../Tests/Mocks/SchemaManagerMock.php | 2 +- .../Doctrine/Tests/Models/CMS/CmsArticle.php | 2 +- tests/Doctrine/Tests/Models/CMS/CmsEmail.php | 4 +- tests/Doctrine/Tests/Models/CMS/CmsGroup.php | 2 +- .../Tests/Models/CMS/CmsPhonenumber.php | 2 +- tests/Doctrine/Tests/Models/CMS/CmsUser.php | 12 +- .../Tests/Models/Company/CompanyAuction.php | 4 +- .../Tests/Models/Company/CompanyCar.php | 6 +- .../Tests/Models/Company/CompanyContract.php | 4 +- .../Tests/Models/Company/CompanyEmployee.php | 2 +- .../Tests/Models/Company/CompanyEvent.php | 8 +- .../Tests/Models/Company/CompanyManager.php | 6 +- .../Models/Company/CompanyOrganization.php | 14 +- .../Tests/Models/Company/CompanyPerson.php | 8 +- .../Tests/Models/Company/CompanyRaffle.php | 4 +- .../Tests/Models/DDC117/DDC117Article.php | 2 +- .../DDC1476EntityWithDefaultFieldType.php | 14 +- .../Models/DDC753/DDC753CustomRepository.php | 2 +- .../Models/DDC753/DDC753DefaultRepository.php | 2 +- .../DDC753EntityWithCustomRepository.php | 4 +- ...DC753EntityWithDefaultCustomRepository.php | 4 +- .../DDC753EntityWithInvalidRepository.php | 4 +- .../Models/DDC869/DDC869ChequePayment.php | 2 +- .../Models/DDC869/DDC869CreditCardPayment.php | 2 +- .../Tests/Models/DDC869/DDC869Payment.php | 8 +- .../Models/DDC869/DDC869PaymentRepository.php | 4 +- .../DirectoryTree/AbstractContentItem.php | 2 +- .../Tests/Models/ECommerce/ECommerceCart.php | 12 +- .../Models/ECommerce/ECommerceCustomer.php | 14 +- .../Models/ECommerce/ECommerceFeature.php | 10 +- .../Models/ECommerce/ECommerceProduct.php | 2 +- .../Doctrine/Tests/Models/Forum/ForumUser.php | 8 +- .../Tests/ORM/CommitOrderCalculatorTest.php | 10 +- .../Tests/ORM/Criteria/DqlGenerationTest.php | 2 +- .../Tests/ORM/Entity/ConstructorTest.php | 4 +- .../Doctrine/Tests/ORM/EntityManagerTest.php | 4 +- .../Functional/AdvancedAssociationTest.php | 134 +++++------ .../ORM/Functional/BasicFunctionalTest.php | 144 ++++++------ .../Functional/ClassTableInheritanceTest.php | 98 ++++---- .../Functional/ClassTableInheritanceTest2.php | 40 ++-- .../Functional/CompositePrimaryKeyTest.php | 6 +- .../ORM/Functional/DefaultValuesTest.php | 18 +- .../ORM/Functional/DetachedEntityTest.php | 14 +- .../Functional/ExtraLazyCollectionTest.php | 2 +- .../Tests/ORM/Functional/FlushEventTest.php | 28 +-- .../Tests/ORM/Functional/IdentityMapTest.php | 122 +++++----- .../ORM/Functional/LifecycleCallbackTest.php | 48 ++-- .../Functional/Locking/GearmanLockTest.php | 2 +- .../ORM/Functional/Locking/OptimisticTest.php | 8 +- .../ManyToManyBasicAssociationTest.php | 62 ++--- ...ManyToManyBidirectionalAssociationTest.php | 34 +-- ...nyToManySelfReferentialAssociationTest.php | 16 +- ...anyToManyUnidirectionalAssociationTest.php | 10 +- .../OneToManyBidirectionalAssociationTest.php | 28 +-- ...neToManySelfReferentialAssociationTest.php | 12 +- .../OneToOneBidirectionalAssociationTest.php | 36 +-- .../Functional/OneToOneEagerLoadingTest.php | 2 +- .../Functional/OneToOneOrphanRemovalTest.php | 48 ++-- ...OneToOneSelfReferentialAssociationTest.php | 26 +- .../OneToOneUnidirectionalAssociationTest.php | 16 +- .../ORM/Functional/OrderedCollectionTest.php | 2 +- ...edJoinedTableInheritanceCollectionTest.php | 6 +- .../PostgreSQLIdentityStrategyTest.php | 4 +- .../Tests/ORM/Functional/QueryCacheTest.php | 10 +- .../ORM/Functional/QueryDqlFunctionTest.php | 10 +- .../Tests/ORM/Functional/ResultCacheTest.php | 12 +- .../ORM/Functional/SchemaTool/DDC214Test.php | 2 +- .../SchemaTool/MySqlSchemaToolTest.php | 10 +- .../StandardEntityPersisterTest.php | 30 +-- .../ORM/Functional/Ticket/DDC1041Test.php | 8 +- .../ORM/Functional/Ticket/DDC1050Test.php | 4 +- .../ORM/Functional/Ticket/DDC1080Test.php | 22 +- .../ORM/Functional/Ticket/DDC1163Test.php | 8 +- .../ORM/Functional/Ticket/DDC117Test.php | 2 +- .../ORM/Functional/Ticket/DDC1181Test.php | 12 +- .../ORM/Functional/Ticket/DDC1193Test.php | 2 +- .../ORM/Functional/Ticket/DDC1276Test.php | 2 +- .../ORM/Functional/Ticket/DDC1383Test.php | 20 +- .../ORM/Functional/Ticket/DDC1404Test.php | 36 +-- .../ORM/Functional/Ticket/DDC1430Test.php | 102 ++++---- .../ORM/Functional/Ticket/DDC144Test.php | 10 +- .../ORM/Functional/Ticket/DDC1458Test.php | 4 +- .../ORM/Functional/Ticket/DDC1461Test.php | 2 +- .../ORM/Functional/Ticket/DDC1509Test.php | 4 +- .../ORM/Functional/Ticket/DDC1514Test.php | 222 +++++++++--------- .../ORM/Functional/Ticket/DDC1548Test.php | 2 +- .../ORM/Functional/Ticket/DDC168Test.php | 4 +- .../ORM/Functional/Ticket/DDC192Test.php | 20 +- .../ORM/Functional/Ticket/DDC199Test.php | 22 +- .../ORM/Functional/Ticket/DDC211Test.php | 6 +- .../ORM/Functional/Ticket/DDC237Test.php | 26 +- .../ORM/Functional/Ticket/DDC258Test.php | 6 +- .../ORM/Functional/Ticket/DDC279Test.php | 6 +- .../ORM/Functional/Ticket/DDC345Test.php | 2 +- .../ORM/Functional/Ticket/DDC353Test.php | 2 +- .../ORM/Functional/Ticket/DDC371Test.php | 12 +- .../ORM/Functional/Ticket/DDC381Test.php | 4 +- .../ORM/Functional/Ticket/DDC422Test.php | 8 +- .../ORM/Functional/Ticket/DDC425Test.php | 2 +- .../ORM/Functional/Ticket/DDC440Test.php | 10 +- .../ORM/Functional/Ticket/DDC444Test.php | 6 +- .../ORM/Functional/Ticket/DDC501Test.php | 2 +- .../ORM/Functional/Ticket/DDC512Test.php | 2 +- .../ORM/Functional/Ticket/DDC522Test.php | 4 +- .../ORM/Functional/Ticket/DDC531Test.php | 2 +- .../ORM/Functional/Ticket/DDC618Test.php | 2 +- .../ORM/Functional/Ticket/DDC633Test.php | 6 +- .../ORM/Functional/Ticket/DDC656Test.php | 2 +- .../ORM/Functional/Ticket/DDC729Test.php | 4 +- .../ORM/Functional/Ticket/DDC736Test.php | 6 +- .../ORM/Functional/Ticket/DDC767Test.php | 2 +- .../ORM/Functional/Ticket/DDC809Test.php | 2 +- .../ORM/Functional/Ticket/DDC812Test.php | 4 +- .../ORM/Functional/Ticket/DDC832Test.php | 2 +- .../ORM/Functional/Ticket/DDC849Test.php | 36 +-- .../ORM/Functional/Ticket/DDC881Test.php | 2 +- .../Tests/ORM/Functional/Ticket/Ticket69.php | 2 +- .../Tests/ORM/Functional/TypeValueSqlTest.php | 4 +- .../ORM/Hydration/ResultSetMappingTest.php | 12 +- .../Tests/ORM/Id/AssignedGeneratorTest.php | 4 +- .../ORM/Mapping/AbstractMappingDriverTest.php | 18 +- .../ORM/Mapping/AnnotationDriverTest.php | 28 +-- .../Mapping/BasicInheritanceMappingTest.php | 66 +++--- .../ORM/Mapping/ClassMetadataFactoryTest.php | 12 +- .../Mapping/ClassMetadataLoadEventTest.php | 2 +- .../Tests/ORM/Mapping/ClassMetadataTest.php | 10 +- .../Tests/ORM/Mapping/DriverChainTest.php | 6 +- .../ORM/Mapping/XmlMappingDriverTest.php | 2 +- .../php/Doctrine.Tests.ORM.Mapping.User.php | 22 +- .../Performance/HydrationPerformanceTest.php | 6 +- .../ORM/Performance/InsertPerformanceTest.php | 6 +- .../Performance/UnitOfWorkPerformanceTest.php | 2 +- .../Tests/ORM/PersistentCollectionTest.php | 2 +- .../BasicEntityPersisterTypeValueSqlTest.php | 4 +- .../ORM/Query/LanguageRecognitionTest.php | 54 ++--- tests/Doctrine/Tests/ORM/Query/LexerTest.php | 2 +- tests/Doctrine/Tests/ORM/QueryBuilderTest.php | 90 +++---- .../Tests/ORM/Tools/EntityGeneratorTest.php | 6 +- .../AbstractClassMetadataExporterTest.php | 12 +- .../Doctrine.Tests.ORM.Tools.Export.User.php | 22 +- .../Tools/ResolveTargetEntityListenerTest.php | 4 +- tests/Doctrine/Tests/ORM/Tools/SetupTest.php | 36 +-- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 28 +-- .../Doctrine/Tests/OrmFunctionalTestCase.php | 28 +-- tests/Doctrine/Tests/OrmTestCase.php | 26 +- tests/NativePhpunitTask.php | 2 +- 268 files changed, 1724 insertions(+), 1724 deletions(-) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index 7010136c8..3fe27f93b 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -616,7 +616,7 @@ abstract class AbstractQuery $this->_queryCacheProfile = $this->_queryCacheProfile ? $this->_queryCacheProfile->setCacheKey($id) : new QueryCacheProfile(0, $id); - + return $this; } diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index cddc8672c..83b4dc5dd 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -523,14 +523,14 @@ class Configuration extends \Doctrine\DBAL\Configuration /** * Set default repository class. - * + * * @since 2.2 * @param string $className * @throws ORMException If not is a \Doctrine\ORM\EntityRepository */ public function setDefaultRepositoryClassName($className) { - if ($className != "Doctrine\ORM\EntityRepository" && + if ($className != "Doctrine\ORM\EntityRepository" && !is_subclass_of($className, 'Doctrine\ORM\EntityRepository')){ throw ORMException::invalidEntityRepository($className); } @@ -539,7 +539,7 @@ class Configuration extends \Doctrine\DBAL\Configuration /** * Get default repository class. - * + * * @since 2.2 * @return string */ diff --git a/lib/Doctrine/ORM/Event/LifecycleEventArgs.php b/lib/Doctrine/ORM/Event/LifecycleEventArgs.php index 320b03572..6740a3e12 100644 --- a/lib/Doctrine/ORM/Event/LifecycleEventArgs.php +++ b/lib/Doctrine/ORM/Event/LifecycleEventArgs.php @@ -42,10 +42,10 @@ class LifecycleEventArgs extends EventArgs * @var object */ private $entity; - + /** * Constructor - * + * * @param object $entity * @param \Doctrine\ORM\EntityManager $em */ @@ -54,11 +54,11 @@ class LifecycleEventArgs extends EventArgs $this->entity = $entity; $this->em = $em; } - + /** * Retireve associated Entity. - * - * @return object + * + * @return object */ public function getEntity() { @@ -67,7 +67,7 @@ class LifecycleEventArgs extends EventArgs /** * Retrieve associated EntityManager. - * + * * @return \Doctrine\ORM\EntityManager */ public function getEntityManager() diff --git a/lib/Doctrine/ORM/Event/LoadClassMetadataEventArgs.php b/lib/Doctrine/ORM/Event/LoadClassMetadataEventArgs.php index 2cd25933b..901bf3a78 100644 --- a/lib/Doctrine/ORM/Event/LoadClassMetadataEventArgs.php +++ b/lib/Doctrine/ORM/Event/LoadClassMetadataEventArgs.php @@ -43,7 +43,7 @@ class LoadClassMetadataEventArgs extends EventArgs /** * Constructor. - * + * * @param \Doctrine\ORM\Mapping\ClassMetadataInfo $classMetadata * @param \Doctrine\ORM\EntityManager $em */ @@ -55,7 +55,7 @@ class LoadClassMetadataEventArgs extends EventArgs /** * Retrieve associated ClassMetadata. - * + * * @return \Doctrine\ORM\Mapping\ClassMetadataInfo */ public function getClassMetadata() @@ -65,7 +65,7 @@ class LoadClassMetadataEventArgs extends EventArgs /** * Retrieve associated EntityManager. - * + * * @return \Doctrine\ORM\EntityManager */ public function getEntityManager() diff --git a/lib/Doctrine/ORM/Event/OnClearEventArgs.php b/lib/Doctrine/ORM/Event/OnClearEventArgs.php index 07f5c4711..542ac45e3 100644 --- a/lib/Doctrine/ORM/Event/OnClearEventArgs.php +++ b/lib/Doctrine/ORM/Event/OnClearEventArgs.php @@ -42,7 +42,7 @@ class OnClearEventArgs extends \Doctrine\Common\EventArgs /** * Constructor. - * + * * @param \Doctrine\ORM\EntityManager $em * @param string $entityClass Optional entity class */ @@ -54,7 +54,7 @@ class OnClearEventArgs extends \Doctrine\Common\EventArgs /** * Retrieve associated EntityManager. - * + * * @return \Doctrine\ORM\EntityManager */ public function getEntityManager() diff --git a/lib/Doctrine/ORM/Event/OnFlushEventArgs.php b/lib/Doctrine/ORM/Event/OnFlushEventArgs.php index fd8545b21..c4aeb2a16 100644 --- a/lib/Doctrine/ORM/Event/OnFlushEventArgs.php +++ b/lib/Doctrine/ORM/Event/OnFlushEventArgs.php @@ -38,13 +38,13 @@ class OnFlushEventArgs extends \Doctrine\Common\EventArgs * @var Doctirne\ORM\EntityManager */ private $em; - + //private $entitiesToPersist = array(); //private $entitiesToRemove = array(); - + /** * Constructor. - * + * * @param \Doctrine\ORM\EntityManager $em */ public function __construct(EntityManager $em) @@ -54,30 +54,30 @@ class OnFlushEventArgs extends \Doctrine\Common\EventArgs /** * Retrieve associated EntityManager. - * + * * @return \Doctrine\ORM\EntityManager */ public function getEntityManager() { return $this->em; } - + /* public function addEntityToPersist($entity) { - + } - + public function addEntityToRemove($entity) { - + } - + public function addEntityToUpdate($entity) { - + } - + public function getEntitiesToPersist() { return $this->_entitiesToPersist; diff --git a/lib/Doctrine/ORM/Event/PostFlushEventArgs.php b/lib/Doctrine/ORM/Event/PostFlushEventArgs.php index e10d600df..f45030de7 100644 --- a/lib/Doctrine/ORM/Event/PostFlushEventArgs.php +++ b/lib/Doctrine/ORM/Event/PostFlushEventArgs.php @@ -41,7 +41,7 @@ class PostFlushEventArgs extends EventArgs /** * Constructor. - * + * * @param \Doctrine\ORM\EntityManager $em */ public function __construct(EntityManager $em) @@ -51,7 +51,7 @@ class PostFlushEventArgs extends EventArgs /** * Retrieve associated EntityManager. - * + * * @return \Doctrine\ORM\EntityManager */ public function getEntityManager() diff --git a/lib/Doctrine/ORM/Event/PreUpdateEventArgs.php b/lib/Doctrine/ORM/Event/PreUpdateEventArgs.php index 4d7e3ef38..0bebba1c8 100644 --- a/lib/Doctrine/ORM/Event/PreUpdateEventArgs.php +++ b/lib/Doctrine/ORM/Event/PreUpdateEventArgs.php @@ -41,7 +41,7 @@ class PreUpdateEventArgs extends LifecycleEventArgs /** * Constructor. - * + * * @param object $entity * @param \Doctrine\ORM\EntityManager $em * @param array $changeSet @@ -49,13 +49,13 @@ class PreUpdateEventArgs extends LifecycleEventArgs public function __construct($entity, EntityManager $em, array &$changeSet) { parent::__construct($entity, $em); - + $this->entityChangeSet = &$changeSet; } /** * Retrieve entity changeset. - * + * * @return array */ public function getEntityChangeSet() @@ -75,7 +75,7 @@ class PreUpdateEventArgs extends LifecycleEventArgs /** * Get the old value of the changeset of the changed field. - * + * * @param string $field * @return mixed */ @@ -101,7 +101,7 @@ class PreUpdateEventArgs extends LifecycleEventArgs /** * Set the new value of this field. - * + * * @param string $field * @param mixed $value */ @@ -114,8 +114,8 @@ class PreUpdateEventArgs extends LifecycleEventArgs /** * Assert the field exists in changeset. - * - * @param string $field + * + * @param string $field */ private function assertValidField($field) { diff --git a/lib/Doctrine/ORM/Events.php b/lib/Doctrine/ORM/Events.php index 8af7a9b61..45424e7c2 100644 --- a/lib/Doctrine/ORM/Events.php +++ b/lib/Doctrine/ORM/Events.php @@ -35,55 +35,55 @@ final class Events /** * The preRemove event occurs for a given entity before the respective * EntityManager remove operation for that entity is executed. - * + * * This is an entity lifecycle event. - * + * * @var string */ const preRemove = 'preRemove'; /** - * The postRemove event occurs for an entity after the entity has + * The postRemove event occurs for an entity after the entity has * been deleted. It will be invoked after the database delete operations. - * + * * This is an entity lifecycle event. - * + * * @var string */ const postRemove = 'postRemove'; /** * The prePersist event occurs for a given entity before the respective * EntityManager persist operation for that entity is executed. - * + * * This is an entity lifecycle event. - * + * * @var string */ const prePersist = 'prePersist'; /** - * The postPersist event occurs for an entity after the entity has + * The postPersist event occurs for an entity after the entity has * been made persistent. It will be invoked after the database insert operations. * Generated primary key values are available in the postPersist event. - * + * * This is an entity lifecycle event. - * + * * @var string */ const postPersist = 'postPersist'; /** - * The preUpdate event occurs before the database update operations to - * entity data. - * + * The preUpdate event occurs before the database update operations to + * entity data. + * * This is an entity lifecycle event. - * + * * @var string */ const preUpdate = 'preUpdate'; /** - * The postUpdate event occurs after the database update operations to - * entity data. - * + * The postUpdate event occurs after the database update operations to + * entity data. + * * This is an entity lifecycle event. - * + * * @var string */ const postUpdate = 'postUpdate'; @@ -91,24 +91,24 @@ final class Events * The postLoad event occurs for an entity after the entity has been loaded * into the current EntityManager from the database or after the refresh operation * has been applied to it. - * + * * Note that the postLoad event occurs for an entity before any associations have been * initialized. Therefore it is not safe to access associations in a postLoad callback * or event handler. - * + * * This is an entity lifecycle event. - * + * * @var string */ const postLoad = 'postLoad'; /** * The loadClassMetadata event occurs after the mapping metadata for a class * has been loaded from a mapping source (annotations/xml/yaml). - * + * * @var string */ const loadClassMetadata = 'loadClassMetadata'; - + /** * The preFlush event occurs when the EntityManager#flush() operation is invoked, * but before any changes to managed entites have been calculated. This event is @@ -122,7 +122,7 @@ final class Events * actual database operations are executed. The event is only raised if there is * actually something to do for the underlying UnitOfWork. If nothing needs to be done, * the onFlush event is not raised. - * + * * @var string */ const onFlush = 'onFlush'; @@ -133,11 +133,11 @@ final class Events * actually something to do for the underlying UnitOfWork. If nothing needs to be done, * the postFlush event is not raised. The event won't be raised if an error occurs during the * flush operation. - * + * * @var string */ const postFlush = 'postFlush'; - + /** * The onClear event occurs when the EntityManager#clear() operation is invoked, * after all references to entities have been removed from the unit of work. diff --git a/lib/Doctrine/ORM/Id/AbstractIdGenerator.php b/lib/Doctrine/ORM/Id/AbstractIdGenerator.php index 677238289..d27c00b77 100644 --- a/lib/Doctrine/ORM/Id/AbstractIdGenerator.php +++ b/lib/Doctrine/ORM/Id/AbstractIdGenerator.php @@ -35,7 +35,7 @@ abstract class AbstractIdGenerator * Gets whether this generator is a post-insert generator which means that * {@link generate()} must be called after the entity has been inserted * into the database. - * + * * By default, this method returns FALSE. Generators that have this requirement * must override this method and return TRUE. * diff --git a/lib/Doctrine/ORM/Id/AssignedGenerator.php b/lib/Doctrine/ORM/Id/AssignedGenerator.php index 2e2d4f2f6..c9f9adad8 100644 --- a/lib/Doctrine/ORM/Id/AssignedGenerator.php +++ b/lib/Doctrine/ORM/Id/AssignedGenerator.php @@ -46,14 +46,14 @@ class AssignedGenerator extends AbstractIdGenerator $class = $em->getClassMetadata(get_class($entity)); $idFields = $class->getIdentifierFieldNames(); $identifier = array(); - + foreach ($idFields as $idField) { $value = $class->reflFields[$idField]->getValue($entity); - + if ( ! isset($value)) { throw ORMException::entityMissingAssignedIdForField($entity, $idField); } - + if (isset($class->associationMappings[$idField])) { if ( ! $em->getUnitOfWork()->isInIdentityMap($value)) { throw ORMException::entityMissingForeignAssignedId($entity, $value); @@ -62,10 +62,10 @@ class AssignedGenerator extends AbstractIdGenerator // NOTE: Single Columns as associated identifiers only allowed - this constraint it is enforced. $value = current($em->getUnitOfWork()->getEntityIdentifier($value)); } - + $identifier[$idField] = $value; } - + return $identifier; } } diff --git a/lib/Doctrine/ORM/Id/TableGenerator.php b/lib/Doctrine/ORM/Id/TableGenerator.php index 5c49344fe..24b1d90e5 100644 --- a/lib/Doctrine/ORM/Id/TableGenerator.php +++ b/lib/Doctrine/ORM/Id/TableGenerator.php @@ -50,12 +50,12 @@ class TableGenerator extends AbstractIdGenerator if ($this->_maxValue === null || $this->_nextValue == $this->_maxValue) { // Allocate new values $conn = $em->getConnection(); - + if ($conn->getTransactionNestingLevel() === 0) { // use select for update $sql = $conn->getDatabasePlatform()->getTableHiLoCurrentValSql($this->_tableName, $this->_sequenceName); $currentLevel = $conn->fetchColumn($sql); - + if ($currentLevel != null) { $this->_nextValue = $currentLevel; $this->_maxValue = $this->_nextValue + $this->_allocationSize; @@ -63,7 +63,7 @@ class TableGenerator extends AbstractIdGenerator $updateSql = $conn->getDatabasePlatform()->getTableHiLoUpdateNextValSql( $this->_tableName, $this->_sequenceName, $this->_allocationSize ); - + if ($conn->executeUpdate($updateSql, array(1 => $currentLevel, 2 => $currentLevel+1)) !== 1) { // no affected rows, concurrency issue, throw exception } @@ -75,7 +75,7 @@ class TableGenerator extends AbstractIdGenerator // or do we want to work with table locks exclusively? } } - + return $this->_nextValue++; } } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php b/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php index aad34e993..049cab060 100644 --- a/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php +++ b/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php @@ -24,7 +24,7 @@ namespace Doctrine\ORM\Internal; * correct order in which changes to entities need to be persisted. * * @since 2.0 - * @author Roman Borschel + * @author Roman Borschel * @author Guilherme Blanco */ class CommitOrderCalculator @@ -32,12 +32,12 @@ class CommitOrderCalculator const NOT_VISITED = 1; const IN_PROGRESS = 2; const VISITED = 3; - + private $_nodeStates = array(); private $_classes = array(); // The nodes to sort private $_relatedClasses = array(); private $_sorted = array(); - + /** * Clears the current graph. * @@ -48,10 +48,10 @@ class CommitOrderCalculator $this->_classes = $this->_relatedClasses = array(); } - + /** * Gets a valid commit order for all current nodes. - * + * * Uses a depth-first search (DFS) to traverse the graph. * The desired topological sorting is the reverse postorder of these searches. * @@ -65,12 +65,12 @@ class CommitOrderCalculator if ($nodeCount <= 1) { return ($nodeCount == 1) ? array_values($this->_classes) : array(); } - + // Init foreach ($this->_classes as $node) { $this->_nodeStates[$node->name] = self::NOT_VISITED; } - + // Go foreach ($this->_classes as $node) { if ($this->_nodeStates[$node->name] == self::NOT_VISITED) { @@ -100,17 +100,17 @@ class CommitOrderCalculator $this->_nodeStates[$node->name] = self::VISITED; $this->_sorted[] = $node; } - + public function addDependency($fromClass, $toClass) { $this->_relatedClasses[$fromClass->name][] = $toClass; } - + public function hasClass($className) { return isset($this->_classes[$className]); } - + public function addClass($class) { $this->_classes[$class->name] = $class; diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index 1935e901d..838e9ef8c 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -233,20 +233,20 @@ class ObjectHydrator extends AbstractHydrator } $this->_hints['fetchAlias'] = $dqlAlias; - + $entity = $this->_uow->createEntity($className, $data, $this->_hints); - + //TODO: These should be invoked later, after hydration, because associations may not yet be loaded here. if (isset($this->_ce[$className]->lifecycleCallbacks[Events::postLoad])) { $this->_ce[$className]->invokeLifecycleCallbacks(Events::postLoad, $entity); } - + $evm = $this->_em->getEventManager(); if ($evm->hasListeners(Events::postLoad)) { $evm->dispatchEvent(Events::postLoad, new LifecycleEventArgs($entity, $this->_em)); } - + return $entity; } diff --git a/lib/Doctrine/ORM/Internal/Hydration/ScalarHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ScalarHydrator.php index 29c0d12e5..d02651b29 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ScalarHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ScalarHydrator.php @@ -32,22 +32,22 @@ use Doctrine\DBAL\Connection; */ class ScalarHydrator extends AbstractHydrator { - /** + /** * {@inheritdoc} */ protected function hydrateAllData() { $result = array(); $cache = array(); - + while ($data = $this->_stmt->fetch(\PDO::FETCH_ASSOC)) { $this->hydrateRowData($data, $cache, $result); } - + return $result; } - /** + /** * {@inheritdoc} */ protected function hydrateRowData(array $data, array &$cache, array &$result) diff --git a/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php index a4770f28e..648f64979 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php @@ -63,18 +63,18 @@ class SimpleObjectHydrator extends AbstractHydrator if (count($this->_rsm->aliasMap) !== 1) { throw new \RuntimeException("Cannot use SimpleObjectHydrator with a ResultSetMapping that contains more than one object result."); } - + if ($this->_rsm->scalarMappings) { throw new \RuntimeException("Cannot use SimpleObjectHydrator with a ResultSetMapping that contains scalar mappings."); } - + $this->class = $this->_em->getClassMetadata(reset($this->_rsm->aliasMap)); - + // We only need to add declaring classes if we have inheritance. if ($this->class->inheritanceType === ClassMetadata::INHERITANCE_TYPE_NONE) { return; } - + foreach ($this->_rsm->declaringClasses AS $column => $class) { $this->declaringClasses[$column] = $this->_em->getClassMetadata($class); } @@ -87,27 +87,27 @@ class SimpleObjectHydrator extends AbstractHydrator { $entityName = $this->class->name; $data = array(); - + // We need to find the correct entity class name if we have inheritance in resultset if ($this->class->inheritanceType !== ClassMetadata::INHERITANCE_TYPE_NONE) { $discrColumnName = $this->_platform->getSQLResultCasing($this->class->discriminatorColumn['name']); - + if ($sqlResult[$discrColumnName] === '') { throw HydrationException::emptyDiscriminatorValue(key($this->_rsm->aliasMap)); } $entityName = $this->class->discriminatorMap[$sqlResult[$discrColumnName]]; - + unset($sqlResult[$discrColumnName]); } - + foreach ($sqlResult as $column => $value) { // Hydrate column information if not yet present if ( ! isset($cache[$column])) { if (($info = $this->hydrateColumnInfo($entityName, $column)) === null) { continue; } - + $cache[$column] = $info; } @@ -116,7 +116,7 @@ class SimpleObjectHydrator extends AbstractHydrator $type = Type::getType($cache[$column]['class']->fieldMappings[$cache[$column]['name']]['type']); $value = $type->convertToPHPValue($value, $this->_platform); } - + // Prevent overwrite in case of inherit classes using same property name (See AbstractHydrator) if (isset($cache[$column]) && ( ! isset($data[$cache[$column]['name']]) || $value !== null)) { $data[$cache[$column]['name']] = $value; @@ -129,7 +129,7 @@ class SimpleObjectHydrator extends AbstractHydrator $uow = $this->_em->getUnitOfWork(); $entity = $uow->createEntity($entityName, $data, $this->_hints); - + //TODO: These should be invoked later, after hydration, because associations may not yet be loaded here. if (isset($this->class->lifecycleCallbacks[Events::postLoad])) { $this->class->invokeLifecycleCallbacks(Events::postLoad, $entity); @@ -140,24 +140,24 @@ class SimpleObjectHydrator extends AbstractHydrator if ($evm->hasListeners(Events::postLoad)) { $evm->dispatchEvent(Events::postLoad, new LifecycleEventArgs($entity, $this->_em)); } - + $result[] = $entity; } - + /** * Retrieve column information form ResultSetMapping. - * + * * @param string $entityName * @param string $column - * - * @return array + * + * @return array */ protected function hydrateColumnInfo($entityName, $column) { switch (true) { case (isset($this->_rsm->fieldMappings[$column])): - $class = isset($this->declaringClasses[$column]) - ? $this->declaringClasses[$column] + $class = isset($this->declaringClasses[$column]) + ? $this->declaringClasses[$column] : $this->class; // If class is not part of the inheritance, ignore @@ -172,8 +172,8 @@ class SimpleObjectHydrator extends AbstractHydrator ); case (isset($this->_rsm->relationMap[$column])): - $class = isset($this->_rsm->relationMap[$column]) - ? $this->_rsm->relationMap[$column] + $class = isset($this->_rsm->relationMap[$column]) + ? $this->_rsm->relationMap[$column] : $this->class; // If class is not self referencing, ignore @@ -181,7 +181,7 @@ class SimpleObjectHydrator extends AbstractHydrator return null; } - // TODO: Decide what to do with associations. It seems original code is incomplete. + // TODO: Decide what to do with associations. It seems original code is incomplete. // One solution is to load the association, but it might require extra efforts. return array('name' => $column); diff --git a/lib/Doctrine/ORM/Internal/Hydration/SingleScalarHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/SingleScalarHydrator.php index 98a45960e..a5dabc60c 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/SingleScalarHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/SingleScalarHydrator.php @@ -33,24 +33,24 @@ use Doctrine\DBAL\Connection, class SingleScalarHydrator extends AbstractHydrator { /** - * {@inheritdoc} + * {@inheritdoc} */ protected function hydrateAllData() { $data = $this->_stmt->fetchAll(\PDO::FETCH_ASSOC); $numRows = count($data); - + if ($numRows === 0) { throw new NoResultException(); } - + if ($numRows > 1 || count($data[key($data)]) > 1) { throw new NonUniqueResultException(); } - + $cache = array(); $result = $this->gatherScalarRowData($data[key($data)], $cache); - + return array_shift($result); } } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Mapping/Builder/AssociationBuilder.php b/lib/Doctrine/ORM/Mapping/Builder/AssociationBuilder.php index cff4e5d52..843e2ce5d 100644 --- a/lib/Doctrine/ORM/Mapping/Builder/AssociationBuilder.php +++ b/lib/Doctrine/ORM/Mapping/Builder/AssociationBuilder.php @@ -124,7 +124,7 @@ class AssociationBuilder /** * Add Join Columns - * + * * @param string $columnName * @param string $referencedColumnName * @param bool $nullable diff --git a/lib/Doctrine/ORM/Mapping/Builder/ClassMetadataBuilder.php b/lib/Doctrine/ORM/Mapping/Builder/ClassMetadataBuilder.php index 3765fbd93..fb1f1d5e5 100644 --- a/lib/Doctrine/ORM/Mapping/Builder/ClassMetadataBuilder.php +++ b/lib/Doctrine/ORM/Mapping/Builder/ClassMetadataBuilder.php @@ -62,7 +62,7 @@ class ClassMetadataBuilder public function setMappedSuperClass() { $this->cm->isMappedSuperclass = true; - + return $this; } diff --git a/lib/Doctrine/ORM/Mapping/Builder/FieldBuilder.php b/lib/Doctrine/ORM/Mapping/Builder/FieldBuilder.php index 9278a6db0..3f4a5bbaf 100644 --- a/lib/Doctrine/ORM/Mapping/Builder/FieldBuilder.php +++ b/lib/Doctrine/ORM/Mapping/Builder/FieldBuilder.php @@ -170,7 +170,7 @@ class FieldBuilder /** * Set Sequence Generator - * + * * @param string $sequenceName * @param int $allocationSize * @param int $initialValue @@ -188,7 +188,7 @@ class FieldBuilder /** * Set column definition. - * + * * @param string $def * @return FieldBuilder */ diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadata.php b/lib/Doctrine/ORM/Mapping/ClassMetadata.php index 4e31f5578..b6c31c52d 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadata.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadata.php @@ -358,7 +358,7 @@ class ClassMetadata extends ClassMetadataInfo implements IClassMetadata ($this->reflClass->getMethod($callback)->getModifiers() & \ReflectionMethod::IS_PUBLIC) == 0) { throw MappingException::lifecycleCallbackMethodNotFound($this->name, $callback); } - + return parent::addLifecycleCallback($callback, $event); } } diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 8801344ff..bf802ecf9 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -43,7 +43,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface * @var EntityManager */ private $em; - + /** * @var AbstractPlatform */ @@ -73,7 +73,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface * @var bool */ private $initialized = false; - + /** * @param EntityManager $$em */ @@ -101,16 +101,16 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface { return $this->cacheDriver; } - + public function getLoadedMetadata() { return $this->loadedMetadata; } - + /** * Forces the factory to load the metadata of all classes known to the underlying * mapping driver. - * + * * @return array The ClassMetadata instances of all mapped classes. */ public function getAllMetadata() @@ -188,7 +188,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface /** * Checks whether the factory has the metadata for a class loaded already. - * + * * @param string $className * @return boolean TRUE if the metadata of the class in question is already loaded, FALSE otherwise. */ @@ -199,7 +199,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface /** * Sets the metadata descriptor for a specific class. - * + * * NOTE: This is only useful in very special cases, like when generating proxy classes. * * @param string $className @@ -308,11 +308,11 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface if ($parent && $parent->isInheritanceTypeSingleTable()) { $class->setPrimaryTable($parent->table); } - + if ($parent && $parent->containsForeignIdentifier) { $class->containsForeignIdentifier = true; } - + if ($parent && !empty ($parent->namedQueries)) { $this->addInheritedNamedQueries($class, $parent); } @@ -325,7 +325,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface } $this->validateRuntimeMetadata($class, $parent); - + $this->loadedMetadata[$className] = $class; $parent = $class; @@ -436,10 +436,10 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface $subClass->addInheritedAssociationMapping($mapping); } } - + /** * Adds inherited named queries to the subclass mapping. - * + * * @since 2.2 * @param \Doctrine\ORM\Mapping\ClassMetadata $subClass * @param \Doctrine\ORM\Mapping\ClassMetadata $parentClass @@ -524,13 +524,13 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface if ( ! $this->initialized) { $this->initialize(); } - + // Check for namespace alias if (strpos($class, ':') !== false) { list($namespaceAlias, $simpleClassName) = explode(':', $class); $class = $this->em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName; } - + return $this->driver->isTransient($class); } } diff --git a/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php index a92432db8..6953bf2d1 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php @@ -25,7 +25,7 @@ use Doctrine\ORM\Mapping\MappingException; /** * Base driver for file-based metadata drivers. - * + * * A file driver operates in a mode where it loads the mapping files of individual * classes on demand. This requires the user to adhere to the convention of 1 mapping * file per class and the file names of the mapping files must correspond to the full @@ -56,16 +56,16 @@ abstract class AbstractFileDriver implements Driver */ protected $_fileExtension; - /** - * Initializes a new FileDriver that looks in the given path(s) for mapping - * documents and operates in the specified operating mode. - * - * @param string|array $paths One or multiple paths where mapping documents can be found. - */ - public function __construct($paths) - { + /** + * Initializes a new FileDriver that looks in the given path(s) for mapping + * documents and operates in the specified operating mode. + * + * @param string|array $paths One or multiple paths where mapping documents can be found. + */ + public function __construct($paths) + { $this->addPaths((array) $paths); - } + } /** * Append lookup paths to metadata driver. @@ -117,7 +117,7 @@ abstract class AbstractFileDriver implements Driver public function getElement($className) { $result = $this->_loadMappingFile($this->_findMappingFile($className)); - + if(!isset($result[$className])){ throw MappingException::invalidMappingFile($className, str_replace('\\', '.', $className) . $this->_fileExtension); } @@ -148,7 +148,7 @@ abstract class AbstractFileDriver implements Driver /** * Gets the names of all mapped classes known to this driver. - * + * * @return array The names of all mapped classes known to this driver. */ public function getAllClassNames() @@ -160,23 +160,23 @@ abstract class AbstractFileDriver implements Driver if ( ! is_dir($path)) { throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath($path); } - + $iterator = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator($path), \RecursiveIteratorIterator::LEAVES_ONLY ); - + foreach ($iterator as $file) { if (($fileName = $file->getBasename($this->_fileExtension)) == $file->getBasename()) { continue; } - + // NOTE: All files found here means classes are not transient! $classes[] = str_replace('.', '\\', $fileName); } } } - + return $classes; } @@ -191,7 +191,7 @@ abstract class AbstractFileDriver implements Driver protected function _findMappingFile($className) { $fileName = str_replace('\\', '.', $className) . $this->_fileExtension; - + // Check whether file exists foreach ((array) $this->_paths as $path) { if (file_exists($path . DIRECTORY_SEPARATOR . $fileName)) { @@ -205,7 +205,7 @@ abstract class AbstractFileDriver implements Driver /** * Loads a mapping file with the given name and returns a map * from class/entity names to their corresponding elements. - * + * * @param string $file The mapping file to load. * @return array */ diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index bee84159f..bcd453508 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -99,7 +99,7 @@ class AnnotationDriver implements Driver /** * Retrieve the current annotation reader - * + * * @return AnnotationReader */ public function getReader() @@ -519,15 +519,15 @@ class AnnotationDriver implements Driver new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::LEAVES_ONLY ), - '/^.+' . str_replace('.', '\.', $this->_fileExtension) . '$/i', + '/^.+' . str_replace('.', '\.', $this->_fileExtension) . '$/i', \RecursiveRegexIterator::GET_MATCH ); - + foreach ($iterator as $file) { $sourceFile = realpath($file[0]); - + require_once $sourceFile; - + $includedFiles[] = $sourceFile; } } diff --git a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php index c2d9240a2..2b73ed9fb 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php @@ -76,7 +76,7 @@ class DatabaseDriver implements Driver /** * Initializes a new AnnotationDriver that uses the given AnnotationReader for reading * docblock annotations. - * + * * @param AnnotationReader $reader The AnnotationReader to use. */ public function __construct(AbstractSchemaManager $schemaManager) @@ -111,7 +111,7 @@ class DatabaseDriver implements Driver } $tables = array(); - + foreach ($this->_sm->listTableNames() as $tableName) { $tables[$tableName] = $this->_sm->listTableDetails($tableName); } @@ -129,7 +129,7 @@ class DatabaseDriver implements Driver foreach ($foreignKeys AS $foreignKey) { $allForeignKeyColumns = array_merge($allForeignKeyColumns, $foreignKey->getLocalColumns()); } - + $pkColumns = $table->getPrimaryKey()->getColumns(); sort($pkColumns); sort($allForeignKeyColumns); @@ -145,7 +145,7 @@ class DatabaseDriver implements Driver } } } - + /** * {@inheritdoc} */ @@ -169,7 +169,7 @@ class DatabaseDriver implements Driver } catch(SchemaException $e) { $primaryKeyColumns = array(); } - + if ($this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) { $foreignKeys = $this->tables[$tableName]->getForeignKeys(); } else { diff --git a/lib/Doctrine/ORM/Mapping/Driver/Driver.php b/lib/Doctrine/ORM/Mapping/Driver/Driver.php index b6cfe36b4..28654a82b 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/Driver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/Driver.php @@ -34,18 +34,18 @@ interface Driver { /** * Loads the metadata for the specified class into the provided container. - * + * * @param string $className * @param ClassMetadataInfo $metadata */ function loadMetadataForClass($className, ClassMetadataInfo $metadata); - + /** * Gets the names of all mapped classes known to this driver. - * + * * @return array The names of all mapped classes known to this driver. */ - function getAllClassNames(); + function getAllClassNames(); /** * Whether the class with the specified name should have its metadata loaded. diff --git a/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php b/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php index d84d2344b..321962d2c 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php @@ -94,7 +94,7 @@ class DriverChain implements Driver if (!isset($driverClasses[$oid])) { $driverClasses[$oid] = $driver->getAllClassNames(); } - + foreach ($driverClasses[$oid] AS $className) { if (strpos($className, $namespace) === 0) { $classNames[$className] = true; diff --git a/lib/Doctrine/ORM/Mapping/Driver/StaticPHPDriver.php b/lib/Doctrine/ORM/Mapping/Driver/StaticPHPDriver.php index 916113c1d..4e593ea8c 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/StaticPHPDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/StaticPHPDriver.php @@ -38,21 +38,21 @@ class StaticPHPDriver implements Driver { /** * Paths of entity directories. - * + * * @var array */ private $_paths = array(); - + /** * Map of all class names. - * + * * @var array */ private $_classNames; - + /** * The file extension of mapping documents. - * + * * @var string */ private $_fileExtension = '.php'; diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 5785ccf2c..7308a23e3 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -232,7 +232,7 @@ class XmlDriver extends AbstractFileDriver if (isset($idElement['column'])) { $mapping['columnName'] = (string)$idElement['column']; } - + if (isset($idElement['column-definition'])) { $mapping['columnDefinition'] = (string)$idElement['column-definition']; } diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index 4ef66f9f8..a65b6fb2f 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -181,7 +181,7 @@ class YamlDriver extends AbstractFileDriver if (isset($idElement['length'])) { $mapping['length'] = $idElement['length']; } - + if (isset($idElement['columnDefinition'])) { $mapping['columnDefinition'] = $idElement['columnDefinition']; } diff --git a/lib/Doctrine/ORM/Mapping/MappingException.php b/lib/Doctrine/ORM/Mapping/MappingException.php index cdc856381..babf4c98e 100644 --- a/lib/Doctrine/ORM/Mapping/MappingException.php +++ b/lib/Doctrine/ORM/Mapping/MappingException.php @@ -67,7 +67,7 @@ class MappingException extends \Doctrine\ORM\ORMException { return new self("No mapping file found named '$fileName' for class '$entityName'."); } - + public static function invalidMappingFile($entityName, $fileName) { return new self("Invalid mapping file '$fileName' for class '$entityName'."); diff --git a/lib/Doctrine/ORM/NoResultException.php b/lib/Doctrine/ORM/NoResultException.php index 80f08bb93..eb31f7cc9 100644 --- a/lib/Doctrine/ORM/NoResultException.php +++ b/lib/Doctrine/ORM/NoResultException.php @@ -21,7 +21,7 @@ namespace Doctrine\ORM; /** * Exception thrown when an ORM query unexpectedly does not return any results. - * + * * @author robo * @since 2.0 */ diff --git a/lib/Doctrine/ORM/NonUniqueResultException.php b/lib/Doctrine/ORM/NonUniqueResultException.php index 811df75c1..1a3a8b7eb 100644 --- a/lib/Doctrine/ORM/NonUniqueResultException.php +++ b/lib/Doctrine/ORM/NonUniqueResultException.php @@ -21,7 +21,7 @@ namespace Doctrine\ORM; /** * Exception thrown when an ORM query unexpectedly returns more than one result. - * + * * @author robo * @since 2.0 */ diff --git a/lib/Doctrine/ORM/ORMException.php b/lib/Doctrine/ORM/ORMException.php index 0e36217d9..bd16839f3 100644 --- a/lib/Doctrine/ORM/ORMException.php +++ b/lib/Doctrine/ORM/ORMException.php @@ -144,7 +144,7 @@ class ORMException extends Exception return new self("Invalid repository class '".$className."'. ". "it must be a Doctrine\ORM\EntityRepository."); } - + public static function missingIdentifierField($className, $fieldName) { return new self("The identifier $fieldName is missing for a query of " . $className); diff --git a/lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php b/lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php index 3ee81f0d4..7f8c40b09 100644 --- a/lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php +++ b/lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php @@ -65,11 +65,11 @@ abstract class AbstractCollectionPersister public function delete(PersistentCollection $coll) { $mapping = $coll->getMapping(); - + if ( ! $mapping['isOwningSide']) { return; // ignore inverse side } - + $sql = $this->_getDeleteSQL($coll); $this->_conn->executeUpdate($sql, $this->_getDeleteSQLParameters($coll)); } @@ -98,34 +98,34 @@ abstract class AbstractCollectionPersister public function update(PersistentCollection $coll) { $mapping = $coll->getMapping(); - + if ( ! $mapping['isOwningSide']) { return; // ignore inverse side } - + $this->deleteRows($coll); //$this->updateRows($coll); $this->insertRows($coll); } - + public function deleteRows(PersistentCollection $coll) - { + { $deleteDiff = $coll->getDeleteDiff(); $sql = $this->_getDeleteRowSQL($coll); - + foreach ($deleteDiff as $element) { $this->_conn->executeUpdate($sql, $this->_getDeleteRowSQLParameters($coll, $element)); } } - + //public function updateRows(PersistentCollection $coll) //{} - + public function insertRows(PersistentCollection $coll) { $insertDiff = $coll->getInsertDiff(); $sql = $this->_getInsertRowSQL($coll); - + foreach ($insertDiff as $element) { $this->_conn->executeUpdate($sql, $this->_getInsertRowSQLParameters($coll, $element)); } @@ -168,7 +168,7 @@ abstract class AbstractCollectionPersister /** * Gets the SQL statement used for deleting a row from the collection. - * + * * @param PersistentCollection $coll */ abstract protected function _getDeleteRowSQL(PersistentCollection $coll); diff --git a/lib/Doctrine/ORM/Persisters/AbstractEntityInheritancePersister.php b/lib/Doctrine/ORM/Persisters/AbstractEntityInheritancePersister.php index e3bb9a943..191c07798 100644 --- a/lib/Doctrine/ORM/Persisters/AbstractEntityInheritancePersister.php +++ b/lib/Doctrine/ORM/Persisters/AbstractEntityInheritancePersister.php @@ -26,7 +26,7 @@ use Doctrine\ORM\Mapping\ClassMetadata, * Base class for entity persisters that implement a certain inheritance mapping strategy. * All these persisters are assumed to use a discriminator column to discriminate entity * types in the hierarchy. - * + * * @author Roman Borschel * @author Benjamin Eberlei * @since 2.0 @@ -39,18 +39,18 @@ abstract class AbstractEntityInheritancePersister extends BasicEntityPersister protected function _prepareInsertData($entity) { $data = parent::_prepareInsertData($entity); - + // Populate the discriminator column $discColumn = $this->_class->discriminatorColumn; $this->_columnTypes[$discColumn['name']] = $discColumn['type']; $data[$this->_getDiscriminatorColumnTableName()][$discColumn['name']] = $this->_class->discriminatorValue; - + return $data; } /** * Gets the name of the table that contains the discriminator column. - * + * * @return string The table name. */ abstract protected function _getDiscriminatorColumnTableName(); @@ -77,7 +77,7 @@ abstract class AbstractEntityInheritancePersister extends BasicEntityPersister { $columnAlias = $this->getSQLColumnAlias($joinColumnName); $this->_rsm->addMetaResult('r', $columnAlias, $joinColumnName); - + return $tableAlias . '.' . $joinColumnName . ' AS ' . $columnAlias; } } diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 6845d984a..d2f1b4661 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -341,7 +341,7 @@ class BasicEntityPersister foreach ($updateData as $columnName => $value) { $column = $columnName; $placeholder = '?'; - + if (isset($this->_class->fieldNames[$columnName])) { $column = $this->_class->getQuotedColumnName($this->_class->fieldNames[$columnName], $this->_platform); @@ -1307,7 +1307,7 @@ class BasicEntityPersister foreach ($criteria as $field => $value) { $conditionSql .= $conditionSql ? ' AND ' : ''; - + $placeholder = '?'; if (isset($this->_class->columnNames[$field])) { diff --git a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php index 2d9105709..34498a325 100644 --- a/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php @@ -44,8 +44,8 @@ class ManyToManyPersister extends AbstractCollectionPersister { $mapping = $coll->getMapping(); $class = $this->_em->getClassMetadata(get_class($coll->getOwner())); - - return 'DELETE FROM ' . $class->getQuotedJoinTableName($mapping, $this->_conn->getDatabasePlatform()) + + return 'DELETE FROM ' . $class->getQuotedJoinTableName($mapping, $this->_conn->getDatabasePlatform()) . ' WHERE ' . implode(' = ? AND ', $mapping['joinTableColumns']) . ' = ?'; } @@ -81,9 +81,9 @@ class ManyToManyPersister extends AbstractCollectionPersister $mapping = $coll->getMapping(); $columns = $mapping['joinTableColumns']; $class = $this->_em->getClassMetadata(get_class($coll->getOwner())); - + $joinTable = $class->getQuotedJoinTableName($mapping, $this->_conn->getDatabasePlatform()); - + return 'INSERT INTO ' . $joinTable . ' (' . implode(', ', $columns) . ')' . ' VALUES (' . implode(', ', array_fill(0, count($columns), '?')) . ')'; } @@ -124,19 +124,19 @@ class ManyToManyPersister extends AbstractCollectionPersister foreach ($mapping['joinTableColumns'] as $joinTableColumn) { $isRelationToSource = isset($mapping['relationToSourceKeyColumns'][$joinTableColumn]); - + if ( ! $isComposite) { $params[] = $isRelationToSource ? array_pop($identifier1) : array_pop($identifier2); - + continue; } - + if ($isRelationToSource) { $params[] = $identifier1[$class1->getFieldForColumn($mapping['relationToSourceKeyColumns'][$joinTableColumn])]; - + continue; } - + $params[] = $identifier2[$class2->getFieldForColumn($mapping['relationToTargetKeyColumns'][$joinTableColumn])]; } @@ -152,8 +152,8 @@ class ManyToManyPersister extends AbstractCollectionPersister { $class = $this->_em->getClassMetadata(get_class($coll->getOwner())); $mapping = $coll->getMapping(); - - return 'DELETE FROM ' . $class->getQuotedJoinTableName($mapping, $this->_conn->getDatabasePlatform()) + + return 'DELETE FROM ' . $class->getQuotedJoinTableName($mapping, $this->_conn->getDatabasePlatform()) . ' WHERE ' . implode(' = ? AND ', array_keys($mapping['relationToSourceKeyColumns'])) . ' = ?'; } @@ -169,21 +169,21 @@ class ManyToManyPersister extends AbstractCollectionPersister $identifier = $this->_uow->getEntityIdentifier($coll->getOwner()); $mapping = $coll->getMapping(); $params = array(); - + // Optimization for single column identifier if (count($mapping['relationToSourceKeyColumns']) === 1) { $params[] = array_pop($identifier); - + return $params; } - + // Composite identifier $sourceClass = $this->_em->getClassMetadata(get_class($mapping->getOwner())); - + foreach ($mapping['relationToSourceKeyColumns'] as $relColumn => $srcColumn) { $params[] = $identifier[$sourceClass->fieldNames[$srcColumn]]; } - + return $params; } @@ -205,12 +205,12 @@ class ManyToManyPersister extends AbstractCollectionPersister $whereClauses = array(); $params = array(); - + foreach ($mapping['joinTableColumns'] as $joinTableColumn) { if ( ! isset($joinColumns[$joinTableColumn])) { continue; } - + $whereClauses[] = $joinTableColumn . ' = ?'; $params[] = ($class->containsForeignIdentifier) @@ -240,7 +240,7 @@ class ManyToManyPersister extends AbstractCollectionPersister public function slice(PersistentCollection $coll, $offset, $length = null) { $mapping = $coll->getMapping(); - + return $this->_em->getUnitOfWork()->getEntityPersister($mapping['targetEntity'])->getManyToManyCollection($mapping, $coll->getOwner(), $offset, $length); } @@ -259,12 +259,12 @@ class ManyToManyPersister extends AbstractCollectionPersister } list($quotedJoinTable, $whereClauses, $params) = $this->getJoinTableRestrictions($coll, $element, true); - + $sql = 'SELECT 1 FROM ' . $quotedJoinTable . ' WHERE ' . implode(' AND ', $whereClauses); return (bool) $this->_conn->fetchColumn($sql, $params); } - + /** * @param PersistentCollection $coll * @param object $element @@ -282,10 +282,10 @@ class ManyToManyPersister extends AbstractCollectionPersister list($quotedJoinTable, $whereClauses, $params) = $this->getJoinTableRestrictions($coll, $element, false); $sql = 'DELETE FROM ' . $quotedJoinTable . ' WHERE ' . implode(' AND ', $whereClauses); - + return (bool) $this->_conn->executeUpdate($sql, $params); } - + /** * @param \Doctrine\ORM\PersistentCollection $coll * @param object $element @@ -296,13 +296,13 @@ class ManyToManyPersister extends AbstractCollectionPersister { $uow = $this->_em->getUnitOfWork(); $mapping = $coll->getMapping(); - + if ( ! $mapping['isOwningSide']) { $sourceClass = $this->_em->getClassMetadata($mapping['targetEntity']); $targetClass = $this->_em->getClassMetadata($mapping['sourceEntity']); $sourceId = $uow->getEntityIdentifier($element); $targetId = $uow->getEntityIdentifier($coll->getOwner()); - + $mapping = $sourceClass->associationMappings[$mapping['mappedBy']]; } else { $sourceClass = $this->_em->getClassMetadata($mapping['sourceEntity']); @@ -310,11 +310,11 @@ class ManyToManyPersister extends AbstractCollectionPersister $sourceId = $uow->getEntityIdentifier($coll->getOwner()); $targetId = $uow->getEntityIdentifier($element); } - + $quotedJoinTable = $sourceClass->getQuotedJoinTableName($mapping, $this->_conn->getDatabasePlatform()); $whereClauses = array(); $params = array(); - + foreach ($mapping['joinTableColumns'] as $joinTableColumn) { $whereClauses[] = $joinTableColumn . ' = ?'; @@ -324,7 +324,7 @@ class ManyToManyPersister extends AbstractCollectionPersister : $targetId[$targetClass->fieldNames[$mapping['relationToTargetKeyColumns'][$joinTableColumn]]]; continue; } - + // relationToSourceKeyColumns $params[] = ($sourceClass->containsForeignIdentifier) ? $sourceId[$sourceClass->getFieldForColumn($mapping['relationToSourceKeyColumns'][$joinTableColumn])] @@ -338,7 +338,7 @@ class ManyToManyPersister extends AbstractCollectionPersister $whereClauses[] = $filterSql; } } - + return array($quotedJoinTable, $whereClauses, $params); } diff --git a/lib/Doctrine/ORM/Persisters/OneToManyPersister.php b/lib/Doctrine/ORM/Persisters/OneToManyPersister.php index b78d0e561..c4efd8c2e 100644 --- a/lib/Doctrine/ORM/Persisters/OneToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/OneToManyPersister.php @@ -44,14 +44,14 @@ class OneToManyPersister extends AbstractCollectionPersister { $mapping = $coll->getMapping(); $class = $this->_em->getClassMetadata($mapping['targetEntity']); - + return 'DELETE FROM ' . $class->getQuotedTableName($this->_conn->getDatabasePlatform()) . ' WHERE ' . implode('= ? AND ', $class->getIdentifierColumnNames()) . ' = ?'; } /** * {@inheritdoc} - * + * */ protected function _getDeleteRowSQLParameters(PersistentCollection $coll, $element) { @@ -110,10 +110,10 @@ class OneToManyPersister extends AbstractCollectionPersister $whereClauses = array(); $params = array(); - + foreach ($targetClass->associationMappings[$mapping['mappedBy']]['joinColumns'] AS $joinColumn) { $whereClauses[] = $joinColumn['name'] . ' = ?'; - + $params[] = ($targetClass->containsForeignIdentifier) ? $id[$sourceClass->getFieldForColumn($joinColumn['referencedColumnName'])] : $id[$sourceClass->fieldNames[$joinColumn['referencedColumnName']]]; @@ -143,7 +143,7 @@ class OneToManyPersister extends AbstractCollectionPersister $mapping = $coll->getMapping(); $uow = $this->_em->getUnitOfWork(); $persister = $uow->getEntityPersister($mapping['targetEntity']); - + return $persister->getOneToManyCollection($mapping, $coll->getOwner(), $offset, $length); } @@ -156,22 +156,22 @@ class OneToManyPersister extends AbstractCollectionPersister { $mapping = $coll->getMapping(); $uow = $this->_em->getUnitOfWork(); - + // shortcut for new entities if ($uow->getEntityState($element, UnitOfWork::STATE_NEW) == UnitOfWork::STATE_NEW) { return false; } $persister = $uow->getEntityPersister($mapping['targetEntity']); - - // only works with single id identifier entities. Will throw an - // exception in Entity Persisters if that is not the case for the + + // only works with single id identifier entities. Will throw an + // exception in Entity Persisters if that is not the case for the // 'mappedBy' field. $id = current( $uow->getEntityIdentifier($coll->getOwner()) ); return $persister->exists($element, array($mapping['mappedBy'] => $id)); } - + /** * @param PersistentCollection $coll * @param object $element @@ -190,7 +190,7 @@ class OneToManyPersister extends AbstractCollectionPersister $class = $this->_em->getClassMetadata($mapping['targetEntity']); $sql = 'DELETE FROM ' . $class->getQuotedTableName($this->_conn->getDatabasePlatform()) . ' WHERE ' . implode('= ? AND ', $class->getIdentifierColumnNames()) . ' = ?'; - + return (bool) $this->_conn->executeUpdate($sql, $this->_getDeleteRowSQLParameters($coll, $element)); } } diff --git a/lib/Doctrine/ORM/Persisters/SingleTablePersister.php b/lib/Doctrine/ORM/Persisters/SingleTablePersister.php index c2687c109..171264a1d 100644 --- a/lib/Doctrine/ORM/Persisters/SingleTablePersister.php +++ b/lib/Doctrine/ORM/Persisters/SingleTablePersister.php @@ -51,33 +51,33 @@ class SingleTablePersister extends AbstractEntityInheritancePersister // Append discriminator column $discrColumn = $this->_class->discriminatorColumn['name']; $columnList .= ', ' . $discrColumn; - + $rootClass = $this->_em->getClassMetadata($this->_class->rootEntityName); $tableAlias = $this->_getSQLTableAlias($rootClass->name); $resultColumnName = $this->_platform->getSQLResultCasing($discrColumn); - + $this->_rsm->setDiscriminatorColumn('r', $resultColumnName); $this->_rsm->addMetaResult('r', $resultColumnName, $discrColumn); // Append subclass columns foreach ($this->_class->subClasses as $subClassName) { $subClass = $this->_em->getClassMetadata($subClassName); - + // Regular columns foreach ($subClass->fieldMappings as $fieldName => $mapping) { if ( ! isset($mapping['inherited'])) { $columnList .= ', ' . $this->_getSelectColumnSQL($fieldName, $subClass); } } - + // Foreign key columns foreach ($subClass->associationMappings as $assoc) { if ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE && ! isset($assoc['inherited'])) { foreach ($assoc['targetToSourceKeyColumns'] as $srcColumn) { if ($columnList != '') $columnList .= ', '; - + $columnList .= $this->getSelectJoinColumnSQL( - $tableAlias, + $tableAlias, $srcColumn, isset($assoc['inherited']) ? $assoc['inherited'] : $this->_class->name ); @@ -94,7 +94,7 @@ class SingleTablePersister extends AbstractEntityInheritancePersister protected function _getInsertColumnList() { $columns = parent::_getInsertColumnList(); - + // Add discriminator column to the INSERT SQL $columns[] = $this->_class->discriminatorColumn['name']; @@ -114,19 +114,19 @@ class SingleTablePersister extends AbstractEntityInheritancePersister // Append discriminator condition if ($conditionSql) $conditionSql .= ' AND '; - + $values = array(); - + if ($this->_class->discriminatorValue !== null) { // discriminators can be 0 $values[] = $this->_conn->quote($this->_class->discriminatorValue); } $discrValues = array_flip($this->_class->discriminatorMap); - + foreach ($this->_class->subClasses as $subclassName) { $values[] = $this->_conn->quote($discrValues[$subclassName]); } - + $conditionSql .= $this->_getSQLTableAlias($this->_class->name) . '.' . $this->_class->discriminatorColumn['name'] . ' IN (' . implode(', ', $values) . ')'; diff --git a/lib/Doctrine/ORM/Persisters/UnionSubclassPersister.php b/lib/Doctrine/ORM/Persisters/UnionSubclassPersister.php index b2e683a27..ef844a706 100644 --- a/lib/Doctrine/ORM/Persisters/UnionSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/UnionSubclassPersister.php @@ -4,5 +4,5 @@ namespace Doctrine\ORM\Persisters; class UnionSubclassPersister extends BasicEntityPersister { - + } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Proxy/Proxy.php b/lib/Doctrine/ORM/Proxy/Proxy.php index 853f9c1f0..5eaff19fe 100644 --- a/lib/Doctrine/ORM/Proxy/Proxy.php +++ b/lib/Doctrine/ORM/Proxy/Proxy.php @@ -23,7 +23,7 @@ namespace Doctrine\ORM\Proxy; /** * Interface for proxy classes. - * + * * @author Roman Borschel * @since 2.0 */ diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index 252f9fa32..ff3f8426e 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -640,7 +640,7 @@ final class Query extends AbstractQuery public function __clone() { parent::__clone(); - + $this->_state = self::STATE_DIRTY; } } diff --git a/lib/Doctrine/ORM/Query/AST/ArithmeticFactor.php b/lib/Doctrine/ORM/Query/AST/ArithmeticFactor.php index b559e4a30..3ad6abf47 100644 --- a/lib/Doctrine/ORM/Query/AST/ArithmeticFactor.php +++ b/lib/Doctrine/ORM/Query/AST/ArithmeticFactor.php @@ -38,7 +38,7 @@ class ArithmeticFactor extends Node * @var ArithmeticPrimary */ public $arithmeticPrimary; - + /** * @var null|boolean NULL represents no sign, TRUE means positive and FALSE means negative sign */ diff --git a/lib/Doctrine/ORM/Query/AST/CoalesceExpression.php b/lib/Doctrine/ORM/Query/AST/CoalesceExpression.php index 338d49fce..dae074200 100644 --- a/lib/Doctrine/ORM/Query/AST/CoalesceExpression.php +++ b/lib/Doctrine/ORM/Query/AST/CoalesceExpression.php @@ -33,13 +33,13 @@ namespace Doctrine\ORM\Query\AST; class CoalesceExpression extends Node { public $scalarExpressions = array(); - + public function __construct(array $scalarExpressions) { $this->scalarExpressions = $scalarExpressions; - } - + } + public function dispatch($sqlWalker) { return $sqlWalker->walkCoalesceExpression($this); diff --git a/lib/Doctrine/ORM/Query/AST/CollectionMemberExpression.php b/lib/Doctrine/ORM/Query/AST/CollectionMemberExpression.php index ea252de08..62d756b88 100644 --- a/lib/Doctrine/ORM/Query/AST/CollectionMemberExpression.php +++ b/lib/Doctrine/ORM/Query/AST/CollectionMemberExpression.php @@ -18,7 +18,7 @@ * and is licensed under the LGPL. For more information, see * . */ - + namespace Doctrine\ORM\Query\AST; /** diff --git a/lib/Doctrine/ORM/Query/AST/DeleteStatement.php b/lib/Doctrine/ORM/Query/AST/DeleteStatement.php index de807abaa..01c6acbe1 100644 --- a/lib/Doctrine/ORM/Query/AST/DeleteStatement.php +++ b/lib/Doctrine/ORM/Query/AST/DeleteStatement.php @@ -41,7 +41,7 @@ class DeleteStatement extends Node { $this->deleteClause = $deleteClause; } - + public function dispatch($sqlWalker) { return $sqlWalker->walkDeleteStatement($this); diff --git a/lib/Doctrine/ORM/Query/AST/EmptyCollectionComparisonExpression.php b/lib/Doctrine/ORM/Query/AST/EmptyCollectionComparisonExpression.php index 271d304dc..6bb50e87d 100644 --- a/lib/Doctrine/ORM/Query/AST/EmptyCollectionComparisonExpression.php +++ b/lib/Doctrine/ORM/Query/AST/EmptyCollectionComparisonExpression.php @@ -18,7 +18,7 @@ * and is licensed under the LGPL. For more information, see * . */ - + namespace Doctrine\ORM\Query\AST; /** diff --git a/lib/Doctrine/ORM/Query/AST/FromClause.php b/lib/Doctrine/ORM/Query/AST/FromClause.php index 83aa85ccb..a4dc6282d 100644 --- a/lib/Doctrine/ORM/Query/AST/FromClause.php +++ b/lib/Doctrine/ORM/Query/AST/FromClause.php @@ -36,8 +36,8 @@ class FromClause extends Node public function __construct(array $identificationVariableDeclarations) { $this->identificationVariableDeclarations = $identificationVariableDeclarations; - } - + } + public function dispatch($sqlWalker) { return $sqlWalker->walkFromClause($this); diff --git a/lib/Doctrine/ORM/Query/AST/Functions/AbsFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/AbsFunction.php index 3fafccd5b..3ee436035 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/AbsFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/AbsFunction.php @@ -53,9 +53,9 @@ class AbsFunction extends FunctionNode { $parser->match(Lexer::T_IDENTIFIER); $parser->match(Lexer::T_OPEN_PARENTHESIS); - + $this->simpleArithmeticExpression = $parser->SimpleArithmeticExpression(); - + $parser->match(Lexer::T_CLOSE_PARENTHESIS); } } diff --git a/lib/Doctrine/ORM/Query/AST/Functions/CurrentDateFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/CurrentDateFunction.php index 7bf7683eb..66107cc00 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/CurrentDateFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/CurrentDateFunction.php @@ -16,7 +16,7 @@ * and is licensed under the LGPL. For more information, see * . */ - + namespace Doctrine\ORM\Query\AST\Functions; use Doctrine\ORM\Query\Lexer; diff --git a/lib/Doctrine/ORM/Query/AST/Functions/IdentityFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/IdentityFunction.php index 10c7982c5..1b7592990 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/IdentityFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/IdentityFunction.php @@ -42,13 +42,13 @@ class IdentityFunction extends FunctionNode $platform = $sqlWalker->getConnection()->getDatabasePlatform(); $dqlAlias = $this->pathExpression->identificationVariable; $assocField = $this->pathExpression->field; - + $qComp = $sqlWalker->getQueryComponent($dqlAlias); $class = $qComp['metadata']; $assoc = $class->associationMappings[$assocField]; - + $tableAlias = $sqlWalker->getSQLTableAlias($class->getTableName(), $dqlAlias); - + return $tableAlias . '.' . reset($assoc['targetToSourceKeyColumns']);; } @@ -59,9 +59,9 @@ class IdentityFunction extends FunctionNode { $parser->match(Lexer::T_IDENTIFIER); $parser->match(Lexer::T_OPEN_PARENTHESIS); - + $this->pathExpression = $parser->SingleValuedAssociationPathExpression(); - + $parser->match(Lexer::T_CLOSE_PARENTHESIS); } } diff --git a/lib/Doctrine/ORM/Query/AST/Functions/LengthFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/LengthFunction.php index 36787786d..82dd4b49d 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/LengthFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/LengthFunction.php @@ -53,9 +53,9 @@ class LengthFunction extends FunctionNode { $parser->match(Lexer::T_IDENTIFIER); $parser->match(Lexer::T_OPEN_PARENTHESIS); - + $this->stringPrimary = $parser->StringPrimary(); - + $parser->match(Lexer::T_CLOSE_PARENTHESIS); } } diff --git a/lib/Doctrine/ORM/Query/AST/Functions/LocateFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/LocateFunction.php index a4ea71696..e630b2efe 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/LocateFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/LocateFunction.php @@ -61,20 +61,20 @@ class LocateFunction extends FunctionNode { $parser->match(Lexer::T_IDENTIFIER); $parser->match(Lexer::T_OPEN_PARENTHESIS); - + $this->firstStringPrimary = $parser->StringPrimary(); - + $parser->match(Lexer::T_COMMA); - + $this->secondStringPrimary = $parser->StringPrimary(); - + $lexer = $parser->getLexer(); if ($lexer->isNextToken(Lexer::T_COMMA)) { $parser->match(Lexer::T_COMMA); - + $this->simpleArithmeticExpression = $parser->SimpleArithmeticExpression(); } - + $parser->match(Lexer::T_CLOSE_PARENTHESIS); } } diff --git a/lib/Doctrine/ORM/Query/AST/Functions/LowerFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/LowerFunction.php index 775f51d9a..7bc092dad 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/LowerFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/LowerFunction.php @@ -53,9 +53,9 @@ class LowerFunction extends FunctionNode { $parser->match(Lexer::T_IDENTIFIER); $parser->match(Lexer::T_OPEN_PARENTHESIS); - + $this->stringPrimary = $parser->StringPrimary(); - + $parser->match(Lexer::T_CLOSE_PARENTHESIS); } } diff --git a/lib/Doctrine/ORM/Query/AST/Functions/ModFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/ModFunction.php index 4d124fe85..53f064a90 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/ModFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/ModFunction.php @@ -55,13 +55,13 @@ class ModFunction extends FunctionNode { $parser->match(Lexer::T_MOD); $parser->match(Lexer::T_OPEN_PARENTHESIS); - + $this->firstSimpleArithmeticExpression = $parser->SimpleArithmeticExpression(); - + $parser->match(Lexer::T_COMMA); - + $this->secondSimpleArithmeticExpression = $parser->SimpleArithmeticExpression(); - + $parser->match(Lexer::T_CLOSE_PARENTHESIS); } } diff --git a/lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php index 91e40395a..3decb918e 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/SizeFunction.php @@ -45,7 +45,7 @@ class SizeFunction extends FunctionNode $platform = $sqlWalker->getConnection()->getDatabasePlatform(); $dqlAlias = $this->collectionPathExpression->identificationVariable; $assocField = $this->collectionPathExpression->field; - + $qComp = $sqlWalker->getQueryComponent($dqlAlias); $class = $qComp['metadata']; $assoc = $class->associationMappings[$assocField]; @@ -61,7 +61,7 @@ class SizeFunction extends FunctionNode $owningAssoc = $targetClass->associationMappings[$assoc['mappedBy']]; $first = true; - + foreach ($owningAssoc['targetToSourceKeyColumns'] as $targetColumn => $sourceColumn) { if ($first) $first = false; else $sql .= ' AND '; @@ -100,7 +100,7 @@ class SizeFunction extends FunctionNode . $sourceTableAlias . '.' . $sourceColumnName; } } - + return '(' . $sql . ')'; } @@ -110,12 +110,12 @@ class SizeFunction extends FunctionNode public function parse(\Doctrine\ORM\Query\Parser $parser) { $lexer = $parser->getLexer(); - + $parser->match(Lexer::T_SIZE); $parser->match(Lexer::T_OPEN_PARENTHESIS); - + $this->collectionPathExpression = $parser->CollectionValuedPathExpression(); - + $parser->match(Lexer::T_CLOSE_PARENTHESIS); } } diff --git a/lib/Doctrine/ORM/Query/AST/Functions/SqrtFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/SqrtFunction.php index 02ffa26a7..087b93be1 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/SqrtFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/SqrtFunction.php @@ -52,9 +52,9 @@ class SqrtFunction extends FunctionNode { $parser->match(Lexer::T_IDENTIFIER); $parser->match(Lexer::T_OPEN_PARENTHESIS); - + $this->simpleArithmeticExpression = $parser->SimpleArithmeticExpression(); - + $parser->match(Lexer::T_CLOSE_PARENTHESIS); } } diff --git a/lib/Doctrine/ORM/Query/AST/Functions/SubstringFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/SubstringFunction.php index bfcbdefb3..c0e6223b2 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/SubstringFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/SubstringFunction.php @@ -64,15 +64,15 @@ class SubstringFunction extends FunctionNode $parser->match(Lexer::T_OPEN_PARENTHESIS); $this->stringPrimary = $parser->StringPrimary(); - + $parser->match(Lexer::T_COMMA); - + $this->firstSimpleArithmeticExpression = $parser->SimpleArithmeticExpression(); $lexer = $parser->getLexer(); if ($lexer->isNextToken(Lexer::T_COMMA)) { $parser->match(Lexer::T_COMMA); - + $this->secondSimpleArithmeticExpression = $parser->SimpleArithmeticExpression(); } diff --git a/lib/Doctrine/ORM/Query/AST/Functions/UpperFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/UpperFunction.php index acc8dd8eb..16a0ed816 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/UpperFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/UpperFunction.php @@ -53,9 +53,9 @@ class UpperFunction extends FunctionNode { $parser->match(Lexer::T_IDENTIFIER); $parser->match(Lexer::T_OPEN_PARENTHESIS); - + $this->stringPrimary = $parser->StringPrimary(); - + $parser->match(Lexer::T_CLOSE_PARENTHESIS); } } diff --git a/lib/Doctrine/ORM/Query/AST/GeneralCaseExpression.php b/lib/Doctrine/ORM/Query/AST/GeneralCaseExpression.php index e9e49f070..facacd5fe 100644 --- a/lib/Doctrine/ORM/Query/AST/GeneralCaseExpression.php +++ b/lib/Doctrine/ORM/Query/AST/GeneralCaseExpression.php @@ -20,7 +20,7 @@ namespace Doctrine\ORM\Query\AST; /** - * GeneralCaseExpression ::= "CASE" WhenClause {WhenClause}* "ELSE" ScalarExpression "END" + * GeneralCaseExpression ::= "CASE" WhenClause {WhenClause}* "ELSE" ScalarExpression "END" * * @since 2.2 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL @@ -39,8 +39,8 @@ class GeneralCaseExpression extends Node { $this->whenClauses = $whenClauses; $this->elseScalarExpression = $elseScalarExpression; - } - + } + public function dispatch($sqlWalker) { return $sqlWalker->walkGeneralCaseExpression($this); diff --git a/lib/Doctrine/ORM/Query/AST/IdentificationVariableDeclaration.php b/lib/Doctrine/ORM/Query/AST/IdentificationVariableDeclaration.php index bf168c34b..2f590cc80 100644 --- a/lib/Doctrine/ORM/Query/AST/IdentificationVariableDeclaration.php +++ b/lib/Doctrine/ORM/Query/AST/IdentificationVariableDeclaration.php @@ -44,7 +44,7 @@ class IdentificationVariableDeclaration extends Node $this->indexBy = $indexBy; $this->joinVariableDeclarations = $joinVariableDecls; } - + public function dispatch($sqlWalker) { return $sqlWalker->walkIdentificationVariableDeclaration($this); diff --git a/lib/Doctrine/ORM/Query/AST/IndexBy.php b/lib/Doctrine/ORM/Query/AST/IndexBy.php index b657be70f..16f220630 100644 --- a/lib/Doctrine/ORM/Query/AST/IndexBy.php +++ b/lib/Doctrine/ORM/Query/AST/IndexBy.php @@ -39,8 +39,8 @@ class IndexBy extends Node public function __construct($simpleStateFieldPathExpression) { $this->simpleStateFieldPathExpression = $simpleStateFieldPathExpression; - } - + } + public function dispatch($sqlWalker) { return $sqlWalker->walkIndexBy($this); diff --git a/lib/Doctrine/ORM/Query/AST/InstanceOfExpression.php b/lib/Doctrine/ORM/Query/AST/InstanceOfExpression.php index b586f4812..4f254b578 100644 --- a/lib/Doctrine/ORM/Query/AST/InstanceOfExpression.php +++ b/lib/Doctrine/ORM/Query/AST/InstanceOfExpression.php @@ -36,7 +36,7 @@ class InstanceOfExpression extends Node public $not; public $identificationVariable; public $value; - + public function __construct($identVariable) { $this->identificationVariable = $identVariable; diff --git a/lib/Doctrine/ORM/Query/AST/Join.php b/lib/Doctrine/ORM/Query/AST/Join.php index 310a418a4..084f7d737 100644 --- a/lib/Doctrine/ORM/Query/AST/Join.php +++ b/lib/Doctrine/ORM/Query/AST/Join.php @@ -39,7 +39,7 @@ class Join extends Node const JOIN_TYPE_LEFTOUTER = 2; const JOIN_TYPE_INNER = 3; - public $joinType = self::JOIN_TYPE_INNER; + public $joinType = self::JOIN_TYPE_INNER; public $joinAssociationPathExpression = null; public $aliasIdentificationVariable = null; public $conditionalExpression = null; @@ -50,7 +50,7 @@ class Join extends Node $this->joinAssociationPathExpression = $joinAssocPathExpr; $this->aliasIdentificationVariable = $aliasIdentVar; } - + public function dispatch($sqlWalker) { return $sqlWalker->walkJoin($this); diff --git a/lib/Doctrine/ORM/Query/AST/JoinAssociationPathExpression.php b/lib/Doctrine/ORM/Query/AST/JoinAssociationPathExpression.php index 7f87e52f8..f9300b2ed 100644 --- a/lib/Doctrine/ORM/Query/AST/JoinAssociationPathExpression.php +++ b/lib/Doctrine/ORM/Query/AST/JoinAssociationPathExpression.php @@ -18,7 +18,7 @@ * and is licensed under the LGPL. For more information, see * . */ - + namespace Doctrine\ORM\Query\AST; /** diff --git a/lib/Doctrine/ORM/Query/AST/JoinVariableDeclaration.php b/lib/Doctrine/ORM/Query/AST/JoinVariableDeclaration.php index 687eba38d..7fa956222 100644 --- a/lib/Doctrine/ORM/Query/AST/JoinVariableDeclaration.php +++ b/lib/Doctrine/ORM/Query/AST/JoinVariableDeclaration.php @@ -42,7 +42,7 @@ class JoinVariableDeclaration extends Node $this->join = $join; $this->indexBy = $indexBy; } - + public function dispatch($sqlWalker) { return $sqlWalker->walkJoinVariableDeclaration($this); diff --git a/lib/Doctrine/ORM/Query/AST/Literal.php b/lib/Doctrine/ORM/Query/AST/Literal.php index d3acb9625..426907f6d 100644 --- a/lib/Doctrine/ORM/Query/AST/Literal.php +++ b/lib/Doctrine/ORM/Query/AST/Literal.php @@ -7,16 +7,16 @@ class Literal extends Node const STRING = 1; const BOOLEAN = 2; const NUMERIC = 3; - + public $type; public $value; - + public function __construct($type, $value) { $this->type = $type; $this->value = $value; } - + public function dispatch($walker) { return $walker->walkLiteral($this); diff --git a/lib/Doctrine/ORM/Query/AST/Node.php b/lib/Doctrine/ORM/Query/AST/Node.php index adaf06cae..8ef13c0b5 100644 --- a/lib/Doctrine/ORM/Query/AST/Node.php +++ b/lib/Doctrine/ORM/Query/AST/Node.php @@ -36,16 +36,16 @@ abstract class Node { /** * Double-dispatch method, supposed to dispatch back to the walker. - * + * * Implementation is not mandatory for all nodes. - * + * * @param $walker */ public function dispatch($walker) { throw ASTException::noDispatchForNode($this); } - + /** * Dumps the AST Node into a string representation for information purpose only * @@ -55,36 +55,36 @@ abstract class Node { return $this->dump($this); } - + public function dump($obj) { static $ident = 0; - + $str = ''; - + if ($obj instanceof Node) { $str .= get_class($obj) . '(' . PHP_EOL; $props = get_object_vars($obj); - + foreach ($props as $name => $prop) { $ident += 4; - $str .= str_repeat(' ', $ident) . '"' . $name . '": ' + $str .= str_repeat(' ', $ident) . '"' . $name . '": ' . $this->dump($prop) . ',' . PHP_EOL; $ident -= 4; } - + $str .= str_repeat(' ', $ident) . ')'; } else if (is_array($obj)) { $ident += 4; $str .= 'array('; $some = false; - + foreach ($obj as $k => $v) { - $str .= PHP_EOL . str_repeat(' ', $ident) . '"' + $str .= PHP_EOL . str_repeat(' ', $ident) . '"' . $k . '" => ' . $this->dump($v) . ','; $some = true; } - + $ident -= 4; $str .= ($some ? PHP_EOL . str_repeat(' ', $ident) : '') . ')'; } else if (is_object($obj)) { @@ -92,7 +92,7 @@ abstract class Node } else { $str .= var_export($obj, true); } - + return $str; } } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Query/AST/NullComparisonExpression.php b/lib/Doctrine/ORM/Query/AST/NullComparisonExpression.php index aa205b712..0e64bd2fb 100644 --- a/lib/Doctrine/ORM/Query/AST/NullComparisonExpression.php +++ b/lib/Doctrine/ORM/Query/AST/NullComparisonExpression.php @@ -36,7 +36,7 @@ class NullComparisonExpression extends Node { public $not; public $expression; - + public function __construct($expression) { $this->expression = $expression; diff --git a/lib/Doctrine/ORM/Query/AST/NullIfExpression.php b/lib/Doctrine/ORM/Query/AST/NullIfExpression.php index c79d23a99..12c8c140f 100644 --- a/lib/Doctrine/ORM/Query/AST/NullIfExpression.php +++ b/lib/Doctrine/ORM/Query/AST/NullIfExpression.php @@ -33,15 +33,15 @@ namespace Doctrine\ORM\Query\AST; class NullIfExpression extends Node { public $firstExpression; - + public $secondExpression; public function __construct($firstExpression, $secondExpression) { $this->firstExpression = $firstExpression; $this->secondExpression = $secondExpression; - } - + } + public function dispatch($sqlWalker) { return $sqlWalker->walkNullIfExpression($this); diff --git a/lib/Doctrine/ORM/Query/AST/OrderByItem.php b/lib/Doctrine/ORM/Query/AST/OrderByItem.php index a05bac32b..207cbd369 100644 --- a/lib/Doctrine/ORM/Query/AST/OrderByItem.php +++ b/lib/Doctrine/ORM/Query/AST/OrderByItem.php @@ -36,7 +36,7 @@ class OrderByItem extends Node { public $expression; public $type; - + public function __construct($expression) { $this->expression = $expression; diff --git a/lib/Doctrine/ORM/Query/AST/PartialObjectExpression.php b/lib/Doctrine/ORM/Query/AST/PartialObjectExpression.php index 08fd564f2..d1757d790 100644 --- a/lib/Doctrine/ORM/Query/AST/PartialObjectExpression.php +++ b/lib/Doctrine/ORM/Query/AST/PartialObjectExpression.php @@ -6,7 +6,7 @@ class PartialObjectExpression extends Node { public $identificationVariable; public $partialFieldSet; - + public function __construct($identificationVariable, array $partialFieldSet) { $this->identificationVariable = $identificationVariable; diff --git a/lib/Doctrine/ORM/Query/AST/PathExpression.php b/lib/Doctrine/ORM/Query/AST/PathExpression.php index 45042c2ea..2f78b9c26 100644 --- a/lib/Doctrine/ORM/Query/AST/PathExpression.php +++ b/lib/Doctrine/ORM/Query/AST/PathExpression.php @@ -16,7 +16,7 @@ * and is licensed under the LGPL. For more information, see * . */ - + namespace Doctrine\ORM\Query\AST; /** @@ -27,7 +27,7 @@ namespace Doctrine\ORM\Query\AST; * CollectionValuedPathExpression ::= IdentificationVariable "." CollectionValuedAssociationField * StateField ::= {EmbeddedClassStateField "."}* SimpleStateField * SimpleStateFieldPathExpression ::= IdentificationVariable "." StateField - * + * * @since 2.0 * @author Guilherme Blanco * @author Jonathan Wage @@ -38,19 +38,19 @@ class PathExpression extends Node const TYPE_COLLECTION_VALUED_ASSOCIATION = 2; const TYPE_SINGLE_VALUED_ASSOCIATION = 4; const TYPE_STATE_FIELD = 8; - + public $type; public $expectedType; public $identificationVariable; public $field; - + public function __construct($expectedType, $identificationVariable, $field = null) { $this->expectedType = $expectedType; $this->identificationVariable = $identificationVariable; $this->field = $field; } - + public function dispatch($walker) { return $walker->walkPathExpression($this); diff --git a/lib/Doctrine/ORM/Query/AST/RangeVariableDeclaration.php b/lib/Doctrine/ORM/Query/AST/RangeVariableDeclaration.php index 7a01bdcbe..cf8b18020 100644 --- a/lib/Doctrine/ORM/Query/AST/RangeVariableDeclaration.php +++ b/lib/Doctrine/ORM/Query/AST/RangeVariableDeclaration.php @@ -41,8 +41,8 @@ class RangeVariableDeclaration extends Node { $this->abstractSchemaName = $abstractSchemaName; $this->aliasIdentificationVariable = $aliasIdentificationVar; - } - + } + public function dispatch($walker) { return $walker->walkRangeVariableDeclaration($this); diff --git a/lib/Doctrine/ORM/Query/AST/SelectClause.php b/lib/Doctrine/ORM/Query/AST/SelectClause.php index ed9fbaa34..cf8e9df30 100644 --- a/lib/Doctrine/ORM/Query/AST/SelectClause.php +++ b/lib/Doctrine/ORM/Query/AST/SelectClause.php @@ -42,7 +42,7 @@ class SelectClause extends Node $this->isDistinct = $isDistinct; $this->selectExpressions = $selectExpressions; } - + public function dispatch($sqlWalker) { return $sqlWalker->walkSelectClause($this); diff --git a/lib/Doctrine/ORM/Query/AST/SelectExpression.php b/lib/Doctrine/ORM/Query/AST/SelectExpression.php index e3c917200..fd0d49b28 100644 --- a/lib/Doctrine/ORM/Query/AST/SelectExpression.php +++ b/lib/Doctrine/ORM/Query/AST/SelectExpression.php @@ -44,8 +44,8 @@ class SelectExpression extends Node $this->expression = $expression; $this->fieldIdentificationVariable = $fieldIdentificationVariable; $this->hiddenAliasResultVariable = $hiddenAliasResultVariable; - } - + } + public function dispatch($sqlWalker) { return $sqlWalker->walkSelectExpression($this); diff --git a/lib/Doctrine/ORM/Query/AST/SelectStatement.php b/lib/Doctrine/ORM/Query/AST/SelectStatement.php index 01eed37d0..d65a97bef 100644 --- a/lib/Doctrine/ORM/Query/AST/SelectStatement.php +++ b/lib/Doctrine/ORM/Query/AST/SelectStatement.php @@ -44,8 +44,8 @@ class SelectStatement extends Node public function __construct($selectClause, $fromClause) { $this->selectClause = $selectClause; $this->fromClause = $fromClause; - } - + } + public function dispatch($sqlWalker) { return $sqlWalker->walkSelectStatement($this); diff --git a/lib/Doctrine/ORM/Query/AST/SimpleCaseExpression.php b/lib/Doctrine/ORM/Query/AST/SimpleCaseExpression.php index 9fd5e22ee..586928df3 100644 --- a/lib/Doctrine/ORM/Query/AST/SimpleCaseExpression.php +++ b/lib/Doctrine/ORM/Query/AST/SimpleCaseExpression.php @@ -20,7 +20,7 @@ namespace Doctrine\ORM\Query\AST; /** - * SimpleCaseExpression ::= "CASE" CaseOperand SimpleWhenClause {SimpleWhenClause}* "ELSE" ScalarExpression "END" + * SimpleCaseExpression ::= "CASE" CaseOperand SimpleWhenClause {SimpleWhenClause}* "ELSE" ScalarExpression "END" * * @since 2.2 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL @@ -41,8 +41,8 @@ class SimpleCaseExpression extends Node $this->caseOperand = $caseOperand; $this->simpleWhenClauses = $simpleWhenClauses; $this->elseScalarExpression = $elseScalarExpression; - } - + } + public function dispatch($sqlWalker) { return $sqlWalker->walkSimpleCaseExpression($this); diff --git a/lib/Doctrine/ORM/Query/AST/SimpleSelectClause.php b/lib/Doctrine/ORM/Query/AST/SimpleSelectClause.php index e3b93e7f6..8a4028036 100644 --- a/lib/Doctrine/ORM/Query/AST/SimpleSelectClause.php +++ b/lib/Doctrine/ORM/Query/AST/SimpleSelectClause.php @@ -42,7 +42,7 @@ class SimpleSelectClause extends Node $this->simpleSelectExpression = $simpleSelectExpression; $this->isDistinct = $isDistinct; } - + public function dispatch($sqlWalker) { return $sqlWalker->walkSimpleSelectClause($this); diff --git a/lib/Doctrine/ORM/Query/AST/SimpleSelectExpression.php b/lib/Doctrine/ORM/Query/AST/SimpleSelectExpression.php index e25d38bfc..1648c4dc5 100644 --- a/lib/Doctrine/ORM/Query/AST/SimpleSelectExpression.php +++ b/lib/Doctrine/ORM/Query/AST/SimpleSelectExpression.php @@ -41,8 +41,8 @@ class SimpleSelectExpression extends Node public function __construct($expression) { $this->expression = $expression; - } - + } + public function dispatch($sqlWalker) { return $sqlWalker->walkSimpleSelectExpression($this); diff --git a/lib/Doctrine/ORM/Query/AST/SimpleWhenClause.php b/lib/Doctrine/ORM/Query/AST/SimpleWhenClause.php index 1cb654f21..0345328a6 100644 --- a/lib/Doctrine/ORM/Query/AST/SimpleWhenClause.php +++ b/lib/Doctrine/ORM/Query/AST/SimpleWhenClause.php @@ -20,7 +20,7 @@ namespace Doctrine\ORM\Query\AST; /** - * SimpleWhenClause ::= "WHEN" ScalarExpression "THEN" ScalarExpression + * SimpleWhenClause ::= "WHEN" ScalarExpression "THEN" ScalarExpression * * @since 2.2 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL @@ -39,8 +39,8 @@ class SimpleWhenClause extends Node { $this->caseScalarExpression = $caseScalarExpression; $this->thenScalarExpression = $thenScalarExpression; - } - + } + public function dispatch($sqlWalker) { return $sqlWalker->walkWhenClauseExpression($this); diff --git a/lib/Doctrine/ORM/Query/AST/Subselect.php b/lib/Doctrine/ORM/Query/AST/Subselect.php index fa5d3356a..548e42ba7 100644 --- a/lib/Doctrine/ORM/Query/AST/Subselect.php +++ b/lib/Doctrine/ORM/Query/AST/Subselect.php @@ -45,8 +45,8 @@ class Subselect extends Node { $this->simpleSelectClause = $simpleSelectClause; $this->subselectFromClause = $subselectFromClause; - } - + } + public function dispatch($sqlWalker) { return $sqlWalker->walkSubselect($this); diff --git a/lib/Doctrine/ORM/Query/AST/SubselectFromClause.php b/lib/Doctrine/ORM/Query/AST/SubselectFromClause.php index 44d2b5988..c7c2f35f8 100644 --- a/lib/Doctrine/ORM/Query/AST/SubselectFromClause.php +++ b/lib/Doctrine/ORM/Query/AST/SubselectFromClause.php @@ -39,8 +39,8 @@ class SubselectFromClause extends Node public function __construct(array $identificationVariableDeclarations) { $this->identificationVariableDeclarations = $identificationVariableDeclarations; - } - + } + public function dispatch($sqlWalker) { return $sqlWalker->walkSubselectFromClause($this); diff --git a/lib/Doctrine/ORM/Query/AST/UpdateStatement.php b/lib/Doctrine/ORM/Query/AST/UpdateStatement.php index 7bf40bbc6..d1e152ea2 100644 --- a/lib/Doctrine/ORM/Query/AST/UpdateStatement.php +++ b/lib/Doctrine/ORM/Query/AST/UpdateStatement.php @@ -46,4 +46,4 @@ class UpdateStatement extends Node { return $sqlWalker->walkUpdateStatement($this); } -} \ No newline at end of file +} \ No newline at end of file diff --git a/lib/Doctrine/ORM/Query/AST/WhenClause.php b/lib/Doctrine/ORM/Query/AST/WhenClause.php index c20bad9f5..69556e5be 100644 --- a/lib/Doctrine/ORM/Query/AST/WhenClause.php +++ b/lib/Doctrine/ORM/Query/AST/WhenClause.php @@ -20,7 +20,7 @@ namespace Doctrine\ORM\Query\AST; /** - * WhenClause ::= "WHEN" ConditionalExpression "THEN" ScalarExpression + * WhenClause ::= "WHEN" ConditionalExpression "THEN" ScalarExpression * * @since 2.2 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL @@ -39,8 +39,8 @@ class WhenClause extends Node { $this->caseConditionExpression = $caseConditionExpression; $this->thenScalarExpression = $thenScalarExpression; - } - + } + public function dispatch($sqlWalker) { return $sqlWalker->walkWhenClauseExpression($this); diff --git a/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php b/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php index 5b07d4d02..51f4b8c5b 100644 --- a/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php @@ -36,7 +36,7 @@ class MultiTableDeleteExecutor extends AbstractSqlExecutor private $_createTempTableSql; private $_dropTempTableSql; private $_insertSql; - + /** * Initializes a new MultiTableDeleteExecutor. * @@ -64,7 +64,7 @@ class MultiTableDeleteExecutor extends AbstractSqlExecutor $this->_insertSql = 'INSERT INTO ' . $tempTable . ' (' . $idColumnList . ')' . ' SELECT t0.' . implode(', t0.', $idColumnNames); - + $rangeDecl = new AST\RangeVariableDeclaration($primaryClass->name, $primaryDqlAlias); $fromClause = new AST\FromClause(array(new AST\IdentificationVariableDeclaration($rangeDecl, null, array()))); $this->_insertSql .= $sqlWalker->walkFromClause($fromClause); @@ -84,7 +84,7 @@ class MultiTableDeleteExecutor extends AbstractSqlExecutor $this->_sqlStatements[] = 'DELETE FROM ' . $tableName . ' WHERE (' . $idColumnList . ') IN (' . $idSubselect . ')'; } - + // 4. Store DDL for temporary identifier table. $columnDefinitions = array(); foreach ($idColumnNames as $idColumnName) { diff --git a/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php b/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php index 67f0bfde8..8be24e555 100644 --- a/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php @@ -80,7 +80,7 @@ class MultiTableUpdateExecutor extends AbstractSqlExecutor // 3. Create and store UPDATE statements $classNames = array_merge($primaryClass->parentClasses, array($primaryClass->name), $primaryClass->subClasses); $i = -1; - + foreach (array_reverse($classNames) as $className) { $affected = false; $class = $em->getClassMetadata($className); @@ -88,27 +88,27 @@ class MultiTableUpdateExecutor extends AbstractSqlExecutor foreach ($updateItems as $updateItem) { $field = $updateItem->pathExpression->field; - + if (isset($class->fieldMappings[$field]) && ! isset($class->fieldMappings[$field]['inherited']) || isset($class->associationMappings[$field]) && ! isset($class->associationMappings[$field]['inherited'])) { $newValue = $updateItem->newValue; - + if ( ! $affected) { $affected = true; ++$i; } else { $updateSql .= ', '; } - + $updateSql .= $sqlWalker->walkUpdateItem($updateItem); - + //FIXME: parameters can be more deeply nested. traverse the tree. //FIXME (URGENT): With query cache the parameter is out of date. Move to execute() stage. if ($newValue instanceof AST\InputParameter) { $paramKey = $newValue->name; $this->_sqlParameters[$i]['parameters'][] = $sqlWalker->getQuery()->getParameter($paramKey); $this->_sqlParameters[$i]['types'][] = $sqlWalker->getQuery()->getParameterType($paramKey); - + ++$this->_numParametersInUpdateClause; } } @@ -118,12 +118,12 @@ class MultiTableUpdateExecutor extends AbstractSqlExecutor $this->_sqlStatements[$i] = $updateSql . ' WHERE (' . $idColumnList . ') IN (' . $idSubselect . ')'; } } - + // Append WHERE clause to insertSql, if there is one. if ($AST->whereClause) { $this->_insertSql .= $sqlWalker->walkWhereClause($AST->whereClause); } - + // 4. Store DDL for temporary identifier table. $columnDefinitions = array(); @@ -133,10 +133,10 @@ class MultiTableUpdateExecutor extends AbstractSqlExecutor 'type' => Type::getType($rootClass->getTypeOfColumn($idColumnName)) ); } - + $this->_createTempTableSql = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' (' . $platform->getColumnDeclarationListSQL($columnDefinitions) . ')'; - + $this->_dropTempTableSql = $platform->getDropTemporaryTableSQL($tempTable); } @@ -152,8 +152,8 @@ class MultiTableUpdateExecutor extends AbstractSqlExecutor // Insert identifiers. Parameters from the update clause are cut off. $numUpdated = $conn->executeUpdate( - $this->_insertSql, - array_slice($params, $this->_numParametersInUpdateClause), + $this->_insertSql, + array_slice($params, $this->_numParametersInUpdateClause), array_slice($types, $this->_numParametersInUpdateClause) ); @@ -161,12 +161,12 @@ class MultiTableUpdateExecutor extends AbstractSqlExecutor for ($i=0, $count=count($this->_sqlStatements); $i<$count; ++$i) { $parameters = array(); $types = array(); - + if (isset($this->_sqlParameters[$i])) { $parameters = isset($this->_sqlParameters[$i]['parameters']) ? $this->_sqlParameters[$i]['parameters'] : array(); $types = isset($this->_sqlParameters[$i]['types']) ? $this->_sqlParameters[$i]['types'] : array(); } - + $conn->executeUpdate($this->_sqlStatements[$i], $parameters, $types); } diff --git a/lib/Doctrine/ORM/Query/Exec/SingleTableDeleteUpdateExecutor.php b/lib/Doctrine/ORM/Query/Exec/SingleTableDeleteUpdateExecutor.php index facccb715..467ce5460 100644 --- a/lib/Doctrine/ORM/Query/Exec/SingleTableDeleteUpdateExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/SingleTableDeleteUpdateExecutor.php @@ -30,7 +30,7 @@ use Doctrine\DBAL\Connection, * @author Roman Borschel * @link www.doctrine-project.org * @since 2.0 - * @todo This is exactly the same as SingleSelectExecutor. Unify in SingleStatementExecutor. + * @todo This is exactly the same as SingleSelectExecutor. Unify in SingleStatementExecutor. */ class SingleTableDeleteUpdateExecutor extends AbstractSqlExecutor { diff --git a/lib/Doctrine/ORM/Query/Expr/Comparison.php b/lib/Doctrine/ORM/Query/Expr/Comparison.php index 7fcd263a2..d42560eb7 100644 --- a/lib/Doctrine/ORM/Query/Expr/Comparison.php +++ b/lib/Doctrine/ORM/Query/Expr/Comparison.php @@ -40,7 +40,7 @@ class Comparison const LTE = '<='; const GT = '>'; const GTE = '>='; - + private $_leftExpr; private $_operator; private $_rightExpr; diff --git a/lib/Doctrine/ORM/Query/Expr/From.php b/lib/Doctrine/ORM/Query/Expr/From.php index 4c0c8175a..e5707cce6 100644 --- a/lib/Doctrine/ORM/Query/Expr/From.php +++ b/lib/Doctrine/ORM/Query/Expr/From.php @@ -38,17 +38,17 @@ class From * @var string */ private $_from; - + /** - * @var string + * @var string */ private $_alias; - + /** - * @var string + * @var string */ private $_indexBy; - + /** * @param string $from The class name. * @param string $alias The alias of the class. @@ -60,7 +60,7 @@ class From $this->_alias = $alias; $this->_indexBy = $indexBy; } - + /** * @return string */ @@ -82,7 +82,7 @@ class From */ public function __toString() { - return $this->_from . ' ' . $this->_alias . + return $this->_from . ' ' . $this->_alias . ($this->_indexBy ? ' INDEX BY ' . $this->_indexBy : ''); } } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Query/Expr/Join.php b/lib/Doctrine/ORM/Query/Expr/Join.php index 54ad6ead7..14f5b43cd 100644 --- a/lib/Doctrine/ORM/Query/Expr/Join.php +++ b/lib/Doctrine/ORM/Query/Expr/Join.php @@ -36,10 +36,10 @@ class Join { const INNER_JOIN = 'INNER'; const LEFT_JOIN = 'LEFT'; - + const ON = 'ON'; const WITH = 'WITH'; - + private $_joinType; private $_join; private $_alias; diff --git a/lib/Doctrine/ORM/Query/Expr/Math.php b/lib/Doctrine/ORM/Query/Expr/Math.php index c6135c866..e7e8b329c 100644 --- a/lib/Doctrine/ORM/Query/Expr/Math.php +++ b/lib/Doctrine/ORM/Query/Expr/Math.php @@ -49,18 +49,18 @@ class Math { // Adjusting Left Expression $leftExpr = (string) $this->_leftExpr; - + if ($this->_leftExpr instanceof Math) { $leftExpr = '(' . $leftExpr . ')'; } - + // Adjusting Right Expression $rightExpr = (string) $this->_rightExpr; - + if ($this->_rightExpr instanceof Math) { $rightExpr = '(' . $rightExpr . ')'; } - + return $leftExpr . ' ' . $this->_operator . ' ' . $rightExpr; } } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Query/ParameterTypeInferer.php b/lib/Doctrine/ORM/Query/ParameterTypeInferer.php index 8664f8670..39aef2974 100644 --- a/lib/Doctrine/ORM/Query/ParameterTypeInferer.php +++ b/lib/Doctrine/ORM/Query/ParameterTypeInferer.php @@ -39,9 +39,9 @@ class ParameterTypeInferer * Infer type of a given value, returning a compatible constant: * - Type (\Doctrine\DBAL\Types\Type::*) * - Connection (\Doctrine\DBAL\Connection::PARAM_*) - * + * * @param mixed $value Parameter value - * + * * @return mixed Parameter type constant */ public static function inferType($value) diff --git a/lib/Doctrine/ORM/Query/ParserResult.php b/lib/Doctrine/ORM/Query/ParserResult.php index 42aecc184..3e938a9c3 100644 --- a/lib/Doctrine/ORM/Query/ParserResult.php +++ b/lib/Doctrine/ORM/Query/ParserResult.php @@ -37,14 +37,14 @@ class ParserResult { /** * The SQL executor used for executing the SQL. - * + * * @var \Doctrine\ORM\Query\Exec\AbstractSqlExecutor */ private $_sqlExecutor; /** * The ResultSetMapping that describes how to map the SQL result set. - * + * * @var \Doctrine\ORM\Query\ResultSetMapping */ private $_resultSetMapping; @@ -55,7 +55,7 @@ class ParserResult * @var array */ private $_parameterMappings = array(); - + /** * Initializes a new instance of the ParserResult class. * The new instance is initialized with an empty ResultSetMapping. @@ -67,7 +67,7 @@ class ParserResult /** * Gets the ResultSetMapping for the parsed query. - * + * * @return ResultSetMapping The result set mapping of the parsed query or NULL * if the query is not a SELECT query. */ @@ -88,7 +88,7 @@ class ParserResult /** * Sets the SQL executor that should be used for this ParserResult. - * + * * @param \Doctrine\ORM\Query\Exec\AbstractSqlExecutor $executor */ public function setSqlExecutor($executor) @@ -98,14 +98,14 @@ class ParserResult /** * Gets the SQL executor used by this ParserResult. - * + * * @return \Doctrine\ORM\Query\Exec\AbstractSqlExecutor */ public function getSqlExecutor() { return $this->_sqlExecutor; } - + /** * Adds a DQL to SQL parameter mapping. One DQL parameter name/position can map to * several SQL parameter positions. @@ -117,17 +117,17 @@ class ParserResult { $this->_parameterMappings[$dqlPosition][] = $sqlPosition; } - + /** * Gets all DQL to SQL parameter mappings. - * + * * @return array The parameter mappings. */ public function getParameterMappings() { return $this->_parameterMappings; } - + /** * Gets the SQL parameter positions for a DQL parameter name/position. * diff --git a/lib/Doctrine/ORM/Query/ResultSetMapping.php b/lib/Doctrine/ORM/Query/ResultSetMapping.php index 3c292fda4..b35af474f 100644 --- a/lib/Doctrine/ORM/Query/ResultSetMapping.php +++ b/lib/Doctrine/ORM/Query/ResultSetMapping.php @@ -131,7 +131,7 @@ class ResultSetMapping if ($resultAlias !== null) { $this->isMixed = true; } - + return $this; } @@ -150,7 +150,7 @@ class ResultSetMapping { $this->discriminatorColumns[$alias] = $discrColumn; $this->columnOwnerMap[$discrColumn] = $alias; - + return $this; } @@ -185,7 +185,7 @@ class ResultSetMapping throw new \LogicException($message); } */ - + return $this; } @@ -198,7 +198,7 @@ class ResultSetMapping public function addIndexByScalar($resultColumnName) { $this->indexByMap['scalars'] = $resultColumnName; - + return $this; } @@ -212,7 +212,7 @@ class ResultSetMapping public function addIndexByColumn($alias, $resultColumnName) { $this->indexByMap[$alias] = $resultColumnName; - + return $this; } @@ -268,7 +268,7 @@ class ResultSetMapping if ( ! $this->isMixed && $this->scalarMappings) { $this->isMixed = true; } - + return $this; } @@ -287,7 +287,7 @@ class ResultSetMapping $this->aliasMap[$alias] = $class; $this->parentAliasMap[$alias] = $parentAlias; $this->relationMap[$alias] = $relation; - + return $this; } @@ -306,7 +306,7 @@ class ResultSetMapping if ( ! $this->isMixed && $this->fieldMappings) { $this->isMixed = true; } - + return $this; } @@ -469,7 +469,7 @@ class ResultSetMapping if ($isIdentifierColumn) { $this->isIdentifierColumn[$alias][$columnName] = true; } - + return $this; } } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/MetadataCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/MetadataCommand.php index 13243a0f7..afff8db63 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/MetadataCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/MetadataCommand.php @@ -51,11 +51,11 @@ class MetadataCommand extends Console\Command\Command 'If defined, cache entries will be flushed instead of deleted/invalidated.' ) )); - + $fullName = $this->getName(); $this->setHelp(<<$fullName command is meant to clear the metadata cache of associated Entity Manager. -It is possible to invalidate all cache entries at once - called delete -, or flushes the cache provider +It is possible to invalidate all cache entries at once - called delete -, or flushes the cache provider instance completely. The execution type differ on how you execute the command. @@ -66,7 +66,7 @@ If you want to invalidate the entries (and not delete from cache instance), this Alternatively, if you want to flush the cache provider using this command: $fullName --flush - + Finally, be aware that if --flush option is passed, not all cache providers are able to flush entries, because of a limitation of its execution nature. EOT @@ -84,7 +84,7 @@ EOT if ( ! $cacheDriver) { throw new \InvalidArgumentException('No Metadata cache driver is configured on given EntityManager.'); } - + if ($cacheDriver instanceof Cache\ApcCache) { throw new \LogicException("Cannot clear APC Cache from Console, its shared in the Webserver memory and not accessible from the CLI."); } @@ -93,12 +93,12 @@ EOT $result = $cacheDriver->deleteAll(); $message = ($result) ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.'; - + if (true === $input->getOption('flush')) { $result = $cacheDriver->flushAll(); $message = ($result) ? 'Successfully flushed cache entries.' : $message; } - + $output->write($message . PHP_EOL); } } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php index 6451d4ad7..6ad75cdcb 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php @@ -51,11 +51,11 @@ class QueryCommand extends Console\Command\Command 'If defined, cache entries will be flushed instead of deleted/invalidated.' ) )); - + $fullName = $this->getName(); $this->setHelp(<<$fullName command is meant to clear the query cache of associated Entity Manager. -It is possible to invalidate all cache entries at once - called delete -, or flushes the cache provider +It is possible to invalidate all cache entries at once - called delete -, or flushes the cache provider instance completely. The execution type differ on how you execute the command. @@ -66,7 +66,7 @@ If you want to invalidate the entries (and not delete from cache instance), this Alternatively, if you want to flush the cache provider using this command: $fullName --flush - + Finally, be aware that if --flush option is passed, not all cache providers are able to flush entries, because of a limitation of its execution nature. EOT @@ -84,7 +84,7 @@ EOT if ( ! $cacheDriver) { throw new \InvalidArgumentException('No Query cache driver is configured on given EntityManager.'); } - + if ($cacheDriver instanceof Cache\ApcCache) { throw new \LogicException("Cannot clear APC Cache from Console, its shared in the Webserver memory and not accessible from the CLI."); } @@ -93,12 +93,12 @@ EOT $result = $cacheDriver->deleteAll(); $message = ($result) ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.'; - + if (true === $input->getOption('flush')) { $result = $cacheDriver->flushAll(); $message = ($result) ? 'Successfully flushed cache entries.' : $message; } - + $output->write($message . PHP_EOL); } } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/ResultCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/ResultCommand.php index 1dfacb056..5bb000c72 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/ResultCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/ResultCommand.php @@ -51,11 +51,11 @@ class ResultCommand extends Console\Command\Command 'If defined, cache entries will be flushed instead of deleted/invalidated.' ) )); - + $fullName = $this->getName(); $this->setHelp(<<$fullName command is meant to clear the result cache of associated Entity Manager. -It is possible to invalidate all cache entries at once - called delete -, or flushes the cache provider +It is possible to invalidate all cache entries at once - called delete -, or flushes the cache provider instance completely. The execution type differ on how you execute the command. @@ -66,7 +66,7 @@ If you want to invalidate the entries (and not delete from cache instance), this Alternatively, if you want to flush the cache provider using this command: $fullName --flush - + Finally, be aware that if --flush option is passed, not all cache providers are able to flush entries, because of a limitation of its execution nature. EOT @@ -84,7 +84,7 @@ EOT if ( ! $cacheDriver) { throw new \InvalidArgumentException('No Result cache driver is configured on given EntityManager.'); } - + if ($cacheDriver instanceof Cache\ApcCache) { throw new \LogicException("Cannot clear APC Cache from Console, its shared in the Webserver memory and not accessible from the CLI."); } @@ -93,12 +93,12 @@ EOT $result = $cacheDriver->deleteAll(); $message = ($result) ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.'; - + if (true === $input->getOption('flush')) { $result = $cacheDriver->flushAll(); $message = ($result) ? 'Successfully flushed cache entries.' : $message; } - + $output->write($message . PHP_EOL); } } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php index 1a1328aac..c78920bcc 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php @@ -80,7 +80,7 @@ class ConvertDoctrine1SchemaCommand extends Console\Command\Command if ($this->metadataExporter == null) { $this->metadataExporter = new ClassMetadataExporter(); } - + return $this->metadataExporter; } @@ -91,7 +91,7 @@ class ConvertDoctrine1SchemaCommand extends Console\Command\Command { $this->metadataExporter = $metadataExporter; } - + /** * @see Console\Command\Command */ diff --git a/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php index 0c65712cb..f00e6d2c4 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php @@ -112,12 +112,12 @@ EOT protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) { $em = $this->getHelper('em')->getEntityManager(); - + $cmf = new DisconnectedClassMetadataFactory(); $cmf->setEntityManager($em); $metadatas = $cmf->getAllMetadata(); $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter')); - + // Process destination directory $destPath = realpath($input->getArgument('dest-path')); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/GenerateProxiesCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/GenerateProxiesCommand.php index cd7578b27..7028d99e2 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/GenerateProxiesCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/GenerateProxiesCommand.php @@ -70,7 +70,7 @@ EOT protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) { $em = $this->getHelper('em')->getEntityManager(); - + $metadatas = $em->getMetadataFactory()->getAllMetadata(); $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter')); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php index 2a92493e8..bb6fc9d8b 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php @@ -70,7 +70,7 @@ EOT protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) { $em = $this->getHelper('em')->getEntityManager(); - + $metadatas = $em->getMetadataFactory()->getAllMetadata(); $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter')); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php index a39995e0f..2b0fc0dd0 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php @@ -127,7 +127,7 @@ EOT $output->writeln(sprintf('The Schema-Tool would execute "%s" queries to update the database.', count($sqls))); $output->writeln('Please run the operation by passing one of the following options:'); - + $output->writeln(sprintf(' %s --force to execute the command', $this->getName())); $output->writeln(sprintf(' %s --dump-sql to dump the SQL statements to the screen', $this->getName())); } diff --git a/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php b/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php index 2fd6ed35b..6907dde39 100644 --- a/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php +++ b/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php @@ -26,7 +26,7 @@ class ConsoleRunner { /** * Run console with the given helperset. - * + * * @param \Symfony\Component\Console\Helper\HelperSet $helperSet * @return void */ diff --git a/lib/Doctrine/ORM/Tools/Console/MetadataFilter.php b/lib/Doctrine/ORM/Tools/Console/MetadataFilter.php index efd720802..2f69d89c5 100644 --- a/lib/Doctrine/ORM/Tools/Console/MetadataFilter.php +++ b/lib/Doctrine/ORM/Tools/Console/MetadataFilter.php @@ -37,7 +37,7 @@ class MetadataFilter extends \FilterIterator implements \Countable { /** * Filter Metadatas by one or more filter options. - * + * * @param array $metadatas * @param array|string $filter * @return array diff --git a/lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php b/lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php index 8b69ce067..93edebbdc 100644 --- a/lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php +++ b/lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php @@ -101,7 +101,7 @@ class ConvertDoctrine1Schema { if (isset($model['tableName']) && $model['tableName']) { $e = explode('.', $model['tableName']); - + if (count($e) > 1) { $metadata->table['schema'] = $e[0]; $metadata->table['name'] = $e[1]; diff --git a/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php b/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php index 5475d998f..0548b9644 100644 --- a/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php +++ b/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php @@ -54,7 +54,7 @@ class DebugUnitOfWorkListener /** * Dump the contents of the identity map into a stream. - * + * * @param EntityManager $em * @return void */ diff --git a/lib/Doctrine/ORM/Tools/DisconnectedClassMetadataFactory.php b/lib/Doctrine/ORM/Tools/DisconnectedClassMetadataFactory.php index 7a7715231..f98c8bfae 100644 --- a/lib/Doctrine/ORM/Tools/DisconnectedClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Tools/DisconnectedClassMetadataFactory.php @@ -24,7 +24,7 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo; /** * The DisconnectedClassMetadataFactory is used to create ClassMetadataInfo objects - * that do not require the entity class actually exist. This allows us to + * that do not require the entity class actually exist. This allows us to * load some mapping information and use it to do things like generate code * from the mapping information. * diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php index 75302717e..14f654130 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php @@ -56,7 +56,7 @@ abstract class AbstractExporter * Converts a single ClassMetadata instance to the exported format * and returns it * - * @param ClassMetadataInfo $metadata + * @param ClassMetadataInfo $metadata * @return mixed $exported */ abstract public function exportClassMetadata(ClassMetadataInfo $metadata); @@ -64,7 +64,7 @@ abstract class AbstractExporter /** * Set the array of ClassMetadataInfo instances to export * - * @param array $metadata + * @param array $metadata * @return void */ public function setMetadata(array $metadata) @@ -90,7 +90,7 @@ abstract class AbstractExporter * $exporter->setOutputDir(__DIR__ . '/yaml'); * $exporter->export(); * - * @param string $dir + * @param string $dir * @return void */ public function setOutputDir($dir) @@ -127,7 +127,7 @@ abstract class AbstractExporter /** * Generate the path to write the class for the given ClassMetadataInfo instance * - * @param ClassMetadataInfo $metadata + * @param ClassMetadataInfo $metadata * @return string $path */ protected function _generateOutputPath(ClassMetadataInfo $metadata) @@ -162,11 +162,11 @@ abstract class AbstractExporter case ClassMetadataInfo::INHERITANCE_TYPE_JOINED: return 'JOINED'; break; - + case ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_TABLE: return 'SINGLE_TABLE'; break; - + case ClassMetadataInfo::INHERITANCE_TYPE_TABLE_PER_CLASS: return 'PER_CLASS'; break; @@ -180,11 +180,11 @@ abstract class AbstractExporter case ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT: return 'DEFERRED_IMPLICIT'; break; - + case ClassMetadataInfo::CHANGETRACKING_DEFERRED_EXPLICIT: return 'DEFERRED_EXPLICIT'; break; - + case ClassMetadataInfo::CHANGETRACKING_NOTIFY: return 'NOTIFY'; break; @@ -198,15 +198,15 @@ abstract class AbstractExporter case ClassMetadataInfo::GENERATOR_TYPE_AUTO: return 'AUTO'; break; - + case ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE: return 'SEQUENCE'; break; - + case ClassMetadataInfo::GENERATOR_TYPE_TABLE: return 'TABLE'; break; - + case ClassMetadataInfo::GENERATOR_TYPE_IDENTITY: return 'IDENTITY'; break; diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php index 254905eec..5053290d8 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/AnnotationExporter.php @@ -44,7 +44,7 @@ class AnnotationExporter extends AbstractExporter * Converts a single ClassMetadata instance to the exported format * and returns it * - * @param ClassMetadataInfo $metadata + * @param ClassMetadataInfo $metadata * @return string $exported */ public function exportClassMetadata(ClassMetadataInfo $metadata) diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php index 900fb5bda..fc561c908 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/PhpExporter.php @@ -41,7 +41,7 @@ class PhpExporter extends AbstractExporter * Converts a single ClassMetadata instance to the exported format * and returns it * - * @param ClassMetadataInfo $metadata + * @param ClassMetadataInfo $metadata * @return mixed $exported */ public function exportClassMetadata(ClassMetadataInfo $metadata) @@ -108,7 +108,7 @@ class PhpExporter extends AbstractExporter 'targetEntity' => $associationMapping['targetEntity'], 'cascade' => $cascade, ); - + if ($associationMapping['type'] & ClassMetadataInfo::TO_ONE) { $method = 'mapOneToOne'; $oneToOneMappingArray = array( @@ -117,10 +117,10 @@ class PhpExporter extends AbstractExporter 'joinColumns' => $associationMapping['joinColumns'], 'orphanRemoval' => $associationMapping['orphanRemoval'], ); - + $associationMappingArray = array_merge($associationMappingArray, $oneToOneMappingArray); } else if ($associationMapping['type'] == ClassMetadataInfo::ONE_TO_MANY) { - $method = 'mapOneToMany'; + $method = 'mapOneToMany'; $potentialAssociationMappingIndexes = array( 'mappedBy', 'orphanRemoval', @@ -133,7 +133,7 @@ class PhpExporter extends AbstractExporter } $associationMappingArray = array_merge($associationMappingArray, $oneToManyMappingArray); } else if ($associationMapping['type'] == ClassMetadataInfo::MANY_TO_MANY) { - $method = 'mapManyToMany'; + $method = 'mapManyToMany'; $potentialAssociationMappingIndexes = array( 'mappedBy', 'joinTable', @@ -146,7 +146,7 @@ class PhpExporter extends AbstractExporter } $associationMappingArray = array_merge($associationMappingArray, $manyToManyMappingArray); } - + $lines[] = '$metadata->' . $method . '(' . $this->_varExport($associationMappingArray) . ');'; } diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php index 869580613..bda29810f 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php @@ -41,7 +41,7 @@ class XmlExporter extends AbstractExporter * Converts a single ClassMetadata instance to the exported format * and returns it * - * @param ClassMetadataInfo $metadata + * @param ClassMetadataInfo $metadata * @return mixed $exported */ public function exportClassMetadata(ClassMetadataInfo $metadata) @@ -99,7 +99,7 @@ class XmlExporter extends AbstractExporter if (isset($metadata->table['indexes'])) { $indexesXml = $root->addChild('indexes'); - + foreach ($metadata->table['indexes'] as $name => $index) { $indexXml = $indexesXml->addChild('index'); $indexXml->addAttribute('name', $name); @@ -109,7 +109,7 @@ class XmlExporter extends AbstractExporter if (isset($metadata->table['uniqueConstraints'])) { $uniqueConstraintsXml = $root->addChild('unique-constraints'); - + foreach ($metadata->table['uniqueConstraints'] as $unique) { $uniqueConstraintXml = $uniqueConstraintsXml->addChild('unique-constraint'); $uniqueConstraintXml->addAttribute('name', $unique['name']); @@ -118,7 +118,7 @@ class XmlExporter extends AbstractExporter } $fields = $metadata->fieldMappings; - + $id = array(); foreach ($fields as $name => $field) { if (isset($field['id']) && $field['id']) { diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php index de76c7bdd..2d16792b1 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php @@ -49,13 +49,13 @@ class YamlExporter extends AbstractExporter public function exportClassMetadata(ClassMetadataInfo $metadata) { $array = array(); - + if ($metadata->isMappedSuperclass) { $array['type'] = 'mappedSuperclass'; } else { $array['type'] = 'entity'; } - + $array['table'] = $metadata->table['name']; if (isset($metadata->table['schema'])) { diff --git a/lib/Doctrine/ORM/Tools/Setup.php b/lib/Doctrine/ORM/Tools/Setup.php index b4a6a2c7f..c2550e2c7 100644 --- a/lib/Doctrine/ORM/Tools/Setup.php +++ b/lib/Doctrine/ORM/Tools/Setup.php @@ -28,7 +28,7 @@ use Doctrine\ORM\Mapping\Driver\YamlDriver; /** * Convenience class for setting up Doctrine from different installations and configurations. - * + * * @author Benjamin Eberlei */ class Setup @@ -36,8 +36,8 @@ class Setup /** * Use this method to register all autoloaders for a setup where Doctrine is checked out from * its github repository at {@link http://github.com/doctrine/doctrine2} - * - * @param string $gitCheckoutRootPath + * + * @param string $gitCheckoutRootPath * @return void */ static public function registerAutoloadGit($gitCheckoutRootPath) @@ -45,24 +45,24 @@ class Setup if (!class_exists('Doctrine\Common\ClassLoader', false)) { require_once $gitCheckoutRootPath . "/lib/vendor/doctrine-common/lib/Doctrine/Common/ClassLoader.php"; } - + $loader = new ClassLoader("Doctrine\Common", $gitCheckoutRootPath . "/lib/vendor/doctrine-common/lib"); $loader->register(); - + $loader = new ClassLoader("Doctrine\DBAL", $gitCheckoutRootPath . "/lib/vendor/doctrine-dbal/lib"); $loader->register(); - + $loader = new ClassLoader("Doctrine\ORM", $gitCheckoutRootPath . "/lib"); $loader->register(); - + $loader = new ClassLoader("Symfony\Component", $gitCheckoutRootPath . "/lib/vendor"); $loader->register(); } - + /** * Use this method to register all autoloaders for a setup where Doctrine is installed * though {@link http://pear.doctrine-project.org}. - * + * * @return void */ static public function registerAutoloadPEAR() @@ -70,12 +70,12 @@ class Setup if (!class_exists('Doctrine\Common\ClassLoader', false)) { require_once "Doctrine/Common/ClassLoader.php"; } - + $loader = new ClassLoader("Doctrine"); $loader->register(); - + $parts = explode(PATH_SEPARATOR, get_include_path()); - + foreach ($parts AS $includePath) { if ($includePath != "." && file_exists($includePath . "/Doctrine")) { $loader = new ClassLoader("Symfony\Component", $includePath . "/Doctrine"); @@ -84,29 +84,29 @@ class Setup } } } - + /** * Use this method to register all autoloads for a downloaded Doctrine library. * Pick the directory the library was uncompressed into. - * - * @param string $directory + * + * @param string $directory */ static public function registerAutoloadDirectory($directory) { if (!class_exists('Doctrine\Common\ClassLoader', false)) { require_once $directory . "/Doctrine/Common/ClassLoader.php"; } - + $loader = new ClassLoader("Doctrine", $directory); $loader->register(); - + $loader = new ClassLoader("Symfony\Component", $directory . "/Doctrine"); $loader->register(); } - + /** * Create a configuration with an annotation metadata driver. - * + * * @param array $paths * @param boolean $isDevMode * @param string $proxyDir @@ -119,10 +119,10 @@ class Setup $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver($paths)); return $config; } - + /** * Create a configuration with a xml metadata driver. - * + * * @param array $paths * @param boolean $isDevMode * @param string $proxyDir @@ -135,10 +135,10 @@ class Setup $config->setMetadataDriverImpl(new XmlDriver($paths)); return $config; } - + /** * Create a configuration with a yaml metadata driver. - * + * * @param array $paths * @param boolean $isDevMode * @param string $proxyDir @@ -151,14 +151,14 @@ class Setup $config->setMetadataDriverImpl(new YamlDriver($paths)); return $config; } - + /** * Create a configuration without a metadata driver. - * + * * @param bool $isDevMode * @param string $proxyDir * @param Cache $cache - * @return Configuration + * @return Configuration */ static public function createConfiguration($isDevMode = false, $proxyDir = null, Cache $cache = null) { @@ -180,7 +180,7 @@ class Setup $cache = new ArrayCache; } $cache->setNamespace("dc2_" . md5($proxyDir) . "_"); // to avoid collisions - + $config = new Configuration(); $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); @@ -188,7 +188,7 @@ class Setup $config->setProxyDir( $proxyDir ); $config->setProxyNamespace('DoctrineProxies'); $config->setAutoGenerateProxyClasses($isDevMode); - + return $config; } } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Version.php b/lib/Doctrine/ORM/Version.php index 183887147..e8124cd45 100644 --- a/lib/Doctrine/ORM/Version.php +++ b/lib/Doctrine/ORM/Version.php @@ -16,7 +16,7 @@ * and is licensed under the LGPL. For more information, see * . */ - + namespace Doctrine\ORM; /** @@ -42,7 +42,7 @@ class Version * Compares a Doctrine version with the current one. * * @param string $version Doctrine version to compare. - * @return int Returns -1 if older, 0 if it is the same, 1 if version + * @return int Returns -1 if older, 0 if it is the same, 1 if version * passed as argument is newer. */ public static function compare($version) diff --git a/tests/Doctrine/Tests/Mocks/ClassMetadataMock.php b/tests/Doctrine/Tests/Mocks/ClassMetadataMock.php index 39c53646d..c6be1b79c 100644 --- a/tests/Doctrine/Tests/Mocks/ClassMetadataMock.php +++ b/tests/Doctrine/Tests/Mocks/ClassMetadataMock.php @@ -5,10 +5,10 @@ namespace Doctrine\Tests\Mocks; class ClassMetadataMock extends \Doctrine\ORM\Mapping\ClassMetadata { /* Mock API */ - + public function setIdGeneratorType($type) { $this->_generatorType = $type; } - + } \ No newline at end of file diff --git a/tests/Doctrine/Tests/Mocks/DriverMock.php b/tests/Doctrine/Tests/Mocks/DriverMock.php index 2c7fadc52..c60a137f5 100644 --- a/tests/Doctrine/Tests/Mocks/DriverMock.php +++ b/tests/Doctrine/Tests/Mocks/DriverMock.php @@ -13,7 +13,7 @@ class DriverMock implements \Doctrine\DBAL\Driver { return new DriverConnectionMock(); } - + /** * Constructs the Sqlite PDO DSN. * diff --git a/tests/Doctrine/Tests/Mocks/EntityManagerMock.php b/tests/Doctrine/Tests/Mocks/EntityManagerMock.php index edf220a42..04b038d85 100644 --- a/tests/Doctrine/Tests/Mocks/EntityManagerMock.php +++ b/tests/Doctrine/Tests/Mocks/EntityManagerMock.php @@ -39,7 +39,7 @@ class EntityManagerMock extends \Doctrine\ORM\EntityManager { return isset($this->_uowMock) ? $this->_uowMock : parent::getUnitOfWork(); } - + /* Mock API */ /** @@ -61,7 +61,7 @@ class EntityManagerMock extends \Doctrine\ORM\EntityManager { return isset($this->_proxyFactoryMock) ? $this->_proxyFactoryMock : parent::getProxyFactory(); } - + /** * Mock factory method to create an EntityManager. * @@ -83,8 +83,8 @@ class EntityManagerMock extends \Doctrine\ORM\EntityManager if (is_null($eventManager)) { $eventManager = new \Doctrine\Common\EventManager(); } - - return new EntityManagerMock($conn, $config, $eventManager); + + return new EntityManagerMock($conn, $config, $eventManager); } /* public function setIdGenerator($className, $generator) @@ -99,7 +99,7 @@ class EntityManagerMock extends \Doctrine\ORM\EntityManager if (isset($this->_idGenerators[$className])) { return $this->_idGenerators[$className]; } - + return parent::getIdGenerator($className); } */ diff --git a/tests/Doctrine/Tests/Mocks/EntityPersisterMock.php b/tests/Doctrine/Tests/Mocks/EntityPersisterMock.php index 157c96e78..768e357b1 100644 --- a/tests/Doctrine/Tests/Mocks/EntityPersisterMock.php +++ b/tests/Doctrine/Tests/Mocks/EntityPersisterMock.php @@ -53,7 +53,7 @@ class EntityPersisterMock extends \Doctrine\ORM\Persisters\BasicEntityPersister { $this->_mockIdGeneratorType = $genType; } - + public function update($entity) { $this->_updates[] = $entity; @@ -63,27 +63,27 @@ class EntityPersisterMock extends \Doctrine\ORM\Persisters\BasicEntityPersister { $this->existsCalled = true; } - + public function delete($entity) { $this->_deletes[] = $entity; } - + public function getInserts() { return $this->_inserts; } - + public function getUpdates() { return $this->_updates; } - + public function getDeletes() { return $this->_deletes; } - + public function reset() { $this->existsCalled = false; diff --git a/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php b/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php index b5f5e3b47..83e978f06 100644 --- a/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php +++ b/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php @@ -106,6 +106,6 @@ class HydratorMockStatement implements \IteratorAggregate, \Doctrine\DBAL\Driver public function setFetchMode($fetchMode) { - + } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/Mocks/MockTreeWalker.php b/tests/Doctrine/Tests/Mocks/MockTreeWalker.php index 809b11443..b92b99f43 100644 --- a/tests/Doctrine/Tests/Mocks/MockTreeWalker.php +++ b/tests/Doctrine/Tests/Mocks/MockTreeWalker.php @@ -6,7 +6,7 @@ class MockTreeWalker extends \Doctrine\ORM\Query\TreeWalkerAdapter { /** * Gets an executor that can be used to execute the result of this walker. - * + * * @return AbstractExecutor */ public function getExecutor($AST) diff --git a/tests/Doctrine/Tests/Mocks/SchemaManagerMock.php b/tests/Doctrine/Tests/Mocks/SchemaManagerMock.php index d78376e79..d4c3c28c0 100644 --- a/tests/Doctrine/Tests/Mocks/SchemaManagerMock.php +++ b/tests/Doctrine/Tests/Mocks/SchemaManagerMock.php @@ -8,6 +8,6 @@ class SchemaManagerMock extends \Doctrine\DBAL\Schema\AbstractSchemaManager { parent::__construct($conn); } - + protected function _getPortableTableColumnDefinition($tableColumn) {} } \ No newline at end of file diff --git a/tests/Doctrine/Tests/Models/CMS/CmsArticle.php b/tests/Doctrine/Tests/Models/CMS/CmsArticle.php index 5cc516735..266cbc662 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsArticle.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsArticle.php @@ -36,7 +36,7 @@ class CmsArticle * @Version @column(type="integer") */ public $version; - + public function setAuthor(CmsUser $author) { $this->user = $author; } diff --git a/tests/Doctrine/Tests/Models/CMS/CmsEmail.php b/tests/Doctrine/Tests/Models/CMS/CmsEmail.php index 2d8818cbd..c79c30036 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsEmail.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsEmail.php @@ -29,7 +29,7 @@ class CmsEmail public function getId() { return $this->id; } - + public function getEmail() { return $this->email; } @@ -37,7 +37,7 @@ class CmsEmail public function setEmail($email) { $this->email = $email; } - + public function getUser() { return $this->user; } diff --git a/tests/Doctrine/Tests/Models/CMS/CmsGroup.php b/tests/Doctrine/Tests/Models/CMS/CmsGroup.php index ad399ba18..b65ae8557 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsGroup.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsGroup.php @@ -1,5 +1,5 @@ user = $user; } - + public function getUser() { return $this->user; } diff --git a/tests/Doctrine/Tests/Models/CMS/CmsUser.php b/tests/Doctrine/Tests/Models/CMS/CmsUser.php index 3296fffc8..05fefb590 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsUser.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsUser.php @@ -55,7 +55,7 @@ class CmsUser * ) */ public $groups; - + public function __construct() { $this->phonenumbers = new ArrayCollection; $this->articles = new ArrayCollection; @@ -115,22 +115,22 @@ class CmsUser } return false; } - + public function getAddress() { return $this->address; } - + public function setAddress(CmsAddress $address) { if ($this->address !== $address) { $this->address = $address; $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/CompanyAuction.php b/tests/Doctrine/Tests/Models/Company/CompanyAuction.php index 88b56e2f6..5dc72e8c1 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyAuction.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyAuction.php @@ -6,11 +6,11 @@ namespace Doctrine\Tests\Models\Company; class CompanyAuction extends CompanyEvent { /** @Column(type="string") */ private $data; - + public function setData($data) { $this->data = $data; } - + public function getData() { return $this->data; } diff --git a/tests/Doctrine/Tests/Models/Company/CompanyCar.php b/tests/Doctrine/Tests/Models/Company/CompanyCar.php index f970c273d..5af89b2a3 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyCar.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyCar.php @@ -13,7 +13,7 @@ class CompanyCar * @GeneratedValue(strategy="AUTO") */ private $id; - + /** * @Column(type="string", length=50) */ @@ -22,11 +22,11 @@ class CompanyCar public function __construct($brand = null) { $this->brand = $brand; } - + public function getId() { return $this->id; } - + public function getBrand() { return $this->title; } diff --git a/tests/Doctrine/Tests/Models/Company/CompanyContract.php b/tests/Doctrine/Tests/Models/Company/CompanyContract.php index 655d4fccb..221bf1cd8 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyContract.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyContract.php @@ -8,8 +8,8 @@ namespace Doctrine\Tests\Models\Company; * @InheritanceType("SINGLE_TABLE") * @DiscriminatorColumn(name="discr", type="string") * @DiscriminatorMap({ - * "fix" = "CompanyFixContract", - * "flexible" = "CompanyFlexContract", + * "fix" = "CompanyFixContract", + * "flexible" = "CompanyFlexContract", * "flexultra" = "CompanyFlexUltraContract" * }) */ diff --git a/tests/Doctrine/Tests/Models/Company/CompanyEmployee.php b/tests/Doctrine/Tests/Models/Company/CompanyEmployee.php index 61be7c5e6..5e050f948 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyEmployee.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyEmployee.php @@ -17,7 +17,7 @@ class CompanyEmployee extends CompanyPerson * @Column(type="string", length=255) */ private $department; - + /** * @Column(type="datetime", nullable=true) */ diff --git a/tests/Doctrine/Tests/Models/Company/CompanyEvent.php b/tests/Doctrine/Tests/Models/Company/CompanyEvent.php index 2db4986ae..bb320aa91 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyEvent.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyEvent.php @@ -20,17 +20,17 @@ abstract class CompanyEvent { * @JoinColumn(name="org_id", referencedColumnName="id") */ private $organization; - + public function getId() { return $this->id; } - + public function getOrganization() { return $this->organization; } - + public function setOrganization(CompanyOrganization $org) { $this->organization = $org; } - + } \ 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 226995185..e0d39dfcf 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyManager.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyManager.php @@ -12,7 +12,7 @@ class CompanyManager extends CompanyEmployee * @Column(type="string", length=250) */ private $title; - + /** * @OneToOne(targetEntity="CompanyCar", cascade={"persist"}) * @JoinColumn(name="car_id", referencedColumnName="id") @@ -26,11 +26,11 @@ class CompanyManager extends CompanyEmployee public function setTitle($title) { $this->title = $title; } - + public function getCar() { return $this->car; } - + public function setCar(CompanyCar $car) { $this->car = $car; } diff --git a/tests/Doctrine/Tests/Models/Company/CompanyOrganization.php b/tests/Doctrine/Tests/Models/Company/CompanyOrganization.php index ce47e8d9e..19463206b 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyOrganization.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyOrganization.php @@ -9,35 +9,35 @@ class CompanyOrganization { * @GeneratedValue(strategy="AUTO") */ private $id; - + /** * @OneToMany(targetEntity="CompanyEvent", mappedBy="organization", cascade={"persist"}) */ private $events; - + public function getId() { return $this->id; } - + public function getEvents() { return $this->events; } - + public function addEvent(CompanyEvent $event) { $this->events[] = $event; $event->setOrganization($this); } - + /** * @OneToOne(targetEntity="CompanyEvent", cascade={"persist"}) * @JoinColumn(name="main_event_id", referencedColumnName="id", nullable=true) */ private $mainevent; - + public function getMainEvent() { return $this->mainevent; } - + public function setMainEvent($event) { $this->mainevent = $event; } diff --git a/tests/Doctrine/Tests/Models/Company/CompanyPerson.php b/tests/Doctrine/Tests/Models/Company/CompanyPerson.php index 740c323ef..712e81c83 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyPerson.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyPerson.php @@ -32,7 +32,7 @@ class CompanyPerson * @JoinColumn(name="spouse_id", referencedColumnName="id") */ private $spouse; - + /** * @ManyToMany(targetEntity="CompanyPerson") * @JoinTable(name="company_persons_friends", @@ -40,7 +40,7 @@ class CompanyPerson inverseJoinColumns={@JoinColumn(name="friend_id", referencedColumnName="id")}) */ private $friends; - + public function __construct() { $this->friends = new \Doctrine\Common\Collections\ArrayCollection; } @@ -60,11 +60,11 @@ class CompanyPerson public function getSpouse() { return $this->spouse; } - + public function getFriends() { return $this->friends; } - + public function addFriend(CompanyPerson $friend) { if ( ! $this->friends->contains($friend)) { $this->friends->add($friend); diff --git a/tests/Doctrine/Tests/Models/Company/CompanyRaffle.php b/tests/Doctrine/Tests/Models/Company/CompanyRaffle.php index 3d05996f2..733190d58 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyRaffle.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyRaffle.php @@ -6,11 +6,11 @@ namespace Doctrine\Tests\Models\Company; class CompanyRaffle extends CompanyEvent { /** @Column */ private $data; - + public function setData($data) { $this->data = $data; } - + public function getData() { return $this->data; } diff --git a/tests/Doctrine/Tests/Models/DDC117/DDC117Article.php b/tests/Doctrine/Tests/Models/DDC117/DDC117Article.php index 70b1c6353..d77bb942b 100644 --- a/tests/Doctrine/Tests/Models/DDC117/DDC117Article.php +++ b/tests/Doctrine/Tests/Models/DDC117/DDC117Article.php @@ -9,7 +9,7 @@ class DDC117Article { /** @Id @Column(type="integer", name="article_id") @GeneratedValue */ private $id; - + /** @Column */ private $title; diff --git a/tests/Doctrine/Tests/Models/DDC1476/DDC1476EntityWithDefaultFieldType.php b/tests/Doctrine/Tests/Models/DDC1476/DDC1476EntityWithDefaultFieldType.php index f06199b4d..cc09c13e9 100644 --- a/tests/Doctrine/Tests/Models/DDC1476/DDC1476EntityWithDefaultFieldType.php +++ b/tests/Doctrine/Tests/Models/DDC1476/DDC1476EntityWithDefaultFieldType.php @@ -27,8 +27,8 @@ class DDC1476EntityWithDefaultFieldType { /** - * @Id - * @Column() + * @Id + * @Column() * @GeneratedValue("NONE") */ protected $id; @@ -37,7 +37,7 @@ class DDC1476EntityWithDefaultFieldType protected $name; /** - * @return integer + * @return integer */ public function getId() { @@ -45,7 +45,7 @@ class DDC1476EntityWithDefaultFieldType } /** - * @return string + * @return string */ public function getName() { @@ -53,13 +53,13 @@ class DDC1476EntityWithDefaultFieldType } /** - * @param string $name + * @param string $name */ public function setName($name) { $this->name = $name; } - + public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) { $metadata->mapField(array( @@ -69,7 +69,7 @@ class DDC1476EntityWithDefaultFieldType $metadata->mapField(array( 'fieldName' => 'name', )); - + $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadataInfo::GENERATOR_TYPE_NONE); } diff --git a/tests/Doctrine/Tests/Models/DDC753/DDC753CustomRepository.php b/tests/Doctrine/Tests/Models/DDC753/DDC753CustomRepository.php index d277cf8aa..eaf9006c7 100644 --- a/tests/Doctrine/Tests/Models/DDC753/DDC753CustomRepository.php +++ b/tests/Doctrine/Tests/Models/DDC753/DDC753CustomRepository.php @@ -26,7 +26,7 @@ class DDC753CustomRepository extends EntityRepository { /** - * @return bool + * @return bool */ public function isCustomRepository() { diff --git a/tests/Doctrine/Tests/Models/DDC753/DDC753DefaultRepository.php b/tests/Doctrine/Tests/Models/DDC753/DDC753DefaultRepository.php index feba2cb50..5be9aa522 100644 --- a/tests/Doctrine/Tests/Models/DDC753/DDC753DefaultRepository.php +++ b/tests/Doctrine/Tests/Models/DDC753/DDC753DefaultRepository.php @@ -25,7 +25,7 @@ use Doctrine\ORM\EntityRepository; class DDC753DefaultRepository extends EntityRepository { /** - * @return bool + * @return bool */ public function isDefaultRepository() { diff --git a/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithCustomRepository.php b/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithCustomRepository.php index fa8a77957..7b92e66ac 100644 --- a/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithCustomRepository.php +++ b/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithCustomRepository.php @@ -27,8 +27,8 @@ class DDC753EntityWithCustomRepository { /** - * @Id - * @Column(type="integer") + * @Id + * @Column(type="integer") * @GeneratedValue */ protected $id; diff --git a/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithDefaultCustomRepository.php b/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithDefaultCustomRepository.php index 43f435a98..8ca2a2c94 100644 --- a/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithDefaultCustomRepository.php +++ b/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithDefaultCustomRepository.php @@ -27,8 +27,8 @@ class DDC753EntityWithDefaultCustomRepository { /** - * @Id - * @Column(type="integer") + * @Id + * @Column(type="integer") * @GeneratedValue */ protected $id; diff --git a/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithInvalidRepository.php b/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithInvalidRepository.php index e7c21762a..d12660cf4 100644 --- a/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithInvalidRepository.php +++ b/tests/Doctrine/Tests/Models/DDC753/DDC753EntityWithInvalidRepository.php @@ -27,8 +27,8 @@ class DDC753EntityWithInvalidRepository { /** - * @Id - * @Column(type="integer") + * @Id + * @Column(type="integer") * @GeneratedValue */ protected $id; diff --git a/tests/Doctrine/Tests/Models/DDC869/DDC869ChequePayment.php b/tests/Doctrine/Tests/Models/DDC869/DDC869ChequePayment.php index 46cceb4c7..594f79f78 100644 --- a/tests/Doctrine/Tests/Models/DDC869/DDC869ChequePayment.php +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869ChequePayment.php @@ -28,7 +28,7 @@ class DDC869ChequePayment extends DDC869Payment /** @column(type="string") */ protected $serialNumber; - + public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) { $metadata->mapField(array( diff --git a/tests/Doctrine/Tests/Models/DDC869/DDC869CreditCardPayment.php b/tests/Doctrine/Tests/Models/DDC869/DDC869CreditCardPayment.php index b446e059a..9e978d494 100644 --- a/tests/Doctrine/Tests/Models/DDC869/DDC869CreditCardPayment.php +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869CreditCardPayment.php @@ -28,7 +28,7 @@ class DDC869CreditCardPayment extends DDC869Payment /** @column(type="string") */ protected $creditCardNumber; - + public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) { $metadata->mapField(array( diff --git a/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php b/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php index c3c365715..b9b8febdc 100644 --- a/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php @@ -27,16 +27,16 @@ class DDC869Payment { /** - * @Id - * @Column(type="integer") + * @Id + * @Column(type="integer") * @GeneratedValue */ protected $id; /** @column(type="float") */ protected $value; - - + + public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) { $metadata->mapField(array( diff --git a/tests/Doctrine/Tests/Models/DDC869/DDC869PaymentRepository.php b/tests/Doctrine/Tests/Models/DDC869/DDC869PaymentRepository.php index d9018266a..f950df0e0 100644 --- a/tests/Doctrine/Tests/Models/DDC869/DDC869PaymentRepository.php +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869PaymentRepository.php @@ -27,8 +27,8 @@ class DDC869PaymentRepository extends EntityRepository /** * Very complex method - * - * @return bool + * + * @return bool */ public function isTrue() { diff --git a/tests/Doctrine/Tests/Models/DirectoryTree/AbstractContentItem.php b/tests/Doctrine/Tests/Models/DirectoryTree/AbstractContentItem.php index 200a88ab1..12b27eed3 100644 --- a/tests/Doctrine/Tests/Models/DirectoryTree/AbstractContentItem.php +++ b/tests/Doctrine/Tests/Models/DirectoryTree/AbstractContentItem.php @@ -28,7 +28,7 @@ abstract class AbstractContentItem * @Id @Column(type="integer") @GeneratedValue */ private $id; - + /** * @ManyToOne(targetEntity="Directory") */ diff --git a/tests/Doctrine/Tests/Models/ECommerce/ECommerceCart.php b/tests/Doctrine/Tests/Models/ECommerce/ECommerceCart.php index d68b37056..3d9f6798f 100644 --- a/tests/Doctrine/Tests/Models/ECommerce/ECommerceCart.php +++ b/tests/Doctrine/Tests/Models/ECommerce/ECommerceCart.php @@ -44,26 +44,26 @@ class ECommerceCart { $this->products = new ArrayCollection; } - + public function getId() { return $this->id; } - + public function getPayment() { return $this->payment; } - + public function setPayment($payment) { $this->payment = $payment; } - + public function setCustomer(ECommerceCustomer $customer) { if ($this->customer !== $customer) { $this->customer = $customer; $customer->setCart($this); } } - + public function removeCustomer() { if ($this->customer !== null) { $customer = $this->customer; @@ -71,7 +71,7 @@ class ECommerceCart $customer->removeCart(); } } - + public function getCustomer() { return $this->customer; } diff --git a/tests/Doctrine/Tests/Models/ECommerce/ECommerceCustomer.php b/tests/Doctrine/Tests/Models/ECommerce/ECommerceCustomer.php index 0144b0998..a5de9e119 100644 --- a/tests/Doctrine/Tests/Models/ECommerce/ECommerceCustomer.php +++ b/tests/Doctrine/Tests/Models/ECommerce/ECommerceCustomer.php @@ -33,20 +33,20 @@ class ECommerceCustomer * Example of a one-one self referential association. A mentor can follow * 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"}, fetch="EAGER") * @JoinColumn(name="mentor_id", referencedColumnName="id") */ private $mentor; - + public function getId() { return $this->id; } - + public function getName() { return $this->name; } - + public function setName($name) { $this->name = $name; } @@ -55,15 +55,15 @@ class ECommerceCustomer { if ($this->cart !== $cart) { $this->cart = $cart; - $cart->setCustomer($this); + $cart->setCustomer($this); } } - + /* Does not properly maintain the bidirectional association! */ public function brokenSetCart(ECommerceCart $cart) { $this->cart = $cart; } - + public function getCart() { return $this->cart; } diff --git a/tests/Doctrine/Tests/Models/ECommerce/ECommerceFeature.php b/tests/Doctrine/Tests/Models/ECommerce/ECommerceFeature.php index 8f6cdd983..04fc2bed3 100644 --- a/tests/Doctrine/Tests/Models/ECommerce/ECommerceFeature.php +++ b/tests/Doctrine/Tests/Models/ECommerce/ECommerceFeature.php @@ -32,19 +32,19 @@ class ECommerceFeature public function getId() { return $this->id; } - + public function getDescription() { return $this->description; } - + public function setDescription($description) { $this->description = $description; } - + public function setProduct(ECommerceProduct $product) { $this->product = $product; } - + public function removeProduct() { if ($this->product !== null) { $product = $this->product; @@ -52,7 +52,7 @@ class ECommerceFeature $product->removeFeature($this); } } - + public function getProduct() { return $this->product; } diff --git a/tests/Doctrine/Tests/Models/ECommerce/ECommerceProduct.php b/tests/Doctrine/Tests/Models/ECommerce/ECommerceProduct.php index f843436b7..f053fd2cb 100644 --- a/tests/Doctrine/Tests/Models/ECommerce/ECommerceProduct.php +++ b/tests/Doctrine/Tests/Models/ECommerce/ECommerceProduct.php @@ -46,7 +46,7 @@ class ECommerceProduct private $categories; /** - * This relation is saved with two records in the association table for + * This relation is saved with two records in the association table for * simplicity. * @ManyToMany(targetEntity="ECommerceProduct", cascade={"persist"}) * @JoinTable(name="ecommerce_products_related", diff --git a/tests/Doctrine/Tests/Models/Forum/ForumUser.php b/tests/Doctrine/Tests/Models/Forum/ForumUser.php index e27623160..3f3b5d9d2 100644 --- a/tests/Doctrine/Tests/Models/Forum/ForumUser.php +++ b/tests/Doctrine/Tests/Models/Forum/ForumUser.php @@ -22,19 +22,19 @@ class ForumUser * @JoinColumn(name="avatar_id", referencedColumnName="id") */ public $avatar; - + public function getId() { return $this->id; } - + public function getUsername() { return $this->username; } - + public function getAvatar() { return $this->avatar; } - + public function setAvatar(ForumAvatar $avatar) { $this->avatar = $avatar; } diff --git a/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php b/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php index d51aa344a..ff8205987 100644 --- a/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php +++ b/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php @@ -16,12 +16,12 @@ require_once __DIR__ . '/../TestInit.php'; class CommitOrderCalculatorTest extends \Doctrine\Tests\OrmTestCase { private $_calc; - + protected function setUp() { $this->_calc = new \Doctrine\ORM\Internal\CommitOrderCalculator(); } - + public function testCommitOrdering1() { $class1 = new ClassMetadata(__NAMESPACE__ . '\NodeClass1'); @@ -29,20 +29,20 @@ class CommitOrderCalculatorTest extends \Doctrine\Tests\OrmTestCase $class3 = new ClassMetadata(__NAMESPACE__ . '\NodeClass3'); $class4 = new ClassMetadata(__NAMESPACE__ . '\NodeClass4'); $class5 = new ClassMetadata(__NAMESPACE__ . '\NodeClass5'); - + $this->_calc->addClass($class1); $this->_calc->addClass($class2); $this->_calc->addClass($class3); $this->_calc->addClass($class4); $this->_calc->addClass($class5); - + $this->_calc->addDependency($class1, $class2); $this->_calc->addDependency($class2, $class3); $this->_calc->addDependency($class3, $class4); $this->_calc->addDependency($class5, $class1); $sorted = $this->_calc->getCommitOrder(); - + // There is only 1 valid ordering for this constellation $correctOrder = array($class5, $class1, $class2, $class3, $class4); $this->assertSame($correctOrder, $sorted); diff --git a/tests/Doctrine/Tests/ORM/Criteria/DqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Criteria/DqlGenerationTest.php index f2d223d02..b3aa60792 100644 --- a/tests/Doctrine/Tests/ORM/Criteria/DqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Criteria/DqlGenerationTest.php @@ -39,7 +39,7 @@ class DqlGenerationTest extends \Doctrine\Tests\OrmTestCase protected function setUp() { $this->markTestSkipped('Not yet implemented.'); } - + protected function createQuery() { return $this->_em->createQuery(); diff --git a/tests/Doctrine/Tests/ORM/Entity/ConstructorTest.php b/tests/Doctrine/Tests/ORM/Entity/ConstructorTest.php index e21176487..014a7b421 100644 --- a/tests/Doctrine/Tests/ORM/Entity/ConstructorTest.php +++ b/tests/Doctrine/Tests/ORM/Entity/ConstructorTest.php @@ -3,13 +3,13 @@ namespace Doctrine\Tests\ORM\Entity; require_once __DIR__ . '/../../TestInit.php'; - + class ConstructorTest extends \Doctrine\Tests\OrmTestCase { public function testFieldInitializationInConstructor() { $entity = new ConstructorTestEntity1("romanb"); - $this->assertEquals("romanb", $entity->username); + $this->assertEquals("romanb", $entity->username); } } diff --git a/tests/Doctrine/Tests/ORM/EntityManagerTest.php b/tests/Doctrine/Tests/ORM/EntityManagerTest.php index f54974a27..5f1578153 100644 --- a/tests/Doctrine/Tests/ORM/EntityManagerTest.php +++ b/tests/Doctrine/Tests/ORM/EntityManagerTest.php @@ -143,7 +143,7 @@ class EntityManagerTest extends \Doctrine\Tests\OrmTestCase $this->_em->close(); $this->_em->$methodName(new \stdClass()); } - + /** * @group DDC-1125 */ @@ -152,7 +152,7 @@ class EntityManagerTest extends \Doctrine\Tests\OrmTestCase $return = $this->_em->transactional(function ($em) { return 'foo'; }); - + $this->assertEquals('foo', $return); } } \ 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 c4e43dfad..f15279672 100644 --- a/tests/Doctrine/Tests/ORM/Functional/AdvancedAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/AdvancedAssociationTest.php @@ -16,8 +16,8 @@ class AdvancedAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCase protected function setUp() { parent::setUp(); try { - $this->_schemaTool->createSchema(array( - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Phrase'), + $this->_schemaTool->createSchema(array( + $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Phrase'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\PhraseType'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Definition'), $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Lemma'), @@ -33,33 +33,33 @@ class AdvancedAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCase //setup $phrase = new Phrase; $phrase->setPhrase('lalala'); - + $type = new PhraseType; $type->setType('nonsense'); $type->setAbbreviation('non'); - + $def1 = new Definition; $def1->setDefinition('def1'); $def2 = new Definition; $def2->setDefinition('def2'); - + $phrase->setType($type); $phrase->addDefinition($def1); $phrase->addDefinition($def2); - + $this->_em->persist($phrase); $this->_em->persist($type); - + $this->_em->flush(); $this->_em->clear(); //end setup - + // test1 - lazy-loading many-to-one after find() $phrase2 = $this->_em->find('Doctrine\Tests\ORM\Functional\Phrase', $phrase->getId()); $this->assertTrue(is_numeric($phrase2->getType()->getId())); - + $this->_em->clear(); - + // test2 - eager load in DQL query $query = $this->_em->createQuery("SELECT p,t FROM Doctrine\Tests\ORM\Functional\Phrase p JOIN p.type t"); $res = $query->getResult(); @@ -67,9 +67,9 @@ class AdvancedAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCase $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(); - + // test2 - eager load in DQL query with double-join back and forth $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(); @@ -77,48 +77,48 @@ class AdvancedAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCase $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(); - + // test3 - lazy-loading one-to-many after find() $phrase3 = $this->_em->find('Doctrine\Tests\ORM\Functional\Phrase', $phrase->getId()); $definitions = $phrase3->getDefinitions(); $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $definitions); $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Definition', $definitions[0]); - + $this->_em->clear(); - + // test4 - lazy-loading after DQL query $query = $this->_em->createQuery("SELECT p FROM Doctrine\Tests\ORM\Functional\Phrase p"); $res = $query->getResult(); $definitions = $res[0]->getDefinitions(); - + $this->assertEquals(1, count($res)); - + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Definition', $definitions[0]); $this->assertEquals(2, $definitions->count()); } - + public function testManyToMany() { $lemma = new Lemma; $lemma->setLemma('abu'); - + $type = new Type(); $type->setType('nonsense'); $type->setAbbreviation('non'); - + $lemma->addType($type); - + $this->_em->persist($lemma); $this->_em->persist($type); $this->_em->flush(); - + // test5 ManyToMany $query = $this->_em->createQuery("SELECT l FROM Doctrine\Tests\ORM\Functional\Lemma l"); $res = $query->getResult(); $types = $res[0]->getTypes(); - + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Type', $types[0]); } } @@ -181,9 +181,9 @@ class Lemma { public function getLemma(){ return $this->lemma; } - + /** - * + * * @param kateglo\application\models\Type $type * @return void */ @@ -195,7 +195,7 @@ class Lemma { } /** - * + * * @param kateglo\application\models\Type $type * @return void */ @@ -208,7 +208,7 @@ class Lemma { } /** - * + * * @return kateglo\application\helpers\collections\ArrayCollection */ public function getTypes() @@ -261,7 +261,7 @@ class Type { public function __construct(){ $this->lemmas = new \Doctrine\Common\Collections\ArrayCollection(); } - + /** * * @return int @@ -305,7 +305,7 @@ class Type { } /** - * + * * @param kateglo\application\models\Lemma $lemma * @return void */ @@ -318,7 +318,7 @@ class Type { } /** - * + * * @param kateglo\application\models\Lemma $lemma * @return void */ @@ -331,7 +331,7 @@ class Type { } /** - * + * * @return kateglo\application\helpers\collections\ArrayCollection */ public function getCategories() @@ -367,7 +367,7 @@ class Phrase { * @JoinColumn(name="phrase_type_id", referencedColumnName="phrase_type_id") */ private $type; - + /** * @OneToMany(targetEntity="Definition", mappedBy="phrase", cascade={"persist"}) */ @@ -376,9 +376,9 @@ class Phrase { public function __construct() { $this->definitions = new \Doctrine\Common\Collections\ArrayCollection; } - + /** - * + * * @param Definition $definition * @return void */ @@ -386,14 +386,14 @@ class Phrase { $this->definitions[] = $definition; $definition->setPhrase($this); } - + /** * @return int */ public function getId(){ return $this->id; } - + /** * @param string $phrase * @return void @@ -401,14 +401,14 @@ class Phrase { public function setPhrase($phrase){ $this->phrase = $phrase; } - + /** * @return string */ public function getPhrase(){ return $this->phrase; } - + /** * * @param PhraseType $type @@ -417,7 +417,7 @@ class Phrase { public function setType(PhraseType $type){ $this->type = $type; } - + /** * * @return PhraseType @@ -425,9 +425,9 @@ class Phrase { public function getType(){ return $this->type; } - + /** - * + * * @return ArrayCollection */ public function getDefinitions(){ @@ -440,42 +440,42 @@ class Phrase { * @Table(name="phrase_type") */ class PhraseType { - + const CLASS_NAME = __CLASS__; - + /** * @Id * @Column(type="integer", name="phrase_type_id") * @GeneratedValue(strategy="AUTO") */ private $id; - + /** * @Column(type="string", name="phrase_type_name", unique=true) */ private $type; - + /** * @Column(type="string", name="phrase_type_abbreviation", unique=true) */ private $abbreviation; - + /** * @OneToMany(targetEntity="Phrase", mappedBy="type") */ private $phrases; - + public function __construct() { $this->phrases = new \Doctrine\Common\Collections\ArrayCollection; } - + /** * @return int */ public function getId(){ return $this->id; } - + /** * @param string $type * @return void @@ -483,14 +483,14 @@ class PhraseType { public function setType($type){ $this->type = $type; } - + /** * @return string */ public function getType(){ return $this->type; } - + /** * @param string $abbreviation * @return void @@ -498,14 +498,14 @@ class PhraseType { public function setAbbreviation($abbreviation){ $this->abbreviation = $abbreviation; } - + /** * @return string */ public function getAbbreviation(){ return $this->abbreviation; } - + /** * @param ArrayCollection $phrases * @return void @@ -513,15 +513,15 @@ class PhraseType { public function setPhrases($phrases){ $this->phrases = $phrases; } - + /** - * + * * @return ArrayCollection */ public function getPhrases(){ return $this->phrases; } - + } /** @@ -529,34 +529,34 @@ class PhraseType { * @Table(name="definition") */ class Definition { - + const CLASS_NAME = __CLASS__; - + /** * @Id * @Column(type="integer", name="definition_id") * @GeneratedValue(strategy="AUTO") */ private $id; - + /** * @ManyToOne(targetEntity="Phrase") * @JoinColumn(name="definition_phrase_id", referencedColumnName="phrase_id") */ private $phrase; - + /** * @Column(type="text", name="definition_text") */ private $definition; - + /** * @return int */ public function getId(){ return $this->id; } - + /** * @param Phrase $phrase * @return void @@ -564,14 +564,14 @@ class Definition { public function setPhrase(Phrase $phrase){ $this->phrase = $phrase; } - + /** * @return Phrase */ public function getPhrase(){ return $this->phrase; } - + public function removePhrase() { if ($this->phrase !== null) { /*@var $phrase kateglo\application\models\Phrase */ @@ -580,7 +580,7 @@ class Definition { $phrase->removeDefinition($this); } } - + /** * @param string $definition * @return void @@ -588,7 +588,7 @@ class Definition { public function setDefinition($definition){ $this->definition = $definition; } - + /** * @return string */ diff --git a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php index 77c964eea..9b68098c0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php @@ -29,9 +29,9 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $user->username = 'romanb'; $user->status = 'developer'; $this->_em->persist($user); - + $this->_em->flush(); - + $this->assertTrue(is_numeric($user->id)); $this->assertTrue($this->_em->contains($user)); @@ -128,18 +128,18 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase "SELECT user_id FROM cms_addresses WHERE id=?", array($address->id) )->fetchColumn(); $this->assertTrue(is_numeric($userId)); - + $this->_em->clear(); - + $user2 = $this->_em->createQuery('select u from \Doctrine\Tests\Models\CMS\CmsUser u where u.id=?1') ->setParameter(1, $userId) ->getSingleResult(); - + // Address has been eager-loaded because it cant be lazy $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress', $user2->address); $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $user2->address); } - + /** * @group DDC-1230 */ @@ -151,29 +151,29 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $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() { $user = new CmsUser; @@ -281,7 +281,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(0, $users[0]->phonenumbers->count()); //$this->assertNull($users[0]->articles); } - + public function testBasicRefresh() { $user = new CmsUser; @@ -291,9 +291,9 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->persist($user); $this->_em->flush(); - + $user->status = 'mascot'; - + $this->assertEquals('mascot', $user->status); $this->_em->refresh($user); $this->assertEquals('developer', $user->status); @@ -394,7 +394,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $userId = $user->id; $user = $this->_em->getReference('Doctrine\Tests\Models\CMS\CmsUser', $user->id); - + $dql = "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = ?1"; $user = $this->_em->createQuery($dql) ->setParameter(1, $userId) @@ -419,30 +419,30 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->persist($user); $this->_em->flush(); $this->_em->clear(); - + $this->assertEquals(3, $user->getPhonenumbers()->count()); - + $query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username='gblanco'"); $gblanco = $query->getSingleResult(); - + $this->assertFalse($gblanco->getPhonenumbers()->isInitialized()); - + $newPhone = new CmsPhonenumber; $newPhone->phonenumber = 555; $gblanco->addPhonenumber($newPhone); - + $this->assertFalse($gblanco->getPhonenumbers()->isInitialized()); $this->_em->persist($gblanco); $this->_em->flush(); $this->_em->clear(); - + $query = $this->_em->createQuery("select u, p from Doctrine\Tests\Models\CMS\CmsUser u join u.phonenumbers p where u.username='gblanco'"); $gblanco2 = $query->getSingleResult(); $this->assertEquals(4, $gblanco2->getPhonenumbers()->count()); } - + public function testInitializeCollectionWithNewObjectsRetainsNewObjects() { $user = new CmsUser; @@ -459,63 +459,63 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->persist($user); $this->_em->flush(); $this->_em->clear(); - + $this->assertEquals(3, $user->getPhonenumbers()->count()); - + $query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username='gblanco'"); $gblanco = $query->getSingleResult(); - + $this->assertFalse($gblanco->getPhonenumbers()->isInitialized()); - + $newPhone = new CmsPhonenumber; $newPhone->phonenumber = 555; $gblanco->addPhonenumber($newPhone); - + $this->assertFalse($gblanco->getPhonenumbers()->isInitialized()); $this->assertEquals(4, $gblanco->getPhonenumbers()->count()); $this->assertTrue($gblanco->getPhonenumbers()->isInitialized()); $this->_em->flush(); $this->_em->clear(); - + $query = $this->_em->createQuery("select u, p from Doctrine\Tests\Models\CMS\CmsUser u join u.phonenumbers p where u.username='gblanco'"); $gblanco2 = $query->getSingleResult(); $this->assertEquals(4, $gblanco2->getPhonenumbers()->count()); } - + public function testSetSetAssociationWithGetReference() { $user = new CmsUser; $user->name = 'Guilherme'; $user->username = 'gblanco'; - $user->status = 'developer'; + $user->status = 'developer'; $this->_em->persist($user); - + $address = new CmsAddress; $address->country = 'Germany'; $address->city = 'Berlin'; $address->zip = '12345'; $this->_em->persist($address); - + $this->_em->flush(); $this->_em->detach($address); - + $this->assertFalse($this->_em->contains($address)); $this->assertTrue($this->_em->contains($user)); - + // Assume we only got the identifier of the address and now want to attach // that address to the user without actually loading it, using getReference(). $addressRef = $this->_em->getReference('Doctrine\Tests\Models\CMS\CmsAddress', $address->getId()); - + //$addressRef->getId(); //\Doctrine\Common\Util\Debug::dump($addressRef); - + $user->setAddress($addressRef); // Ugh! Initializes address 'cause of $address->setUser($user)! - + $this->_em->flush(); $this->_em->clear(); - + // Check with a fresh load that the association is indeed there $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(); @@ -523,9 +523,9 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $gblanco); $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress', $gblanco->getAddress()); $this->assertEquals('Berlin', $gblanco->getAddress()->getCity()); - + } - + public function testOneToManyCascadeRemove() { $user = new CmsUser; @@ -542,19 +542,19 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->persist($user); $this->_em->flush(); $this->_em->clear(); - + $query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username='gblanco'"); $gblanco = $query->getSingleResult(); - + $this->_em->remove($gblanco); $this->_em->flush(); - + $this->_em->clear(); - + $this->assertEquals(0, $this->_em->createQuery( "select count(p.phonenumber) from Doctrine\Tests\Models\CMS\CmsPhonenumber p") ->getSingleScalarResult()); - + $this->assertEquals(0, $this->_em->createQuery( "select count(u.id) from Doctrine\Tests\Models\CMS\CmsUser u") ->getSingleScalarResult()); @@ -584,7 +584,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $articleNew = $this->_em->find('\Doctrine\Tests\Models\CMS\CmsArticle', $articleId); $this->assertTrue($this->_em->contains($articleNew)); $this->assertEquals("Lorem ipsum dolor sunt.", $articleNew->text); - + $this->assertNotSame($article, $articleNew); $articleNew->text = "Lorem ipsum dolor sunt. And stuff!"; @@ -603,64 +603,64 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $user->name = 'Guilherme'; $user->username = 'gblanco'; $user->status = 'developer'; - + $address = new CmsAddress; $address->country = 'Germany'; $address->city = 'Berlin'; $address->zip = '12345'; - + $address->user = $user; $user->address = $address; - + $article = new \Doctrine\Tests\Models\CMS\CmsArticle(); $article->text = "Lorem ipsum dolor sunt."; $article->topic = "A Test Article!"; $article->setAuthor($user); - + $this->_em->persist($article); $this->_em->persist($user); - + //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); - + $this->_em->flush(); $this->_em->clear(); - + $query = $this->_em->createQuery('select u,a,ad from Doctrine\Tests\Models\CMS\CmsUser u join u.articles a join u.address ad'); $user2 = $query->getSingleResult(); $this->assertEquals(1, count($user2->articles)); $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsAddress', $user2->address); - + $oldLogger = $this->_em->getConnection()->getConfiguration()->getSQLLogger(); $debugStack = new \Doctrine\DBAL\Logging\DebugStack; $this->_em->getConnection()->getConfiguration()->setSQLLogger($debugStack); - + $this->_em->flush(); $this->assertEquals(0, count($debugStack->queries)); - + $this->_em->getConnection()->getConfiguration()->setSQLLogger($oldLogger); } - + public function testRemoveEntityByReference() { $user = new CmsUser; $user->name = 'Guilherme'; $user->username = 'gblanco'; $user->status = 'developer'; - + //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); - + $this->_em->persist($user); $this->_em->flush(); $this->_em->clear(); - + $userRef = $this->_em->getReference('Doctrine\Tests\Models\CMS\CmsUser', $user->getId()); $this->_em->remove($userRef); $this->_em->flush(); $this->_em->clear(); - + $this->assertEquals(0, $this->_em->getConnection()->fetchColumn("select count(*) from cms_users")); - + //$this->_em->getConnection()->getConfiguration()->setSQLLogger(null); } @@ -670,26 +670,26 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $user->name = 'Guilherme'; $user->username = 'gblanco'; $user->status = 'developer'; - + $address = new CmsAddress; $address->country = 'Germany'; $address->city = 'Berlin'; $address->zip = '12345'; - + $user->setAddress($address); $this->_em->transactional(function($em) use($user) { $em->persist($user); }); $this->_em->clear(); - + //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); - + $userRef = $this->_em->getReference('Doctrine\Tests\Models\CMS\CmsUser', $user->getId()); $address2 = $this->_em->createQuery('select a from Doctrine\Tests\Models\CMS\CmsAddress a where a.user = :user') ->setParameter('user', $userRef) ->getSingleResult(); - + $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $address2->getUser()); $this->assertTrue($userRef === $address2->getUser()); $this->assertFalse($userRef->__isInitialized__); @@ -801,7 +801,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $com->topic = 'Good'; $com->text = 'Really good!'; $art->addComment($com); - + $this->_em->persist($art); // pretend we forgot to persist $com try { diff --git a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php index e8768e7ff..83320dfc7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php @@ -30,7 +30,7 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase { $person = new CompanyPerson; $person->setName('Roman S. Borschel'); - + $this->_em->persist($person); $employee = new CompanyEmployee; @@ -44,7 +44,7 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->flush(); $this->_em->clear(); - + $query = $this->_em->createQuery("select p from Doctrine\Tests\Models\Company\CompanyPerson p order by p.name desc"); $entities = $query->getResult(); @@ -59,7 +59,7 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(100000, $entities[1]->getSalary()); $this->_em->clear(); - + $query = $this->_em->createQuery("select p from Doctrine\Tests\Models\Company\CompanyEmployee p"); $entities = $query->getResult(); @@ -71,13 +71,13 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(100000, $entities[0]->getSalary()); $this->_em->clear(); - + $guilherme = $this->_em->getRepository(get_class($employee))->findOneBy(array('name' => 'Guilherme Blanco')); $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyEmployee', $guilherme); $this->assertEquals('Guilherme Blanco', $guilherme->getName()); $this->_em->clear(); - + $query = $this->_em->createQuery("update Doctrine\Tests\Models\Company\CompanyEmployee p set p.name = ?1, p.department = ?2 where p.name='Guilherme Blanco' and p.salary = ?3"); $query->setParameter(1, 'NewName', 'string'); $query->setParameter(2, 'NewDepartment'); @@ -85,12 +85,12 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $query->getSql(); $numUpdated = $query->execute(); $this->assertEquals(1, $numUpdated); - + $query = $this->_em->createQuery("delete from Doctrine\Tests\Models\Company\CompanyPerson p"); $numDeleted = $query->execute(); $this->assertEquals(2, $numDeleted); } - + public function testMultiLevelUpdateAndFind() { $manager = new CompanyManager; $manager->setName('Roman S. Borschel'); @@ -99,24 +99,24 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $manager->setTitle('CTO'); $this->_em->persist($manager); $this->_em->flush(); - + $manager->setName('Roman B.'); $manager->setSalary(119000); $manager->setTitle('CEO'); $this->_em->persist($manager); $this->_em->flush(); - + $this->_em->clear(); - + $manager = $this->_em->find('Doctrine\Tests\Models\Company\CompanyManager', $manager->getId()); - + $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyManager', $manager); $this->assertEquals('Roman B.', $manager->getName()); $this->assertEquals(119000, $manager->getSalary()); $this->assertEquals('CEO', $manager->getTitle()); $this->assertTrue(is_numeric($manager->getId())); } - + public function testFindOnBaseClass() { $manager = new CompanyManager; $manager->setName('Roman S. Borschel'); @@ -125,11 +125,11 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $manager->setTitle('CTO'); $this->_em->persist($manager); $this->_em->flush(); - + $this->_em->clear(); - + $person = $this->_em->find('Doctrine\Tests\Models\Company\CompanyPerson', $manager->getId()); - + $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyManager', $person); $this->assertEquals('Roman S. Borschel', $person->getName()); $this->assertEquals(100000, $person->getSalary()); @@ -137,34 +137,34 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertTrue(is_numeric($person->getId())); //$this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyCar', $person->getCar()); } - + public function testSelfReferencingOneToOne() { $manager = new CompanyManager; $manager->setName('John Smith'); $manager->setSalary(100000); $manager->setDepartment('IT'); $manager->setTitle('CTO'); - + $wife = new CompanyPerson; $wife->setName('Mary Smith'); $wife->setSpouse($manager); - + $this->assertSame($manager, $wife->getSpouse()); $this->assertSame($wife, $manager->getSpouse()); - + $this->_em->persist($manager); $this->_em->persist($wife); - + $this->_em->flush(); - + //var_dump($this->_em->getConnection()->fetchAll('select * from company_persons')); //var_dump($this->_em->getConnection()->fetchAll('select * from company_employees')); //var_dump($this->_em->getConnection()->fetchAll('select * from company_managers')); - + $this->_em->clear(); - + $query = $this->_em->createQuery('select p, s from Doctrine\Tests\Models\Company\CompanyPerson p join p.spouse s where p.name=\'Mary Smith\''); - + $result = $query->getResult(); $this->assertEquals(1, count($result)); $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyPerson', $result[0]); @@ -173,40 +173,40 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals('John Smith', $result[0]->getSpouse()->getName()); $this->assertSame($result[0], $result[0]->getSpouse()->getSpouse()); } - + public function testSelfReferencingManyToMany() { $person1 = new CompanyPerson; $person1->setName('Roman'); - + $person2 = new CompanyPerson; $person2->setName('Jonathan'); - + $person1->addFriend($person2); - + $this->assertEquals(1, count($person1->getFriends())); $this->assertEquals(1, count($person2->getFriends())); - - + + $this->_em->persist($person1); $this->_em->persist($person2); - + $this->_em->flush(); - + $this->_em->clear(); - + $query = $this->_em->createQuery('select p, f from Doctrine\Tests\Models\Company\CompanyPerson p join p.friends f where p.name=?1'); $query->setParameter(1, 'Roman'); - + $result = $query->getResult(); $this->assertEquals(1, count($result)); $this->assertEquals(1, count($result[0]->getFriends())); $this->assertEquals('Roman', $result[0]->getName()); - + $friends = $result[0]->getFriends(); $this->assertEquals('Jonathan', $friends[0]->getName()); } - + public function testLazyLoading1() { $org = new CompanyOrganization; @@ -216,27 +216,27 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $event2 = new CompanyRaffle; $event2->setData('raffle'); $org->addEvent($event2); - + $this->_em->persist($org); $this->_em->flush(); $this->_em->clear(); - + $orgId = $org->getId(); - + $q = $this->_em->createQuery('select a from Doctrine\Tests\Models\Company\CompanyOrganization a where a.id = ?1'); $q->setParameter(1, $orgId); - + $result = $q->getResult(); - + $this->assertEquals(1, count($result)); $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyOrganization', $result[0]); $this->assertNull($result[0]->getMainEvent()); - + $events = $result[0]->getEvents(); - + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $events); $this->assertFalse($events->isInitialized()); - + $this->assertEquals(2, count($events)); if ($events[0] instanceof CompanyAuction) { $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyRaffle', $events[1]); @@ -246,7 +246,7 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase } } - + public function testLazyLoading2() { $org = new CompanyOrganization; @@ -280,7 +280,7 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyAuction', $mainEvent); $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $mainEvent); } - + /** * @group DDC-368 */ @@ -291,9 +291,9 @@ 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 */ @@ -303,7 +303,7 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $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 e558f2abb..531b10020 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest2.php +++ b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest2.php @@ -24,30 +24,30 @@ class ClassTableInheritanceTest2 extends \Doctrine\Tests\OrmFunctionalTestCase // Swallow all exceptions. We do not test the schema tool here. } } - + public function testOneToOneAssocToBaseTypeBidirectional() { $child = new CTIChild; $child->setData('hello'); - + $related = new CTIRelated; $related->setCTIParent($child); - + $this->_em->persist($related); $this->_em->persist($child); - + $this->_em->flush(); $this->_em->clear(); - + $relatedId = $related->getId(); - + $related2 = $this->_em->find('Doctrine\Tests\ORM\Functional\CTIRelated', $relatedId); - + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\CTIRelated', $related2); $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\CTIChild', $related2->getCTIParent()); $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $related2->getCTIParent()); $this->assertEquals('hello', $related2->getCTIParent()->getData()); - + $this->assertSame($related2, $related2->getCTIParent()->getRelated()); } @@ -85,18 +85,18 @@ class CTIParent { * @GeneratedValue(strategy="AUTO") */ private $id; - + /** @OneToOne(targetEntity="CTIRelated", mappedBy="ctiParent") */ private $related; - + public function getId() { return $this->id; } - + public function getRelated() { return $this->related; - } - + } + public function setRelated($related) { $this->related = $related; $related->setCTIParent($this); @@ -111,15 +111,15 @@ class CTIChild extends CTIParent { * @Column(type="string") */ private $data; - + public function getData() { return $this->data; } - + public function setData($data) { $this->data = $data; } - + } /** @Entity */ @@ -129,21 +129,21 @@ class CTIRelated { * @GeneratedValue(strategy="AUTO") */ private $id; - + /** * @OneToOne(targetEntity="CTIParent") * @JoinColumn(name="ctiparent_id", referencedColumnName="id") */ private $ctiParent; - + public function getId() { return $this->id; } - + public function getCTIParent() { return $this->ctiParent; } - + public function setCTIParent($ctiParent) { $this->ctiParent = $ctiParent; } diff --git a/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php index 15f7e0bda..80e2fa0d6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php @@ -42,7 +42,7 @@ class CompositePrimaryKeyTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testPersistCompositePkEntity() { $this->putGermanysBrandenburderTor(); - + $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 100, 'long' => 200)); $this->assertInstanceOf('Doctrine\Tests\Models\Navigation\NavPointOfInterest', $poi); @@ -71,7 +71,7 @@ class CompositePrimaryKeyTest extends \Doctrine\Tests\OrmFunctionalTestCase $tours = $this->_em->createQuery($dql)->getResult(); $this->assertEquals(1, count($tours)); - + $pois = $tours[0]->getPointOfInterests(); $this->assertEquals(1, count($pois)); @@ -92,7 +92,7 @@ class CompositePrimaryKeyTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(1, count($tours)); } - + public function testSpecifiyUnknownIdentifierPrimaryKeyFails() { $this->setExpectedException('Doctrine\ORM\ORMException', 'The identifier long is missing for a query of Doctrine\Tests\Models\Navigation\NavPointOfInterest'); diff --git a/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php b/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php index 2e17ccf12..11511a079 100644 --- a/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/DefaultValuesTest.php @@ -29,26 +29,26 @@ class DefaultValuesTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->persist($user); $this->_em->flush(); $this->_em->clear(); - + $userId = $user->id; // e.g. from $_REQUEST $user2 = $this->_em->getReference(get_class($user), $userId); - + $this->_em->flush(); $this->assertFalse($user2->__isInitialized__); - + $a = new DefaultValueAddress; $a->country = 'de'; $a->zip = '12345'; $a->city = 'Berlin'; $a->street = 'Sesamestreet'; - + $a->user = $user2; $this->_em->persist($a); $this->_em->flush(); - + $this->assertFalse($user2->__isInitialized__); $this->_em->clear(); - + $a2 = $this->_em->find(get_class($a), $a->id); $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\DefaultValueUser', $a2->getUser()); $this->assertEquals($userId, $a2->getUser()->getId()); @@ -63,7 +63,7 @@ class DefaultValuesTest extends \Doctrine\Tests\OrmFunctionalTestCase $user = new DefaultValueUser; $user->name = 'romanb'; $user->type = 'Normaluser'; - + $this->_em->persist($user); $this->_em->flush(); $this->_em->clear(); @@ -103,7 +103,7 @@ class DefaultValueUser * @OneToOne(targetEntity="DefaultValueAddress", mappedBy="user", cascade={"persist"}) */ public $address; - + public function getId() {return $this->id;} } @@ -145,6 +145,6 @@ class DefaultValueAddress * @JoinColumn(name="user_id", referencedColumnName="id") */ public $user; - + public function getUser() {return $this->user;} } diff --git a/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php b/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php index ee265d0ea..f5c50eb11 100644 --- a/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php @@ -53,7 +53,7 @@ class DetachedEntityTest extends \Doctrine\Tests\OrmFunctionalTestCase $user->name = 'Guilherme'; $user->username = 'gblanco'; $user->status = 'developer'; - + $ph1 = new CmsPhonenumber; $ph1->phonenumber = "1234"; $user->addPhonenumber($ph1); @@ -62,23 +62,23 @@ class DetachedEntityTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->flush(); $this->assertTrue($this->_em->contains($user)); $this->assertTrue($user->phonenumbers->isInitialized()); - + $serialized = serialize($user); $this->_em->clear(); - $this->assertFalse($this->_em->contains($user)); + $this->assertFalse($this->_em->contains($user)); unset($user); - + $user = unserialize($serialized); $this->assertEquals(1, count($user->getPhonenumbers()), "Pre-Condition: 1 Phonenumber"); - + $ph2 = new CmsPhonenumber; $ph2->phonenumber = "56789"; $user->addPhonenumber($ph2); $oldPhonenumbers = $user->getPhonenumbers(); $this->assertEquals(2, count($oldPhonenumbers), "Pre-Condition: 2 Phonenumbers"); $this->assertFalse($this->_em->contains($user)); - + $this->_em->persist($ph2); // Merge back in @@ -87,7 +87,7 @@ class DetachedEntityTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $user->phonenumbers[1]->user); $im = $this->_em->getUnitOfWork()->getIdentityMap(); $this->_em->flush(); - + $this->assertTrue($this->_em->contains($user), "Failed to assert that merged user is contained inside EntityManager persistence context."); $phonenumbers = $user->getPhonenumbers(); $this->assertNotSame($oldPhonenumbers, $phonenumbers, "Merge should replace the Detached Collection with a new PersistentCollection."); diff --git a/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php b/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php index 1bf704a89..0e3be4d25 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php @@ -25,7 +25,7 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $class->associationMappings['groups']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY; $class->associationMappings['articles']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY; - + $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsGroup'); $class->associationMappings['users']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY; diff --git a/tests/Doctrine/Tests/ORM/Functional/FlushEventTest.php b/tests/Doctrine/Tests/ORM/Functional/FlushEventTest.php index 2b1d7260c..8167e8587 100644 --- a/tests/Doctrine/Tests/ORM/Functional/FlushEventTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/FlushEventTest.php @@ -25,24 +25,24 @@ class FlushEventTest extends \Doctrine\Tests\OrmFunctionalTestCase { //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); $this->_em->getEventManager()->addEventListener(Events::onFlush, new OnFlushListener); - + $user = new CmsUser; $user->username = 'romanb'; $user->name = 'Roman'; $user->status = 'Dev'; - + $this->_em->persist($user); - + $this->assertEquals(0, $user->phonenumbers->count()); - + $this->_em->flush(); - + $this->assertEquals(1, $user->phonenumbers->count()); $this->assertTrue($this->_em->contains($user->phonenumbers->get(0))); $this->assertTrue($user->phonenumbers->get(0)->getUser() === $user); - + $this->assertFalse($user->phonenumbers->isDirty()); - + // Can be used together with SQL Logging to check that a subsequent flush has // nothing to do. This proofs the correctness of the changes that happened in onFlush. //echo "SECOND FLUSH"; @@ -55,15 +55,15 @@ class OnFlushListener public function onFlush(OnFlushEventArgs $args) { //echo "---preFlush".PHP_EOL; - + $em = $args->getEntityManager(); $uow = $em->getUnitOfWork(); - + foreach ($uow->getScheduledEntityInsertions() as $entity) { - + if ($entity instanceof CmsUser) { // Adds a phonenumber to every newly persisted CmsUser ... - + $phone = new CmsPhonenumber; $phone->phonenumber = 12345; // Update object model @@ -73,20 +73,20 @@ class OnFlushListener // Explicitly calculate the changeset since onFlush is raised // after changeset calculation! $uow->computeChangeSet($em->getClassMetadata(get_class($phone)), $phone); - + // Take a snapshot because the UoW wont do this for us, because // the UoW did not visit this collection. // Alternatively we could provide an ->addVisitedCollection() method // on the UoW. $entity->getPhonenumbers()->takeSnapshot(); } - + /*foreach ($uow->getEntityChangeSet($entity) as $field => $change) { list ($old, $new) = $change; var_dump($old); }*/ - + } } } diff --git a/tests/Doctrine/Tests/ORM/Functional/IdentityMapTest.php b/tests/Doctrine/Tests/ORM/Functional/IdentityMapTest.php index 8d39c235e..84d0064a9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/IdentityMapTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/IdentityMapTest.php @@ -11,7 +11,7 @@ require_once __DIR__ . '/../../TestInit.php'; /** * IdentityMapTest - * + * * Tests correct behavior and usage of the identity map. Local values and associations * that are already fetched always prevail, unless explicitly refreshed. * @@ -23,45 +23,45 @@ class IdentityMapTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->useModelSet('cms'); parent::setUp(); } - + public function testBasicIdentityManagement() { $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(); $this->_em->clear(); - + $user2 = $this->_em->find(get_class($user), $user->getId()); $this->assertTrue($user2 !== $user); $user3 = $this->_em->find(get_class($user), $user->getId()); $this->assertTrue($user2 === $user3); - + $address2 = $this->_em->find(get_class($address), $address->getId()); $this->assertTrue($address2 !== $address); $address3 = $this->_em->find(get_class($address), $address->getId()); $this->assertTrue($address2 === $address3); - + $this->assertTrue($user2->getAddress() === $address2); // !!! } - + public function testSingleValuedAssociationIdentityMapBehaviorWithRefresh() { $address = new CmsAddress; $address->country = 'de'; $address->zip = '12345'; $address->city = 'Berlin'; - + $user1 = new CmsUser; $user1->status = 'dev'; $user1->username = 'romanb'; @@ -71,27 +71,27 @@ class IdentityMapTest extends \Doctrine\Tests\OrmFunctionalTestCase $user2->status = 'dev'; $user2->username = 'gblanco'; $user2->name = 'Guilherme Blanco'; - + $address->setUser($user1); - + $this->_em->persist($address); $this->_em->persist($user1); $this->_em->persist($user2); $this->_em->flush(); - + $this->assertSame($user1, $address->user); - + //external update to CmsAddress $this->_em->getConnection()->executeUpdate('update cms_addresses set user_id = ?', array($user2->getId())); - + // But we want to have this external change! - // Solution 1: refresh(), broken atm! + // Solution 1: refresh(), broken atm! $this->_em->refresh($address); - + // Now the association should be "correct", referencing $user2 $this->assertSame($user2, $address->user); $this->assertSame($user2->address, $address); // check back reference also - + // Attention! refreshes can result in broken bidirectional associations! this is currently expected! // $user1 still points to $address! $this->assertSame($user1->address, $address); @@ -103,7 +103,7 @@ class IdentityMapTest extends \Doctrine\Tests\OrmFunctionalTestCase $address->country = 'de'; $address->zip = '12345'; $address->city = 'Berlin'; - + $user1 = new CmsUser; $user1->status = 'dev'; $user1->username = 'romanb'; @@ -113,47 +113,47 @@ class IdentityMapTest extends \Doctrine\Tests\OrmFunctionalTestCase $user2->status = 'dev'; $user2->username = 'gblanco'; $user2->name = 'Guilherme Blanco'; - + $address->setUser($user1); - + $this->_em->persist($address); $this->_em->persist($user1); $this->_em->persist($user2); $this->_em->flush(); - - + + $this->assertSame($user1, $address->user); - + //external update to CmsAddress $this->_em->getConnection()->executeUpdate('update cms_addresses set user_id = ?', array($user2->getId())); - + //select $q = $this->_em->createQuery('select a, u from Doctrine\Tests\Models\CMS\CmsAddress a join a.user u'); $address2 = $q->getSingleResult(); - + $this->assertSame($address, $address2); - + // Should still be $user1 $this->assertSame($user1, $address2->user); $this->assertTrue($user2->address === null); - + // But we want to have this external change! // Solution 2: Alternatively, a refresh query should work $q = $this->_em->createQuery('select a, u from Doctrine\Tests\Models\CMS\CmsAddress a join a.user u'); $q->setHint(Query::HINT_REFRESH, true); $address3 = $q->getSingleResult(); - + $this->assertSame($address, $address3); // should still be the same, always from identity map - + // Now the association should be "correct", referencing $user2 $this->assertSame($user2, $address2->user); $this->assertSame($user2->address, $address2); // check back reference also - + // Attention! refreshes can result in broken bidirectional associations! this is currently expected! // $user1 still points to $address2! $this->assertSame($user1->address, $address2); } - + public function testCollectionValuedAssociationIdentityMapBehaviorWithRefreshQuery() { $user = new CmsUser; @@ -163,35 +163,35 @@ class IdentityMapTest extends \Doctrine\Tests\OrmFunctionalTestCase $phone1 = new CmsPhonenumber; $phone1->phonenumber = 123; - + $phone2 = new CmsPhonenumber; $phone2->phonenumber = 234; - + $phone3 = new CmsPhonenumber; $phone3->phonenumber = 345; - + $user->addPhonenumber($phone1); $user->addPhonenumber($phone2); $user->addPhonenumber($phone3); - + $this->_em->persist($user); // cascaded to phone numbers $this->_em->flush(); - + $this->assertEquals(3, count($user->getPhonenumbers())); $this->assertFalse($user->getPhonenumbers()->isDirty()); - + //external update to CmsAddress $this->_em->getConnection()->executeUpdate('insert into cms_phonenumbers (phonenumber, user_id) VALUES (?,?)', array(999, $user->getId())); - + //select $q = $this->_em->createQuery('select u, p from Doctrine\Tests\Models\CMS\CmsUser u join u.phonenumbers p'); $user2 = $q->getSingleResult(); - + $this->assertSame($user, $user2); - + // Should still be the same 3 phonenumbers $this->assertEquals(3, count($user2->getPhonenumbers())); - + // But we want to have this external change! // Solution 1: refresh(). //$this->_em->refresh($user2); broken atm! @@ -199,13 +199,13 @@ class IdentityMapTest extends \Doctrine\Tests\OrmFunctionalTestCase $q = $this->_em->createQuery('select u, p from Doctrine\Tests\Models\CMS\CmsUser u join u.phonenumbers p'); $q->setHint(Query::HINT_REFRESH, true); $user3 = $q->getSingleResult(); - + $this->assertSame($user, $user3); // should still be the same, always from identity map - + // Now the collection should be refreshed with correct count $this->assertEquals(4, count($user3->getPhonenumbers())); } - + public function testCollectionValuedAssociationIdentityMapBehaviorWithRefresh() { $user = new CmsUser; @@ -215,44 +215,44 @@ class IdentityMapTest extends \Doctrine\Tests\OrmFunctionalTestCase $phone1 = new CmsPhonenumber; $phone1->phonenumber = 123; - + $phone2 = new CmsPhonenumber; $phone2->phonenumber = 234; - + $phone3 = new CmsPhonenumber; $phone3->phonenumber = 345; - + $user->addPhonenumber($phone1); $user->addPhonenumber($phone2); $user->addPhonenumber($phone3); - + $this->_em->persist($user); // cascaded to phone numbers $this->_em->flush(); - + $this->assertEquals(3, count($user->getPhonenumbers())); - + //external update to CmsAddress $this->_em->getConnection()->executeUpdate('insert into cms_phonenumbers (phonenumber, user_id) VALUES (?,?)', array(999, $user->getId())); - + //select $q = $this->_em->createQuery('select u, p from Doctrine\Tests\Models\CMS\CmsUser u join u.phonenumbers p'); $user2 = $q->getSingleResult(); - + $this->assertSame($user, $user2); - + // Should still be the same 3 phonenumbers $this->assertEquals(3, count($user2->getPhonenumbers())); - + // But we want to have this external change! // Solution 1: refresh(). $this->_em->refresh($user2); - + $this->assertSame($user, $user2); // should still be the same, always from identity map - + // Now the collection should be refreshed with correct count $this->assertEquals(4, count($user2->getPhonenumbers())); } - + public function testReusedSplObjectHashDoesNotConfuseUnitOfWork() { $hash1 = $this->subRoutine($this->_em); @@ -261,7 +261,7 @@ class IdentityMapTest extends \Doctrine\Tests\OrmFunctionalTestCase // be garbage collected and thus the object hash is not reused. // This is not a memory leak! gc_collect_cycles(); - + $user1 = new CmsUser; $user1->status = 'dev'; $user1->username = 'jwage'; @@ -271,7 +271,7 @@ class IdentityMapTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->persist($user1); $this->_em->flush(); } - + private function subRoutine($em) { $user = new CmsUser; $user->status = 'dev'; @@ -281,7 +281,7 @@ class IdentityMapTest extends \Doctrine\Tests\OrmFunctionalTestCase $em->flush(); $em->remove($user); $em->flush(); - + return spl_object_hash($user); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php b/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php index 8015f341f..230f562c6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php @@ -19,30 +19,30 @@ class LifecycleCallbackTest extends \Doctrine\Tests\OrmFunctionalTestCase // Swallow all exceptions. We do not test the schema tool here. } } - + public function testPreSavePostSaveCallbacksAreInvoked() - { + { $entity = new LifecycleCallbackTestEntity; $entity->value = 'hello'; $this->_em->persist($entity); $this->_em->flush(); - + $this->assertTrue($entity->prePersistCallbackInvoked); $this->assertTrue($entity->postPersistCallbackInvoked); - + $this->_em->clear(); - + $query = $this->_em->createQuery("select e from Doctrine\Tests\ORM\Functional\LifecycleCallbackTestEntity e"); $result = $query->getResult(); $this->assertTrue($result[0]->postLoadCallbackInvoked); - + $result[0]->value = 'hello again'; - + $this->_em->flush(); - + $this->assertEquals('changed from preUpdate callback!', $result[0]->value); } - + public function testPreFlushCallbacksAreInvoked() { $entity = new LifecycleCallbackTestEntity; @@ -73,14 +73,14 @@ class LifecycleCallbackTest extends \Doctrine\Tests\OrmFunctionalTestCase $user->setValue('value'); $this->_em->persist($user); $this->_em->flush(); - + $user->setName('Alice'); $this->_em->flush(); // Triggers preUpdate - + $this->_em->clear(); - + $user2 = $this->_em->find(get_class($user), $user->getId()); - + $this->assertEquals('Alice', $user2->getName()); $this->assertEquals('Hello World', $user2->getValue()); } @@ -132,25 +132,25 @@ class LifecycleCallbackTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testCascadedEntitiesCallsPrePersist() { //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); - + $e1 = new LifecycleCallbackTestEntity; $e2 = new LifecycleCallbackTestEntity; $c = new LifecycleCallbackCascader(); $this->_em->persist($c); - + $c->entities[] = $e1; $c->entities[] = $e2; $e1->cascader = $c; $e2->cascader = $c; - + //$this->_em->persist($c); $this->_em->flush(); $this->assertTrue($e1->prePersistCallbackInvoked); $this->assertTrue($e2->prePersistCallbackInvoked); } - + public function testLifecycleCallbacksGetInherited() { $childMeta = $this->_em->getClassMetadata(__NAMESPACE__ . '\LifecycleCallbackChildEntity'); @@ -212,7 +212,7 @@ class LifecycleCallbackTestEntity public $prePersistCallbackInvoked = false; public $postPersistCallbackInvoked = false; public $postLoadCallbackInvoked = false; - + public $preFlushCallbackInvoked = false; /** @@ -234,26 +234,26 @@ class LifecycleCallbackTestEntity public function getId() { return $this->id; } - + public function getValue() { return $this->value; } - + /** @PrePersist */ public function doStuffOnPrePersist() { $this->prePersistCallbackInvoked = true; } - + /** @PostPersist */ public function doStuffOnPostPersist() { $this->postPersistCallbackInvoked = true; } - + /** @PostLoad */ public function doStuffOnPostLoad() { $this->postLoadCallbackInvoked = true; } - + /** @PreUpdate */ public function doStuffOnPreUpdate() { $this->value = 'changed from preUpdate callback!'; @@ -292,7 +292,7 @@ class LifecycleCallbackCascader class LifecycleCallbackParentEntity { /** @PrePersist */ function doStuff() { - + } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php index a597cc207..a67a44d8f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/GearmanLockTest.php @@ -51,7 +51,7 @@ class GearmanLockTest extends \Doctrine\Tests\OrmFunctionalTestCase { $this->asyncFindWithLock('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId, LockMode::PESSIMISTIC_WRITE); $this->asyncFindWithLock('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId, LockMode::PESSIMISTIC_WRITE); - + $this->assertLockWorked(); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php index b3d9e9b08..e2341a19e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php @@ -52,7 +52,7 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase $test = $q->getSingleResult(); // Manually update/increment the version so we can try and save the same - // $test and make sure the exception is thrown saying the record was + // $test and make sure the exception is thrown saying the record was // changed or updated since you read it $this->_conn->executeQuery('UPDATE optimistic_joined_parent SET version = ? WHERE id = ?', array(2, $test->id)); @@ -87,7 +87,7 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase $test = $q->getSingleResult(); // Manually update/increment the version so we can try and save the same - // $test and make sure the exception is thrown saying the record was + // $test and make sure the exception is thrown saying the record was // changed or updated since you read it $this->_conn->executeQuery('UPDATE optimistic_joined_parent SET version = ? WHERE id = ?', array(2, $test->id)); @@ -137,7 +137,7 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase $test = $q->getSingleResult(); // Manually update/increment the version so we can try and save the same - // $test and make sure the exception is thrown saying the record was + // $test and make sure the exception is thrown saying the record was // changed or updated since you read it $this->_conn->executeQuery('UPDATE optimistic_standard SET version = ? WHERE id = ?', array(2, $test->id)); @@ -249,7 +249,7 @@ class OptimisticStandard * @Version @Column(type="integer") */ private $version; - + function getVersion() {return $this->version;} } diff --git a/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php index cbdb44104..1e1df9d51 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php @@ -11,7 +11,7 @@ require_once __DIR__ . '/../../TestInit.php'; /** * Basic many-to-many association tests. * ("Working with associations") - * + * * @author robo */ class ManyToManyBasicAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCase @@ -68,55 +68,55 @@ class ManyToManyBasicAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCa $query = $this->_em->createQuery("select u, g from Doctrine\Tests\Models\CMS\CmsUser u join u.groups g"); $this->assertEquals(0, count($query->getResult())); } - + public function testManyToManyAddRemove() { $user = $this->addCmsUserGblancoWithGroups(2); $this->_em->clear(); - + $uRep = $this->_em->getRepository(get_class($user)); - + // Get user $user = $uRep->findOneById($user->getId()); $this->assertNotNull($user, "Has to return exactly one entry."); $this->assertFalse($user->getGroups()->isInitialized()); - + // Check groups $this->assertEquals(2, $user->getGroups()->count()); - + $this->assertTrue($user->getGroups()->isInitialized()); - + // Remove first group unset($user->groups[0]); //$user->getGroups()->remove(0); - + $this->_em->flush(); $this->_em->clear(); - + // Reload same user $user2 = $uRep->findOneById($user->getId()); - + // Check groups - $this->assertEquals(1, $user2->getGroups()->count()); + $this->assertEquals(1, $user2->getGroups()->count()); } - + public function testManyToManyInverseSideIgnored() { $user = $this->addCmsUserGblancoWithGroups(0); - + $group = new CmsGroup; $group->name = 'Humans'; - + // modify directly, addUser() would also (properly) set the owning side $group->users[] = $user; - + $this->_em->persist($user); $this->_em->persist($group); $this->_em->flush(); $this->_em->clear(); - + // Association should not exist $user2 = $this->_em->find(get_class($user), $user->getId()); @@ -152,11 +152,11 @@ class ManyToManyBasicAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCa $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $user->groups); $this->assertTrue($user->groups->isDirty()); - + $this->assertEquals($groupCount, count($user->groups), "There should be 10 groups in the collection."); - + $this->_em->flush(); - + $this->assertGblancoGroupCountIs($groupCount); } @@ -197,7 +197,7 @@ class ManyToManyBasicAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCa $this->assertFalse($freshUser->groups->isInitialized(), "CmsUser::groups Collection has to be uninitialized for this test."); $this->assertEquals(3, count($freshUser->getGroups())); $this->assertEquals(3, count($freshUser->getGroups()->getSnapshot()), "Snapshot of CmsUser::groups should contain 3 entries."); - + $this->_em->clear(); $freshUser = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $user->getId()); @@ -257,7 +257,7 @@ class ManyToManyBasicAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCa $group = new CmsGroup(); $group->name = "Developers0"; $this->_em->persist($group); - + $this->_em->flush(); $this->_em->clear(); @@ -268,7 +268,7 @@ class ManyToManyBasicAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCa $this->assertInternalType('array', $newUser->groups->getMapping()); $newUser->addGroup($group); - + $this->_em->flush(); $this->_em->clear(); @@ -342,7 +342,7 @@ 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 */ @@ -350,14 +350,14 @@ class ManyToManyBasicAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCa { $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 @@ -365,15 +365,15 @@ class ManyToManyBasicAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCa public function testClearBeforeLazyLoad() { $user = $this->addCmsUserGblancoWithGroups(4); - + $this->_em->clear(); - + $user = $this->_em->find(get_class($user), $user->id); - $user->groups->clear(); + $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 f8228d7ad..cfe9f1e83 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ManyToManyBidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ManyToManyBidirectionalAssociationTest.php @@ -43,7 +43,7 @@ class ManyToManyBidirectionalAssociationTest extends AbstractManyToManyAssociati $this->firstProduct->addCategory($this->secondCategory); $this->_em->persist($this->firstProduct); $this->_em->flush(); - + $this->assertForeignKeysContain($this->firstProduct->getId(), $this->firstCategory->getId()); $this->assertForeignKeysContain($this->firstProduct->getId(), $this->secondCategory->getId()); } @@ -59,10 +59,10 @@ class ManyToManyBidirectionalAssociationTest extends AbstractManyToManyAssociati $this->assertForeignKeysNotContain($this->firstProduct->getId(), $this->firstCategory->getId()); $this->assertForeignKeysContain($this->firstProduct->getId(), $this->secondCategory->getId()); - + $this->firstProduct->getCategories()->remove(1); $this->_em->flush(); - + $this->assertForeignKeysNotContain($this->firstProduct->getId(), $this->secondCategory->getId()); } @@ -90,7 +90,7 @@ class ManyToManyBidirectionalAssociationTest extends AbstractManyToManyAssociati $this->secondProduct->addCategory($this->secondCategory); $this->_em->persist($this->firstProduct); $this->_em->persist($this->secondProduct); - + $this->_em->flush(); $this->_em->clear(); } @@ -110,7 +110,7 @@ class ManyToManyBidirectionalAssociationTest extends AbstractManyToManyAssociati return $result; } - + protected function _findCategories() { $query = $this->_em->createQuery('SELECT c, p FROM Doctrine\Tests\Models\ECommerce\ECommerceCategory c LEFT JOIN c.products p ORDER BY c.id, p.id'); @@ -123,26 +123,26 @@ class ManyToManyBidirectionalAssociationTest extends AbstractManyToManyAssociati $prods2 = $result[1]->getProducts(); $this->assertTrue($prods1->isInitialized()); $this->assertTrue($prods2->isInitialized()); - + $this->assertFalse($prods1[0]->getCategories()->isInitialized()); $this->assertFalse($prods2[0]->getCategories()->isInitialized()); return $result; } - + public function assertLazyLoadFromInverseSide($products) { list ($firstProduct, $secondProduct) = $products; $firstProductCategories = $firstProduct->getCategories(); $secondProductCategories = $secondProduct->getCategories(); - + $this->assertEquals(2, count($firstProductCategories)); $this->assertEquals(2, count($secondProductCategories)); - + $this->assertTrue($firstProductCategories[0] === $secondProductCategories[0]); $this->assertTrue($firstProductCategories[1] === $secondProductCategories[1]); - + $firstCategoryProducts = $firstProductCategories[0]->getProducts(); $secondCategoryProducts = $firstProductCategories[1]->getProducts(); @@ -150,7 +150,7 @@ class ManyToManyBidirectionalAssociationTest extends AbstractManyToManyAssociati $this->assertFalse($secondCategoryProducts->isInitialized()); $this->assertEquals(0, $firstCategoryProducts->unwrap()->count()); $this->assertEquals(0, $secondCategoryProducts->unwrap()->count()); - + $this->assertEquals(2, count($firstCategoryProducts)); // lazy-load $this->assertTrue($firstCategoryProducts->isInitialized()); $this->assertFalse($secondCategoryProducts->isInitialized()); @@ -161,7 +161,7 @@ class ManyToManyBidirectionalAssociationTest extends AbstractManyToManyAssociati $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); } @@ -171,13 +171,13 @@ class ManyToManyBidirectionalAssociationTest extends AbstractManyToManyAssociati $firstCategoryProducts = $firstCategory->getProducts(); $secondCategoryProducts = $secondCategory->getProducts(); - + $this->assertEquals(2, count($firstCategoryProducts)); $this->assertEquals(2, count($secondCategoryProducts)); - + $this->assertTrue($firstCategoryProducts[0] === $secondCategoryProducts[0]); $this->assertTrue($firstCategoryProducts[1] === $secondCategoryProducts[1]); - + $firstProductCategories = $firstCategoryProducts[0]->getCategories(); $secondProductCategories = $firstCategoryProducts[1]->getCategories(); @@ -185,7 +185,7 @@ class ManyToManyBidirectionalAssociationTest extends AbstractManyToManyAssociati $this->assertFalse($secondProductCategories->isInitialized()); $this->assertEquals(0, $firstProductCategories->unwrap()->count()); $this->assertEquals(0, $secondProductCategories->unwrap()->count()); - + $this->assertEquals(2, count($firstProductCategories)); // lazy-load $this->assertTrue($firstProductCategories->isInitialized()); $this->assertFalse($secondProductCategories->isInitialized()); @@ -196,7 +196,7 @@ class ManyToManyBidirectionalAssociationTest extends AbstractManyToManyAssociati $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 2993825fa..40518e086 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ManyToManySelfReferentialAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ManyToManySelfReferentialAssociationTest.php @@ -41,7 +41,7 @@ class ManyToManySelfReferentialAssociationTest extends AbstractManyToManyAssocia $this->firstProduct->addRelated($this->secondRelated); $this->_em->persist($this->firstProduct); $this->_em->flush(); - + $this->assertForeignKeysContain($this->firstProduct->getId(), $this->firstRelated->getId()); $this->assertForeignKeysContain($this->firstProduct->getId(), @@ -67,7 +67,7 @@ class ManyToManySelfReferentialAssociationTest extends AbstractManyToManyAssocia { $this->_createLoadingFixture(); $products = $this->_findProducts(); - $this->assertLoadingOfOwningSide($products); + $this->assertLoadingOfOwningSide($products); } public function testLazyLoadsOwningSide() @@ -79,7 +79,7 @@ class ManyToManySelfReferentialAssociationTest extends AbstractManyToManyAssocia $query = $this->_em->createQuery('SELECT p FROM Doctrine\Tests\Models\ECommerce\ECommerceProduct p'); $products = $query->getResult(); - $this->assertLoadingOfOwningSide($products); + $this->assertLoadingOfOwningSide($products); } public function assertLoadingOfOwningSide($products) @@ -87,11 +87,11 @@ class ManyToManySelfReferentialAssociationTest extends AbstractManyToManyAssocia list ($firstProduct, $secondProduct) = $products; $this->assertEquals(2, count($firstProduct->getRelated())); $this->assertEquals(2, count($secondProduct->getRelated())); - - $categories = $firstProduct->getRelated(); + + $categories = $firstProduct->getRelated(); $firstRelatedBy = $categories[0]->getRelated(); $secondRelatedBy = $categories[1]->getRelated(); - + $this->assertEquals(2, count($firstRelatedBy)); $this->assertEquals(2, count($secondRelatedBy)); @@ -99,7 +99,7 @@ class ManyToManySelfReferentialAssociationTest extends AbstractManyToManyAssocia $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); } @@ -111,7 +111,7 @@ class ManyToManySelfReferentialAssociationTest extends AbstractManyToManyAssocia $this->secondProduct->addRelated($this->secondRelated); $this->_em->persist($this->firstProduct); $this->_em->persist($this->secondProduct); - + $this->_em->flush(); $this->_em->clear(); } diff --git a/tests/Doctrine/Tests/ORM/Functional/ManyToManyUnidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/ManyToManyUnidirectionalAssociationTest.php index 7de55e4f0..ba83d5315 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ManyToManyUnidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ManyToManyUnidirectionalAssociationTest.php @@ -41,7 +41,7 @@ class ManyToManyUnidirectionalAssociationTest extends AbstractManyToManyAssociat $this->firstCart->addProduct($this->secondProduct); $this->_em->persist($this->firstCart); $this->_em->flush(); - + $this->assertForeignKeysContain($this->firstCart->getId(), $this->firstProduct->getId()); $this->assertForeignKeysContain($this->firstCart->getId(), $this->secondProduct->getId()); } @@ -68,14 +68,14 @@ class ManyToManyUnidirectionalAssociationTest extends AbstractManyToManyAssociat $firstCart = $result[0]; $products = $firstCart->getProducts(); $secondCart = $result[1]; - + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $products[0]); $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $products[1]); $this->assertCollectionEquals($products, $secondCart->getProducts()); //$this->assertEquals("Doctrine 1.x Manual", $products[0]->getName()); //$this->assertEquals("Doctrine 2.x Manual", $products[1]->getName()); } - + public function testLazyLoadsCollection() { $this->_createFixture(); @@ -87,7 +87,7 @@ class ManyToManyUnidirectionalAssociationTest extends AbstractManyToManyAssociat $firstCart = $result[0]; $products = $firstCart->getProducts(); $secondCart = $result[1]; - + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $products[0]); $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $products[1]); $this->assertCollectionEquals($products, $secondCart->getProducts()); @@ -101,7 +101,7 @@ class ManyToManyUnidirectionalAssociationTest extends AbstractManyToManyAssociat $this->secondCart->addProduct($this->secondProduct); $this->_em->persist($this->firstCart); $this->_em->persist($this->secondCart); - + $this->_em->flush(); $this->_em->clear(); } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php index e39e10b3e..a9258dacf 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php @@ -34,7 +34,7 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona $this->product->addFeature($this->secondFeature); $this->_em->persist($this->product); $this->_em->flush(); - + $this->assertFeatureForeignKeyIs($this->product->getId(), $this->firstFeature); $this->assertFeatureForeignKeyIs($this->product->getId(), $this->secondFeature); } @@ -51,7 +51,7 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona $this->product->brokenAddFeature($this->firstFeature); $this->_em->persist($this->product); $this->_em->flush(); - + $this->assertFeatureForeignKeyIs(null, $this->firstFeature); } @@ -74,9 +74,9 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona $query = $this->_em->createQuery('select p, f from Doctrine\Tests\Models\ECommerce\ECommerceProduct p join p.features f'); $result = $query->getResult(); $product = $result[0]; - + $features = $product->getFeatures(); - + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $features[0]); $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $features[0]->getProduct()); $this->assertSame($product, $features[0]->getProduct()); @@ -86,7 +86,7 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $features[1]->getProduct()); $this->assertEquals('Annotations examples', $features[1]->getDescription()); } - + public function testLazyLoadsObjectsOnTheOwningSide() { $this->_createFixture(); @@ -95,7 +95,7 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona $result = $query->getResult(); $product = $result[0]; $features = $product->getFeatures(); - + $this->assertFalse($features->isInitialized()); $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $features[0]); $this->assertTrue($features->isInitialized()); @@ -112,7 +112,7 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona $query = $this->_em->createQuery('select f from Doctrine\Tests\Models\ECommerce\ECommerceFeature f'); $features = $query->getResult(); - + $product = $features[0]->getProduct(); $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $product); $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $product); @@ -120,7 +120,7 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona $this->assertSame('Doctrine Cookbook', $product->getName()); $this->assertTrue($product->__isInitialized__); } - + public function testLazyLoadsObjectsOnTheInverseSide2() { //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); @@ -128,22 +128,22 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona $query = $this->_em->createQuery('select f,p from Doctrine\Tests\Models\ECommerce\ECommerceFeature f join f.product p'); $features = $query->getResult(); - + $product = $features[0]->getProduct(); $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()); - + // This would trigger lazy-load //$this->assertEquals(2, $product->getFeatures()->count()); //$this->assertTrue($product->getFeatures()->contains($features[0])); //$this->assertTrue($product->getFeatures()->contains($features[1])); - + //$this->_em->getConnection()->getConfiguration()->setSQLLogger(null); } - + public function testJoinFromOwningSide() { $query = $this->_em->createQuery('select f,p from Doctrine\Tests\Models\ECommerce\ECommerceFeature f join f.product p'); @@ -156,7 +156,7 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona $this->product->addFeature($this->firstFeature); $this->product->addFeature($this->secondFeature); $this->_em->persist($this->product); - + $this->_em->flush(); $this->_em->clear(); } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php index e37497658..d16217157 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php @@ -33,9 +33,9 @@ class OneToManySelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunctio $this->parent->addChild($this->firstChild); $this->parent->addChild($this->secondChild); $this->_em->persist($this->parent); - + $this->_em->flush(); - + $this->assertForeignKeyIs($this->parent->getId(), $this->firstChild); $this->assertForeignKeyIs($this->parent->getId(), $this->secondChild); } @@ -52,7 +52,7 @@ class OneToManySelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunctio $this->parent->brokenAddChild($this->firstChild); $this->_em->persist($this->parent); $this->_em->flush(); - + $this->assertForeignKeyIs(null, $this->firstChild); } @@ -78,7 +78,7 @@ class OneToManySelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunctio $this->assertEquals(1, count($result)); $parent = $result[0]; $children = $parent->getChildren(); - + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCategory', $children[0]); $this->assertSame($parent, $children[0]->getParent()); $this->assertEquals(' books', strstr($children[0]->getName(), ' books')); @@ -97,7 +97,7 @@ class OneToManySelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunctio $result = $query->getResult(); $parent = $result[0]; $children = $parent->getChildren(); - + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCategory', $children[0]); $this->assertSame($parent, $children[0]->getParent()); $this->assertEquals(' books', strstr($children[0]->getName(), ' books')); @@ -111,7 +111,7 @@ class OneToManySelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunctio $this->parent->addChild($this->firstChild); $this->parent->addChild($this->secondChild); $this->_em->persist($this->parent); - + $this->_em->flush(); $this->_em->clear(); } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php index 75be67e77..ced524c45 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php @@ -31,7 +31,7 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional $this->customer->setCart($this->cart); $this->_em->persist($this->customer); $this->_em->flush(); - + $this->assertCartForeignKeyIs($this->customer->getId()); } @@ -39,7 +39,7 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional $this->customer->brokenSetCart($this->cart); $this->_em->persist($this->customer); $this->_em->flush(); - + $this->assertCartForeignKeyIs(null); } @@ -61,11 +61,11 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional $query = $this->_em->createQuery('select c, ca from Doctrine\Tests\Models\ECommerce\ECommerceCustomer c join c.cart ca'); $result = $query->getResult(); $customer = $result[0]; - + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCart', $customer->getCart()); $this->assertEquals('paypal', $customer->getCart()->getPayment()); } - + public function testLazyLoadsObjectsOnTheOwningSide() { $this->_createFixture(); $metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceCart'); @@ -74,7 +74,7 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional $query = $this->_em->createQuery('select c from Doctrine\Tests\Models\ECommerce\ECommerceCart c'); $result = $query->getResult(); $cart = $result[0]; - + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCustomer', $cart->getCustomer()); $this->assertEquals('Giorgio', $cart->getCustomer()->getName()); } @@ -88,44 +88,44 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional $query = $this->_em->createQuery('select c from Doctrine\Tests\Models\ECommerce\ECommerceCustomer c'); $result = $query->getResult(); $customer = $result[0]; - + $this->assertNull($customer->getMentor()); $this->assertInstanceOF('Doctrine\Tests\Models\ECommerce\ECommerceCart', $customer->getCart()); $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $customer->getCart()); $this->assertEquals('paypal', $customer->getCart()->getPayment()); } - + public function testUpdateWithProxyObject() - { + { $cust = new ECommerceCustomer; $cust->setName('Roman'); $cart = new ECommerceCart; $cart->setPayment('CARD'); $cust->setCart($cart); - + $this->_em->persist($cust); $this->_em->flush(); $this->_em->clear(); - + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCart', $cust->getCart()); $this->assertEquals('Roman', $cust->getName()); $this->assertSame($cust, $cart->getCustomer()); - + $query = $this->_em->createQuery('select ca from Doctrine\Tests\Models\ECommerce\ECommerceCart ca where ca.id =?1'); $query->setParameter(1, $cart->getId()); - + $cart2 = $query->getSingleResult(); - + $cart2->setPayment('CHEQUE'); $this->_em->flush(); $this->_em->clear(); - + $query2 = $this->_em->createQuery('select ca, c from Doctrine\Tests\Models\ECommerce\ECommerceCart ca left join ca.customer c where ca.id =?1'); $query2->setParameter(1, $cart->getId()); - + $cart3 = $query2->getSingleResult(); - + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceCustomer', $cart3->getCustomer()); $this->assertEquals('Roman', $cart3->getCustomer()->getName()); } @@ -137,9 +137,9 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional $cart = new ECommerceCart; $cart->setPayment('paypal'); $customer->setCart($cart); - + $this->_em->persist($customer); - + $this->_em->flush(); $this->_em->clear(); } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneEagerLoadingTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneEagerLoadingTest.php index 8257176ab..b094054eb 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneEagerLoadingTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneEagerLoadingTest.php @@ -30,7 +30,7 @@ class OneToOneEagerLoadingTest extends \Doctrine\Tests\OrmFunctionalTestCase $train = new Train(new TrainOwner("Alexander")); $driver = new TrainDriver("Benjamin"); $waggon = new Waggon(); - + $train->setDriver($driver); $train->addWaggon($waggon); diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneOrphanRemovalTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneOrphanRemovalTest.php index c9bd72fcf..6b3d0a2f0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneOrphanRemovalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneOrphanRemovalTest.php @@ -17,78 +17,78 @@ class OneToOneOrphanRemovalTest extends \Doctrine\Tests\OrmFunctionalTestCase protected function setUp() { $this->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 bcd41dcaf..326e7aec1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php @@ -10,7 +10,7 @@ require_once __DIR__ . '/../../TestInit.php'; /** * Tests a self referential one-to-one association mapping (without inheritance). - * Relation is defined as the mentor that a customer choose. The mentor could + * Relation is defined as the mentor that a customer choose. The mentor could * help only one other customer, while a customer can choose only one mentor * for receiving support. * Inverse side is not present. @@ -34,7 +34,7 @@ class OneToOneSelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunction $this->customer->setMentor($this->mentor); $this->_em->persist($this->customer); $this->_em->flush(); - + $this->assertForeignKeyIs($this->mentor->getId()); } @@ -66,24 +66,24 @@ class OneToOneSelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunction $customer = $result[0]; $this->assertLoadingOfAssociation($customer); } - + /** * @group mine * @return unknown_type */ public function testLazyLoadsAssociation() - { + { $this->_createFixture(); $metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceCustomer'); $metadata->associationMappings['mentor']['fetch'] = ClassMetadata::FETCH_LAZY; - + $query = $this->_em->createQuery("select c from Doctrine\Tests\Models\ECommerce\ECommerceCustomer c where c.name='Luke Skywalker'"); $result = $query->getResult(); $customer = $result[0]; $this->assertLoadingOfAssociation($customer); } - + public function testMultiSelfReference() { try { @@ -93,17 +93,17 @@ class OneToOneSelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunction } catch (\Exception $e) { // Swallow all exceptions. We do not test the schema tool here. } - + $entity1 = new MultiSelfReference(); $this->_em->persist($entity1); $entity1->setOther1($entity2 = new MultiSelfReference); $entity1->setOther2($entity3 = new MultiSelfReference); $this->_em->flush(); - + $this->_em->clear(); - + $entity2 = $this->_em->find(get_class($entity1), $entity1->getId()); - + $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\MultiSelfReference', $entity2->getOther1()); $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\MultiSelfReference', $entity2->getOther2()); $this->assertNull($entity2->getOther1()->getOther1()); @@ -130,9 +130,9 @@ class OneToOneSelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunction $mentor = new ECommerceCustomer; $mentor->setName('Obi-wan Kenobi'); $customer->setMentor($mentor); - + $this->_em->persist($customer); - + $this->_em->flush(); $this->_em->clear(); @@ -156,7 +156,7 @@ class MultiSelfReference { * @JoinColumn(name="other2", referencedColumnName="id") */ private $other2; - + public function getId() {return $this->id;} public function setOther1($other1) {$this->other1 = $other1;} public function getOther1() {return $this->other1;} diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php index ad4dd7404..1ffae6b13 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php @@ -33,7 +33,7 @@ class OneToOneUnidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona $this->product->setShipping($this->shipping); $this->_em->persist($this->product); $this->_em->flush(); - + $this->assertForeignKeyIs($this->shipping->getId()); } @@ -55,11 +55,11 @@ class OneToOneUnidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona $query = $this->_em->createQuery('select p, s from Doctrine\Tests\Models\ECommerce\ECommerceProduct p left join p.shipping s'); $result = $query->getResult(); $product = $result[0]; - + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceShipping', $product->getShipping()); $this->assertEquals(1, $product->getShipping()->getDays()); } - + public function testLazyLoadsObjects() { $this->_createFixture(); $metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceProduct'); @@ -68,7 +68,7 @@ class OneToOneUnidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona $query = $this->_em->createQuery('select p from Doctrine\Tests\Models\ECommerce\ECommerceProduct p'); $result = $query->getResult(); $product = $result[0]; - + $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceShipping', $product->getShipping()); $this->assertEquals(1, $product->getShipping()->getDays()); } @@ -78,10 +78,10 @@ class OneToOneUnidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona $query = $this->_em->createQuery('select p from Doctrine\Tests\Models\ECommerce\ECommerceProduct p'); $query->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true); - + $result = $query->getResult(); $product = $result[0]; - + $this->assertNull($product->getShipping()); } @@ -92,9 +92,9 @@ class OneToOneUnidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona $shipping = new ECommerceShipping; $shipping->setDays('1'); $product->setShipping($shipping); - + $this->_em->persist($product); - + $this->_em->flush(); $this->_em->clear(); } diff --git a/tests/Doctrine/Tests/ORM/Functional/OrderedCollectionTest.php b/tests/Doctrine/Tests/ORM/Functional/OrderedCollectionTest.php index f22c964b8..c2e131cb3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OrderedCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OrderedCollectionTest.php @@ -87,7 +87,7 @@ class OrderedCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->persist($booking1); $this->_em->persist($booking2); - + $this->_em->flush(); $this->_em->clear(); diff --git a/tests/Doctrine/Tests/ORM/Functional/OrderedJoinedTableInheritanceCollectionTest.php b/tests/Doctrine/Tests/ORM/Functional/OrderedJoinedTableInheritanceCollectionTest.php index 0112a86bc..8c0d37b98 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OrderedJoinedTableInheritanceCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OrderedJoinedTableInheritanceCollectionTest.php @@ -61,7 +61,7 @@ class OrderedJoinedTableInheritanceCollectionTest extends \Doctrine\Tests\OrmFun $this->assertEquals(1, count($result)); $poofy = $result[0]; - + $this->assertEquals('Aari', $poofy->children[0]->getName()); $this->assertEquals('Zampa', $poofy->children[1]->getName()); } @@ -121,7 +121,7 @@ abstract class OJTIC_Pet */ class OJTIC_Cat extends OJTIC_Pet { - + } /** @@ -129,5 +129,5 @@ class OJTIC_Cat extends OJTIC_Pet */ class OJTIC_Dog extends OJTIC_Pet { - + } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/PostgreSQLIdentityStrategyTest.php b/tests/Doctrine/Tests/ORM/Functional/PostgreSQLIdentityStrategyTest.php index 74b6ed213..4ee7b7c9b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PostgreSQLIdentityStrategyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PostgreSQLIdentityStrategyTest.php @@ -28,9 +28,9 @@ class PostgreSQLIdentityStrategyTest extends \Doctrine\Tests\OrmFunctionalTestCa // drop sequence manually due to dependency $this->_em->getConnection()->exec('DROP SEQUENCE postgresqlidentityentity_id_seq CASCADE'); } - + public function testPreSavePostSaveCallbacksAreInvoked() - { + { $entity = new PostgreSQLIdentityEntity(); $entity->setValue('hello'); $this->_em->persist($entity); diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php index 13a774b76..370761194 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryCacheTest.php @@ -18,14 +18,14 @@ 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 @@ -34,7 +34,7 @@ class QueryCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase { return sizeof($this->cacheDataReflection->getValue($cache)); } - + public function testQueryCache_DependsOnHints() { @@ -103,7 +103,7 @@ class QueryCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->getConfiguration()->setQueryCacheImpl(new ArrayCache()); $query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux'); - + $cache = $this->getMock('Doctrine\Common\Cache\ArrayCache', array('doFetch', 'doSave', 'doGetStats')); $cache->expects($this->at(0)) ->method('doFetch') @@ -134,7 +134,7 @@ class QueryCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase ->method('getSqlExecutor') ->will($this->returnValue($sqlExecMock)); - $cache = $this->getMock('Doctrine\Common\Cache\CacheProvider', + $cache = $this->getMock('Doctrine\Common\Cache\CacheProvider', array('doFetch', 'doContains', 'doSave', 'doDelete', 'doFlush', 'doGetStats')); $cache->expects($this->once()) ->method('doFetch') diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php index 9841dfeb7..d62c60a60 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php @@ -210,7 +210,7 @@ class QueryDqlFunctionTest extends \Doctrine\Tests\OrmFunctionalTestCase { $result = $this->_em->createQuery('SELECT m, m.salary+2500 AS add FROM Doctrine\Tests\Models\Company\CompanyManager m') ->getResult(); - + $this->assertEquals(4, count($result)); $this->assertEquals(102500, $result[0]['add']); $this->assertEquals(202500, $result[1]['add']); @@ -256,7 +256,7 @@ class QueryDqlFunctionTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(800000, $result[2]['op']); $this->assertEquals(1600000, $result[3]['op']); } - + public function testConcatFunction() { $arg = $this->_em->createQuery('SELECT CONCAT(m.name, m.department) AS namedep FROM Doctrine\Tests\Models\Company\CompanyManager m order by namedep desc') @@ -276,12 +276,12 @@ class QueryDqlFunctionTest extends \Doctrine\Tests\OrmFunctionalTestCase { $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/ResultCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php index 3dcae4fab..2a5092188 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php @@ -19,14 +19,14 @@ 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 @@ -49,7 +49,7 @@ class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase $query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux'); $cache = new ArrayCache(); - + $query->setResultCacheDriver($cache)->setResultCacheId('my_cache_id'); $this->assertFalse($cache->contains('my_cache_id')); @@ -81,7 +81,7 @@ class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase $query->setResultCacheId('testing_result_cache_id'); $this->assertFalse($cache->contains('testing_result_cache_id')); - + $users = $query->getResult(); $this->assertTrue($cache->contains('testing_result_cache_id')); @@ -140,7 +140,7 @@ class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase $cache = new ArrayCache(); $query->setResultCacheDriver($cache)->useResultCache(true); - + $this->assertEquals(0, $this->getCacheSize($cache)); $query->getResult(); $this->assertEquals(1, $this->getCacheSize($cache)); @@ -234,7 +234,7 @@ class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase $query2 = $this->_em->createQuery('select a from Doctrine\Tests\Models\CMS\CmsArticle a WHERE a.user = ?1'); $query2->setParameter(1, $user1); - + $query2->setResultCacheDriver($cache)->useResultCache(true); $articles = $query2->getResult(); diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php index fb58bf07f..eae3d4b88 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php @@ -84,7 +84,7 @@ class DDC214Test extends \Doctrine\Tests\OrmFunctionalTestCase $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/MySqlSchemaToolTest.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/MySqlSchemaToolTest.php index be671bf3d..74d68ca60 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/MySqlSchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/MySqlSchemaToolTest.php @@ -15,7 +15,7 @@ class MySqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->markTestSkipped('The ' . __CLASS__ .' requires the use of mysql.'); } } - + public function testGetCreateSchemaSql() { $classes = array( @@ -38,7 +38,7 @@ class MySqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(9, count($sql)); } - + public function testGetCreateSchemaSql2() { $classes = array( @@ -47,11 +47,11 @@ class MySqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase $tool = new SchemaTool($this->_em); $sql = $tool->getCreateSchemaSql($classes); - + $this->assertEquals(1, count($sql)); $this->assertEquals("CREATE TABLE decimal_model (id INT AUTO_INCREMENT NOT NULL, `decimal` NUMERIC(5, 2) NOT NULL, `high_scale` NUMERIC(14, 4) NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB", $sql[0]); } - + public function testGetCreateSchemaSql3() { $classes = array( @@ -60,7 +60,7 @@ class MySqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase $tool = new SchemaTool($this->_em); $sql = $tool->getCreateSchemaSql($classes); - + $this->assertEquals(1, count($sql)); $this->assertEquals("CREATE TABLE boolean_model (id INT AUTO_INCREMENT NOT NULL, booleanField TINYINT(1) NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB", $sql[0]); } diff --git a/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php b/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php index e8132de5c..de103eb07 100644 --- a/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/StandardEntityPersisterTest.php @@ -6,7 +6,7 @@ use Doctrine\Tests\Models\ECommerce\ECommerceCart, Doctrine\Tests\Models\ECommerce\ECommerceFeature, Doctrine\Tests\Models\ECommerce\ECommerceCustomer, Doctrine\Tests\Models\ECommerce\ECommerceProduct; - + use Doctrine\ORM\Mapping\AssociationMapping; require_once __DIR__ . '/../../TestInit.php'; @@ -24,7 +24,7 @@ class StandardEntityPersisterTest extends \Doctrine\Tests\OrmFunctionalTestCase } public function testAcceptsForeignKeysAsCriteria() - { + { $customer = new ECommerceCustomer(); $customer->setName('John Doe'); $cart = new ECommerceCart(); @@ -35,16 +35,16 @@ class StandardEntityPersisterTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->clear(); $cardId = $cart->getId(); unset($cart); - + $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceCart'); - + $persister = $this->_em->getUnitOfWork()->getEntityPersister('Doctrine\Tests\Models\ECommerce\ECommerceCart'); $newCart = new ECommerceCart(); $this->_em->getUnitOfWork()->registerManaged($newCart, array('id' => $cardId), array()); $persister->load(array('customer_id' => $customer->getId()), $newCart, $class->associationMappings['customer']); $this->assertEquals('Credit card', $newCart->getPayment()); } - + /** * Ticket #2478 from Damon Jones (dljones) */ @@ -62,7 +62,7 @@ class StandardEntityPersisterTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->persist($p); $this->_em->flush(); - + $this->assertEquals(2, count($p->getFeatures())); $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $p->getFeatures()); @@ -71,12 +71,12 @@ class StandardEntityPersisterTest extends \Doctrine\Tests\OrmFunctionalTestCase FROM Doctrine\Tests\Models\ECommerce\ECommerceProduct p JOIN p.features f' ); - + $res = $q->getResult(); - + $this->assertEquals(2, count($p->getFeatures())); $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $p->getFeatures()); - + // Check that the features are the same instances still foreach ($p->getFeatures() as $feature) { if ($feature->getDescription() == 'AC-3') { @@ -85,25 +85,25 @@ class StandardEntityPersisterTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertTrue($feature === $f2); } } - - // Now we test how Hydrator affects IdentityMap + + // Now we test how Hydrator affects IdentityMap // (change from ArrayCollection to PersistentCollection) $f3 = new ECommerceFeature(); $f3->setDescription('XVID'); $p->addFeature($f3); - + // Now we persist the Feature #3 $this->_em->persist($p); $this->_em->flush(); - + $q = $this->_em->createQuery( 'SELECT p, f FROM Doctrine\Tests\Models\ECommerce\ECommerceProduct p JOIN p.features f' ); - + $res = $q->getResult(); - + // Persisted Product now must have 3 Feature items $this->assertEquals(3, count($res[0]->getFeatures())); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1041Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1041Test.php index cf5a5f223..5b30c043e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1041Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1041Test.php @@ -15,17 +15,17 @@ class DDC1041Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->useModelSet('company'); parent::setUp(); } - + public function testGrabWrongSubtypeReturnsNull() { $fix = new \Doctrine\Tests\Models\Company\CompanyFixContract(); $fix->setFixPrice(2000); - + $this->_em->persist($fix); $this->_em->flush(); - + $id = $fix->getId(); - + $this->assertNull($this->_em->find('Doctrine\Tests\Models\Company\CompanyFlexContract', $id)); $this->assertNull($this->_em->getReference('Doctrine\Tests\Models\Company\CompanyFlexContract', $id)); $this->assertNull($this->_em->getPartialReference('Doctrine\Tests\Models\Company\CompanyFlexContract', $id)); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1050Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1050Test.php index 82e9590c0..31c0733e0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1050Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1050Test.php @@ -16,7 +16,7 @@ class DDC1050Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->useModelSet('cms'); parent::setUp(); } - + public function testPerformance() { for ($i = 2; $i < 10000; ++$i) { @@ -28,7 +28,7 @@ class DDC1050Test extends \Doctrine\Tests\OrmFunctionalTestCase } $this->_em->flush(); $this->_em->clear(); - + $s = microtime(true); $users = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser')->findAll(); $e = microtime(true); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1080Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1080Test.php index 50b02e350..2b9d579a5 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1080Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1080Test.php @@ -16,50 +16,50 @@ class DDC1080Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1080Bar'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1080FooBar'), )); - + $foo1 = new DDC1080Foo(); $foo1->setFooTitle('foo title 1'); $foo2 = new DDC1080Foo(); $foo2->setFooTitle('foo title 2'); - + $bar1 = new DDC1080Bar(); $bar1->setBarTitle('bar title 1'); $bar2 = new DDC1080Bar(); $bar2->setBarTitle('bar title 2'); $bar3 = new DDC1080Bar(); $bar3->setBarTitle('bar title 3'); - + $foobar1 = new DDC1080FooBar(); $foobar1->setFoo($foo1); $foobar1->setBar($bar1); $foobar1->setOrderNr(0); - + $foobar2 = new DDC1080FooBar(); $foobar2->setFoo($foo1); $foobar2->setBar($bar2); $foobar2->setOrderNr(0); - + $foobar3 = new DDC1080FooBar(); $foobar3->setFoo($foo1); $foobar3->setBar($bar3); $foobar3->setOrderNr(0); - + $this->_em->persist($foo1); $this->_em->persist($foo2); $this->_em->persist($bar1); $this->_em->persist($bar2); $this->_em->persist($bar3); $this->_em->flush(); - + $this->_em->persist($foobar1); $this->_em->persist($foobar2); $this->_em->persist($foobar3); $this->_em->flush(); $this->_em->clear(); - + $foo = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC1080Foo', $foo1->getFooId()); $fooBars = $foo->getFooBars(); - + $this->assertEquals(3, count($fooBars), "Should return three foobars."); } } @@ -73,7 +73,7 @@ class DDC1080Foo { /** - * @Id + * @Id * @Column(name="fooID", type="integer") * @GeneratedValue(strategy="AUTO") */ @@ -151,7 +151,7 @@ class DDC1080Bar { /** - * @Id + * @Id * @Column(name="barID", type="integer") * @GeneratedValue(strategy="AUTO") */ diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1163Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1163Test.php index 7142ff211..1e8cae6db 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1163Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1163Test.php @@ -61,7 +61,7 @@ class DDC1163Test extends \Doctrine\Tests\OrmFunctionalTestCase { /* @var $proxyHolder ProxyHolder */ $proxyHolder = $this->_em->find(__NAMESPACE__ . '\\DDC1163ProxyHolder', $this->proxyHolderId); - + $this->assertInstanceOf(__NAMESPACE__.'\\DDC1163SpecialProduct', $proxyHolder->getSpecialProduct()); } @@ -72,9 +72,9 @@ class DDC1163Test extends \Doctrine\Tests\OrmFunctionalTestCase $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', @@ -115,7 +115,7 @@ class DDC1163ProxyHolder { $this->specialProduct = $specialProduct; } - + public function getSpecialProduct() { return $this->specialProduct; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php index c79bd2f46..bee6ef971 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php @@ -349,7 +349,7 @@ class DDC117Test extends \Doctrine\Tests\OrmFunctionalTestCase public function testLoadInverseManyToManyCollection() { $editor = $this->loadEditorFixture(); - + $this->assertInstanceOf('Doctrine\Tests\Models\DDC117\DDC117Translation', $editor->reviewingTranslations[0]); $reviewedBy = $editor->reviewingTranslations[0]->getReviewedByEditors(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php index 225353034..32856ace1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php @@ -15,7 +15,7 @@ class DDC1181Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1181Room'), )); } - + /** * @group DDC-1181 */ @@ -24,12 +24,12 @@ class DDC1181Test extends \Doctrine\Tests\OrmFunctionalTestCase $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; @@ -38,11 +38,11 @@ class DDC1181Test extends \Doctrine\Tests\OrmFunctionalTestCase $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(); } @@ -72,7 +72,7 @@ class DDC1181Booking /** * @var Hotel * - * @Id + * @Id * @ManyToOne(targetEntity="DDC1181Hotel", inversedBy="bookings") * @JoinColumns({ * @JoinColumn(name="hotel_id", referencedColumnName="id") diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php index 3ddf37e70..6465fa675 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1193Test.php @@ -45,7 +45,7 @@ class DDC1193Test extends \Doctrine\Tests\OrmFunctionalTestCase $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(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1276Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1276Test.php index 1b9dc8c99..a4f54b55f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1276Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1276Test.php @@ -38,7 +38,7 @@ class DDC1276Test extends \Doctrine\Tests\OrmFunctionalTestCase $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); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1383Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1383Test.php index 6a8cf483a..f6b5a2460 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1383Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1383Test.php @@ -13,7 +13,7 @@ class DDC1383Test extends \Doctrine\Tests\OrmFunctionalTestCase protected function setUp() { parent::setUp(); - + try { $this->_schemaTool->createSchema(array( $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1383AbstractEntity'), @@ -26,25 +26,25 @@ class DDC1383Test extends \Doctrine\Tests\OrmFunctionalTestCase { $parent = new DDC1383Entity(); $child = new DDC1383Entity(); - + $child->setReference($parent); - + $this->_em->persist($parent); $this->_em->persist($child); - + $id = $child->getId(); - + $this->_em->flush(); $this->_em->clear(); - + // Try merging the parent entity $child = $this->_em->merge($child); $parent = $child->getReference(); - + // Parent is not instance of the abstract class self::assertTrue($parent instanceof DDC1383AbstractEntity, "Entity class is " . get_class($parent) . ', "DDC1383AbstractEntity" was expected'); - + // Parent is NOT instance of entity self::assertTrue($parent instanceof DDC1383Entity, "Entity class is " . get_class($parent) . ', "DDC1383Entity" was expected'); @@ -65,7 +65,7 @@ abstract class DDC1383AbstractEntity * @GeneratedValue */ protected $id; - + public function getId() { return $this->id; @@ -86,7 +86,7 @@ class DDC1383Entity extends DDC1383AbstractEntity * @ManyToOne(targetEntity="DDC1383AbstractEntity") */ protected $reference; - + public function getReference() { return $this->reference; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1404Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1404Test.php index 49a282772..cc1d7c9ee 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1404Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1404Test.php @@ -19,9 +19,9 @@ class DDC1404Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1404ParentEntity'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1404ChildEntity'), )); - + $this->loadFixtures(); - + } catch (Exception $exc) { } } @@ -32,27 +32,27 @@ class DDC1404Test extends \Doctrine\Tests\OrmFunctionalTestCase $queryAll = $repository->createNamedQuery('all'); $queryFirst = $repository->createNamedQuery('first'); $querySecond = $repository->createNamedQuery('second'); - - + + $this->assertEquals('SELECT p FROM Doctrine\Tests\ORM\Functional\Ticket\DDC1404ChildEntity p', $queryAll->getDQL()); $this->assertEquals('SELECT p FROM Doctrine\Tests\ORM\Functional\Ticket\DDC1404ChildEntity p WHERE p.id = 1', $queryFirst->getDQL()); $this->assertEquals('SELECT p FROM Doctrine\Tests\ORM\Functional\Ticket\DDC1404ChildEntity p WHERE p.id = 2', $querySecond->getDQL()); - - + + $this->assertEquals(sizeof($queryAll->getResult()), 2); $this->assertEquals(sizeof($queryFirst->getResult()), 1); $this->assertEquals(sizeof($querySecond->getResult()), 1); } - - + + public function loadFixtures() { $c1 = new DDC1404ChildEntity("ChildEntity 1"); $c2 = new DDC1404ChildEntity("ChildEntity 2"); - + $this->_em->persist($c1); $this->_em->persist($c2); - + $this->_em->flush(); } @@ -60,7 +60,7 @@ class DDC1404Test extends \Doctrine\Tests\OrmFunctionalTestCase /** * @MappedSuperclass - * + * * @NamedQueries({ * @NamedQuery(name="all", query="SELECT p FROM __CLASS__ p"), * @NamedQuery(name="first", query="SELECT p FROM __CLASS__ p WHERE p.id = 1"), @@ -70,7 +70,7 @@ class DDC1404ParentEntity { /** - * @Id + * @Id * @Column(type="integer") * @GeneratedValue() */ @@ -88,7 +88,7 @@ class DDC1404ParentEntity /** * @Entity - * + * * @NamedQueries({ * @NamedQuery(name="first", query="SELECT p FROM __CLASS__ p WHERE p.id = 1"), * @NamedQuery(name="second", query="SELECT p FROM __CLASS__ p WHERE p.id = 2") @@ -98,12 +98,12 @@ class DDC1404ChildEntity extends DDC1404ParentEntity { /** - * @column(type="string") + * @column(type="string") */ private $name; - + /** - * @param string $name + * @param string $name */ public function __construct($name) { @@ -111,7 +111,7 @@ class DDC1404ChildEntity extends DDC1404ParentEntity } /** - * @return string + * @return string */ public function getName() { @@ -119,7 +119,7 @@ class DDC1404ChildEntity extends DDC1404ParentEntity } /** - * @param string $name + * @param string $name */ public function setName($name) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1430Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1430Test.php index ec2c89a09..a8102239d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1430Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1430Test.php @@ -21,7 +21,7 @@ class DDC1430Test extends \Doctrine\Tests\OrmFunctionalTestCase )); $this->loadFixtures(); } catch (\Exception $exc) { - + } } @@ -34,28 +34,28 @@ class DDC1430Test extends \Doctrine\Tests\OrmFunctionalTestCase ->groupBy('o.id, o.date') ->orderBy('o.id') ->getQuery(); - + $this->assertEquals('SELECT o.id, o.date, COUNT(p.id) AS p_count FROM Doctrine\Tests\ORM\Functional\Ticket\DDC1430Order o LEFT JOIN o.products p GROUP BY o.id, o.date ORDER BY o.id ASC', $query->getDQL()); $this->assertEquals('SELECT d0_.order_id AS order_id0, d0_.created_at AS created_at1, COUNT(d1_.id) AS sclr2 FROM DDC1430Order d0_ LEFT JOIN DDC1430OrderProduct d1_ ON d0_.order_id = d1_.order_id GROUP BY d0_.order_id, d0_.created_at ORDER BY d0_.order_id ASC', $query->getSQL()); - + $result = $query->getResult(); - + $this->assertEquals(2, sizeof($result)); - + $this->assertArrayHasKey('id', $result[0]); $this->assertArrayHasKey('id', $result[1]); - + $this->assertArrayHasKey('p_count', $result[0]); $this->assertArrayHasKey('p_count', $result[1]); - + $this->assertEquals(1, $result[0]['id']); $this->assertEquals(2, $result[1]['id']); - + $this->assertEquals(2, $result[0]['p_count']); $this->assertEquals(3, $result[1]['p_count']); } - + public function testOrderByAllObjectFields() { $repository = $this->_em->getRepository(__NAMESPACE__ . '\DDC1430Order'); @@ -65,26 +65,26 @@ class DDC1430Test extends \Doctrine\Tests\OrmFunctionalTestCase ->groupBy('o.id, o.date, o.status') ->orderBy('o.id') ->getQuery(); - - + + $this->assertEquals('SELECT o, COUNT(p.id) AS p_count FROM Doctrine\Tests\ORM\Functional\Ticket\DDC1430Order o LEFT JOIN o.products p GROUP BY o.id, o.date, o.status ORDER BY o.id ASC', $query->getDQL()); $this->assertEquals('SELECT d0_.order_id AS order_id0, d0_.created_at AS created_at1, d0_.order_status AS order_status2, COUNT(d1_.id) AS sclr3 FROM DDC1430Order d0_ LEFT JOIN DDC1430OrderProduct d1_ ON d0_.order_id = d1_.order_id GROUP BY d0_.order_id, d0_.created_at, d0_.order_status ORDER BY d0_.order_id ASC', $query->getSQL()); - + $result = $query->getResult(); - - + + $this->assertEquals(2, sizeof($result)); - + $this->assertTrue($result[0][0] instanceof DDC1430Order); $this->assertTrue($result[1][0] instanceof DDC1430Order); - + $this->assertEquals($result[0][0]->getId(), 1); $this->assertEquals($result[1][0]->getId(), 2); - + $this->assertEquals($result[0]['p_count'], 2); $this->assertEquals($result[1]['p_count'], 3); } - + public function testTicket() { $repository = $this->_em->getRepository(__NAMESPACE__ . '\DDC1430Order'); @@ -94,22 +94,22 @@ class DDC1430Test extends \Doctrine\Tests\OrmFunctionalTestCase ->groupBy('o') ->orderBy('o.id') ->getQuery(); - - + + $this->assertEquals('SELECT o, COUNT(p.id) AS p_count FROM Doctrine\Tests\ORM\Functional\Ticket\DDC1430Order o LEFT JOIN o.products p GROUP BY o ORDER BY o.id ASC', $query->getDQL()); $this->assertEquals('SELECT d0_.order_id AS order_id0, d0_.created_at AS created_at1, d0_.order_status AS order_status2, COUNT(d1_.id) AS sclr3 FROM DDC1430Order d0_ LEFT JOIN DDC1430OrderProduct d1_ ON d0_.order_id = d1_.order_id GROUP BY d0_.order_id, d0_.created_at, d0_.order_status ORDER BY d0_.order_id ASC', $query->getSQL()); - - + + $result = $query->getResult(); - + $this->assertEquals(2, sizeof($result)); - + $this->assertTrue($result[0][0] instanceof DDC1430Order); $this->assertTrue($result[1][0] instanceof DDC1430Order); - + $this->assertEquals($result[0][0]->getId(), 1); $this->assertEquals($result[1][0]->getId(), 2); - + $this->assertEquals($result[0]['p_count'], 2); $this->assertEquals($result[1]['p_count'], 3); } @@ -118,14 +118,14 @@ class DDC1430Test extends \Doctrine\Tests\OrmFunctionalTestCase { $o1 = new DDC1430Order('NEW'); $o2 = new DDC1430Order('OK'); - + $o1->addProduct(new DDC1430OrderProduct(1.1)); $o1->addProduct(new DDC1430OrderProduct(1.2)); $o2->addProduct(new DDC1430OrderProduct(2.1)); $o2->addProduct(new DDC1430OrderProduct(2.2)); $o2->addProduct(new DDC1430OrderProduct(2.3)); - + $this->_em->persist($o1); $this->_em->persist($o2); @@ -141,25 +141,25 @@ class DDC1430Order { /** - * @Id + * @Id * @Column(name="order_id", type="integer") * @GeneratedValue() */ protected $id; /** - * @Column(name="created_at", type="datetime") + * @Column(name="created_at", type="datetime") */ private $date; - + /** - * @Column(name="order_status", type="string") + * @Column(name="order_status", type="string") */ private $status; /** * @OneToMany(targetEntity="DDC1430OrderProduct", mappedBy="order", cascade={"persist", "remove"}) - * + * * @var \Doctrine\Common\Collections\ArrayCollection $products */ private $products; @@ -185,23 +185,23 @@ class DDC1430Order { return $this->date; } - + /** - * @return string + * @return string */ public function getStatus() { return $this->status; } - + /** - * @param string $status + * @param string $status */ public function setStatus($status) { $this->status = $status; } - + /** * @return \Doctrine\Common\Collections\ArrayCollection */ @@ -209,9 +209,9 @@ class DDC1430Order { return $this->products; } - + /** - * @param DDC1430OrderProduct $product + * @param DDC1430OrderProduct $product */ public function addProduct(DDC1430OrderProduct $product) { @@ -227,33 +227,33 @@ class DDC1430OrderProduct { /** - * @Id + * @Id * @Column(type="integer") * @GeneratedValue() */ protected $id; - + /** * @var DDC1430Order $order - * + * * @ManyToOne(targetEntity="DDC1430Order", inversedBy="products") * @JoinColumn(name="order_id", referencedColumnName="order_id", nullable = false) */ private $order; /** - * @column(type="float") + * @column(type="float") */ private $value; - + /** - * @param float $value + * @param float $value */ public function __construct($value) { $this->value = $value; } - + /** * @return integer */ @@ -263,7 +263,7 @@ class DDC1430OrderProduct } /** - * @return DDC1430Order + * @return DDC1430Order */ public function getOrder() { @@ -271,7 +271,7 @@ class DDC1430OrderProduct } /** - * @param DDC1430Order $order + * @param DDC1430Order $order */ public function setOrder(DDC1430Order $order) { @@ -279,7 +279,7 @@ class DDC1430OrderProduct } /** - * @return float + * @return float */ public function getValue() { @@ -287,7 +287,7 @@ class DDC1430OrderProduct } /** - * @param float $value + * @param float $value */ public function setValue($value) { diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php index 82a2e314c..dd6391a74 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php @@ -9,27 +9,27 @@ class DDC144Test extends \Doctrine\Tests\OrmFunctionalTestCase protected function setUp() { parent::setUp(); //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); - + $this->_schemaTool->createSchema(array( $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC144FlowElement'), // $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC144Expression'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC144Operand'), )); - + } - + /** * @group DDC-144 */ public function testIssue() { - + $operand = new DDC144Operand; $operand->property = 'flowValue'; $operand->operandProperty = 'operandValue'; $this->_em->persist($operand); $this->_em->flush(); - + } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1458Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1458Test.php index 2a0541afd..745b51c28 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1458Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1458Test.php @@ -88,7 +88,7 @@ class TestEntity { return $this->additional; } - + public function setAdditional($additional) { $this->additional = $additional; @@ -123,7 +123,7 @@ class TestAdditionalEntity { return $this->bool; } - + public function setBool($bool) { $this->bool = $bool; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1461Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1461Test.php index a47571a75..e6aa2e6bc 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1461Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1461Test.php @@ -25,7 +25,7 @@ class DDC1461Test extends \Doctrine\Tests\OrmFunctionalTestCase } } - + public function testChangeDetectionDeferredExplicit() { $user = new DDC1461User; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1509Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1509Test.php index 7f7e7d575..6ba0cd42f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1509Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1509Test.php @@ -21,7 +21,7 @@ class DDC1509Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1509Picture'), )); } catch (\Exception $ignored) { - + } } @@ -142,5 +142,5 @@ class DDC1509AbstractFile */ class DDC1509File extends DDC1509AbstractFile { - + } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1514Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1514Test.php index c905d0048..cc0f9728d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1514Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1514Test.php @@ -1,111 +1,111 @@ -_schemaTool->createSchema(array( - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1514EntityA'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1514EntityB'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1514EntityC'), - )); - } catch (\Exception $ignored) { - } - } - - public function testIssue() - { - $a1 = new DDC1514EntityA(); - $a1->title = "foo"; - - $a2 = new DDC1514EntityA(); - $a2->title = "bar"; - - $b1 = new DDC1514EntityB(); - $b1->entityAFrom = $a1; - $b1->entityATo = $a2; - - $b2 = new DDC1514EntityB(); - $b2->entityAFrom = $a2; - $b2->entityATo = $a1; - - $c = new DDC1514EntityC(); - $c->title = "baz"; - $a2->entityC = $c; - - $this->_em->persist($a1); - $this->_em->persist($a2); - $this->_em->persist($b1); - $this->_em->persist($b2); - $this->_em->persist($c); - $this->_em->flush(); - $this->_em->clear(); - - $dql = "SELECT a, b, ba, c FROM " . __NAMESPACE__ . "\DDC1514EntityA AS a LEFT JOIN a.entitiesB AS b LEFT JOIN b.entityATo AS ba LEFT JOIN a.entityC AS c"; - $results = $this->_em->createQuery($dql)->getResult(); - - $this->assertEquals($c->title, $results[1]->entityC->title); - } -} - -/** - * @Entity - */ -class DDC1514EntityA -{ - /** @Id @Column(type="integer") @GeneratedValue */ - public $id; - /** @Column */ - public $title; - /** @ManyToMany(targetEntity="DDC1514EntityB", mappedBy="entityAFrom") */ - public $entitiesB; - /** @ManyToOne(targetEntity="DDC1514EntityC") */ - public $entityC; - - public function __construct() - { - $this->entitiesB = new ArrayCollection(); - } -} - -/** - * @Entity - */ -class DDC1514EntityB -{ - /** @Id @Column(type="integer") @GeneratedValue */ - public $id; - - /** - * @ManyToOne(targetEntity="DDC1514EntityA", inversedBy="entitiesB") - */ - public $entityAFrom; - /** - * @ManyToOne(targetEntity="DDC1514EntityA") - */ - public $entityATo; -} - -/** - * @Entity - */ -class DDC1514EntityC -{ - /** @Id @Column(type="integer") @GeneratedValue */ - public $id; - /** @Column */ - public $title; -} +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1514EntityA'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1514EntityB'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1514EntityC'), + )); + } catch (\Exception $ignored) { + } + } + + public function testIssue() + { + $a1 = new DDC1514EntityA(); + $a1->title = "foo"; + + $a2 = new DDC1514EntityA(); + $a2->title = "bar"; + + $b1 = new DDC1514EntityB(); + $b1->entityAFrom = $a1; + $b1->entityATo = $a2; + + $b2 = new DDC1514EntityB(); + $b2->entityAFrom = $a2; + $b2->entityATo = $a1; + + $c = new DDC1514EntityC(); + $c->title = "baz"; + $a2->entityC = $c; + + $this->_em->persist($a1); + $this->_em->persist($a2); + $this->_em->persist($b1); + $this->_em->persist($b2); + $this->_em->persist($c); + $this->_em->flush(); + $this->_em->clear(); + + $dql = "SELECT a, b, ba, c FROM " . __NAMESPACE__ . "\DDC1514EntityA AS a LEFT JOIN a.entitiesB AS b LEFT JOIN b.entityATo AS ba LEFT JOIN a.entityC AS c"; + $results = $this->_em->createQuery($dql)->getResult(); + + $this->assertEquals($c->title, $results[1]->entityC->title); + } +} + +/** + * @Entity + */ +class DDC1514EntityA +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; + /** @Column */ + public $title; + /** @ManyToMany(targetEntity="DDC1514EntityB", mappedBy="entityAFrom") */ + public $entitiesB; + /** @ManyToOne(targetEntity="DDC1514EntityC") */ + public $entityC; + + public function __construct() + { + $this->entitiesB = new ArrayCollection(); + } +} + +/** + * @Entity + */ +class DDC1514EntityB +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; + + /** + * @ManyToOne(targetEntity="DDC1514EntityA", inversedBy="entitiesB") + */ + public $entityAFrom; + /** + * @ManyToOne(targetEntity="DDC1514EntityA") + */ + public $entityATo; +} + +/** + * @Entity + */ +class DDC1514EntityC +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; + /** @Column */ + public $title; +} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1548Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1548Test.php index 0baeca2f7..dc77ed60e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1548Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1548Test.php @@ -30,7 +30,7 @@ class DDC1548Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->clear(); $obt = $this->_em->find(__NAMESPACE__ . '\DDC1548Rel', $rel->id); - + $this->assertNull($obt->e2); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC168Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC168Test.php index 004acfa8c..25b63a8dc 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC168Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC168Test.php @@ -15,7 +15,7 @@ class DDC168Test extends \Doctrine\Tests\OrmFunctionalTestCase parent::setUp(); $this->oldMetadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\Company\CompanyEmployee'); - + $metadata = clone $this->oldMetadata; ksort($metadata->reflFields); $this->_em->getMetadataFactory()->setMetadataFor('Doctrine\Tests\Models\Company\CompanyEmployee', $metadata); @@ -26,7 +26,7 @@ class DDC168Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->getMetadataFactory()->setMetadataFor('Doctrine\Tests\Models\Company\CompanyEmployee', $this->oldMetadata); parent::tearDown(); } - + /** * @group DDC-168 */ diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC192Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC192Test.php index 2238c0319..18eb76943 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC192Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC192Test.php @@ -20,13 +20,13 @@ class DDC192Test extends \Doctrine\Tests\OrmFunctionalTestCase * @Entity @Table(name="ddc192_users") */ class DDC192User -{ +{ /** - * @Id @Column(name="id", type="integer") + * @Id @Column(name="id", type="integer") * @GeneratedValue(strategy="AUTO") */ public $id; - + /** * @Column(name="name", type="string") */ @@ -43,23 +43,23 @@ class DDC192Phonenumber * @Id @Column(name="phone", type="string", length=40) */ protected $phone; - + /** * @Id * @ManyToOne(targetEntity="DDC192User") * @JoinColumn(name="userId", referencedColumnName="id") */ protected $User; - - + + public function setPhone($value) { $this->phone = $value; } - + public function getPhone() { return $this->phone; } - - public function setUser(User $user) + + public function setUser(User $user) { $this->User = $user; } - + public function getUser() { return $this->User; } } \ 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 8b5eddbf8..9084ec0a6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC199Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC199Test.php @@ -15,30 +15,30 @@ class DDC199Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC199RelatedClass') )); } - + public function testPolymorphicLoading() { $child = new DDC199ChildClass; $child->parentData = 'parentData'; $child->childData = 'childData'; $this->_em->persist($child); - + $related1 = new DDC199RelatedClass; $related1->relatedData = 'related1'; $related1->parent = $child; $this->_em->persist($related1); - + $related2 = new DDC199RelatedClass; $related2->relatedData = 'related2'; $related2->parent = $child; $this->_em->persist($related2); - + $this->_em->flush(); $this->_em->clear(); - + $query = $this->_em->createQuery('select e,r from Doctrine\Tests\ORM\Functional\Ticket\DDC199ParentClass e join e.relatedEntities r'); $result = $query->getResult(); - + $this->assertEquals(1, count($result)); $this->assertInstanceOf('Doctrine\Tests\ORM\Functional\Ticket\DDC199ParentClass', $result[0]); $this->assertTrue($result[0]->relatedEntities->isInitialized()); @@ -56,18 +56,18 @@ class DDC199Test extends \Doctrine\Tests\OrmFunctionalTestCase * @DiscriminatorMap({"parent" = "DDC199ParentClass", "child" = "DDC199ChildClass"}) */ class DDC199ParentClass -{ +{ /** - * @Id @Column(type="integer") + * @Id @Column(type="integer") * @GeneratedValue(strategy="AUTO") */ public $id; - + /** * @Column(type="string") */ public $parentData; - + /** * @OneToMany(targetEntity="DDC199RelatedClass", mappedBy="parent") */ @@ -91,7 +91,7 @@ class DDC199RelatedClass public $id; /** @Column */ public $relatedData; - + /** * @ManyToOne(targetEntity="DDC199ParentClass", inversedBy="relatedEntities") * @JoinColumn(name="parent_id", referencedColumnName="id") diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC211Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC211Test.php index 27abee236..6104c9cae 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC211Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC211Test.php @@ -14,11 +14,11 @@ class DDC211Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC211Group') )); } - + public function testIssue() { //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); - + $user = new DDC211User; $user->setName('John Doe'); @@ -41,7 +41,7 @@ class DDC211Test extends \Doctrine\Tests\OrmFunctionalTestCase } $this->assertEquals(4, $user->getGroups()->count()); - + } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php index 87939ff71..413e56413 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php @@ -15,33 +15,33 @@ class DDC237Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC237EntityZ') )); } - + public function testUninitializedProxyIsInitializedOnFetchJoin() { $x = new DDC237EntityX; $y = new DDC237EntityY; $z = new DDC237EntityZ; - + $x->data = 'X'; $y->data = 'Y'; $z->data = 'Z'; - + $x->y = $y; $z->y = $y; - + $this->_em->persist($x); $this->_em->persist($y); $this->_em->persist($z); - - $this->_em->flush(); + + $this->_em->flush(); $this->_em->clear(); - + $x2 = $this->_em->find(get_class($x), $x->id); // proxy injected for Y $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $x2->y); $this->assertFalse($x2->y->__isInitialized__); - + // proxy for Y is in identity map - + $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(); @@ -49,7 +49,7 @@ class DDC237Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertTrue($z2->y->__isInitialized__); $this->assertEquals('Y', $z2->y->data); $this->assertEquals($y->id, $z2->y->id); - + // since the Y is the same, the instance from the identity map is // used, even if it is a proxy. @@ -57,7 +57,7 @@ class DDC237Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertNotSame($z, $z2); $this->assertSame($z2->y, $x2->y); $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $z2->y); - + } } @@ -66,7 +66,7 @@ class DDC237Test extends \Doctrine\Tests\OrmFunctionalTestCase * @Entity @Table(name="ddc237_x") */ class DDC237EntityX -{ +{ /** * @Id @Column(type="integer") @GeneratedValue */ @@ -103,7 +103,7 @@ class DDC237EntityZ public $id; /** @Column(type="string") */ public $data; - + /** * @OneToOne(targetEntity="DDC237EntityY") * @JoinColumn(name="y_id", referencedColumnName="id") diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC258Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC258Test.php index d1bcc166e..0d766eaa0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC258Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC258Test.php @@ -22,7 +22,7 @@ class DDC258Test extends \Doctrine\Tests\OrmFunctionalTestCase public function testIssue() { //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); - + $c1 = new DDC258Class1(); $c1->title = "Foo"; $c1->description = "Foo"; @@ -48,9 +48,9 @@ class DDC258Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals('Bar', $e2->title); $this->assertEquals('Bar', $e2->description); $this->assertEquals('Bar', $e2->text); - + $all = $this->_em->getRepository(__NAMESPACE__.'\DDC258Super')->findAll(); - + foreach ($all as $obj) { if ($obj instanceof DDC258Class1) { $this->assertEquals('Foo', $obj->title); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC279Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC279Test.php index 50bc5ec1a..6d41ea8d8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC279Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC279Test.php @@ -44,14 +44,14 @@ class DDC279Test extends \Doctrine\Tests\OrmFunctionalTestCase 'SELECT x, y, z FROM Doctrine\Tests\ORM\Functional\Ticket\DDC279EntityX x '. 'INNER JOIN x.y y INNER JOIN y.z z WHERE x.id = ?1' )->setParameter(1, $x->id); - + $result = $query->getResult(); - + $expected1 = 'Y'; $expected2 = 'Z'; $this->assertEquals(1, count($result)); - + $this->assertEquals($expected1, $result[0]->y->data); $this->assertEquals($expected2, $result[0]->y->z->data); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC345Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC345Test.php index fc2c3fc6d..757b5ab0b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC345Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC345Test.php @@ -45,7 +45,7 @@ class DDC345Test extends \Doctrine\Tests\OrmFunctionalTestCase $group->Memberships->add($membership); $this->_em->flush(); - + $this->assertEquals(1, $membership->prePersistCallCount); $this->assertEquals(0, $membership->preUpdateCallCount); $this->assertInstanceOf('DateTime', $membership->updated); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC353Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC353Test.php index 40f4ca298..df783593a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC353Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC353Test.php @@ -57,7 +57,7 @@ class DDC353Test extends \Doctrine\Tests\OrmFunctionalTestCase $fileId = $file->getFileId(); $pictureId = $picture->getPictureId(); - + $this->assertTrue($fileId > 0); $picture = $em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC353Picture', $pictureId); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php index ad1584fa0..54f76b1a7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php @@ -22,24 +22,24 @@ class DDC371Test extends \Doctrine\Tests\OrmFunctionalTestCase $parent = new DDC371Parent; $parent->data = 'parent'; $parent->children = new \Doctrine\Common\Collections\ArrayCollection; - + $child = new DDC371Child; $child->data = 'child'; - + $child->parent = $parent; $parent->children->add($child); - + $this->_em->persist($parent); $this->_em->persist($child); - + $this->_em->flush(); $this->_em->clear(); - + $children = $this->_em->createQuery('select c,p from '.__NAMESPACE__.'\DDC371Child c ' . 'left join c.parent p where c.id = 1 and p.id = 1') ->setHint(Query::HINT_REFRESH, true) ->getResult(); - + $this->assertEquals(1, count($children)); $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $children[0]->parent); $this->assertFalse($children[0]->parent->children->isInitialized()); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC381Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC381Test.php index 678135daf..9b47bc842 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC381Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC381Test.php @@ -55,9 +55,9 @@ class DDC381Entity { return $this->id; } - + public function getOtherMethod() { - + } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC422Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC422Test.php index ebe9f9d55..3a6dbdb4c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC422Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC422Test.php @@ -20,14 +20,14 @@ class DDC422Test extends \Doctrine\Tests\OrmFunctionalTestCase * @group DDC-422 */ public function testIssue() - { + { $customer = new DDC422Customer; $this->_em->persist($customer); $this->_em->flush(); $this->_em->clear(); - + $customer = $this->_em->find(get_class($customer), $customer->id); - + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $customer->contacts); $this->assertFalse($customer->contacts->isInitialized()); $contact = new DDC422Contact; @@ -35,7 +35,7 @@ class DDC422Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertTrue($customer->contacts->isDirty()); $this->assertFalse($customer->contacts->isInitialized()); $this->_em->flush(); - + $this->assertEquals(1, $this->_em->getConnection()->fetchColumn("select count(*) from ddc422_customers_contacts")); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC425Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC425Test.php index 1fbc8ff46..084da5623 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC425Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC425Test.php @@ -37,7 +37,7 @@ class DDC425Entity { * @GeneratedValue */ public $id; - + /** @Column(type="datetime") */ public $someDatetimeField; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC440Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC440Test.php index 46096fe5b..2b374a85d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC440Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC440Test.php @@ -28,12 +28,12 @@ class DDC440Test extends \Doctrine\Tests\OrmFunctionalTestCase /* The key of the problem is that the first phone is fetched via two association, main_phone and phones. - * + * * You will notice that the original_entity_datas are not loaded for the first phone. (They are for the second) - * - * In the Client entity definition, if you define the main_phone relation after the phones relation, both assertions pass. + * + * In the Client entity definition, if you define the main_phone relation after the phones relation, both assertions pass. * (for the sake or this test, I defined the main_phone relation before the phones relation) - * + * */ //Initialize some data @@ -169,7 +169,7 @@ class DDC440Client public function __construct() { - + } public function setName($value) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC444Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC444Test.php index e0ce88aa2..d89e67a2f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC444Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC444Test.php @@ -61,13 +61,13 @@ class DDC444Test extends \Doctrine\Tests\OrmFunctionalTestCase * @ChangeTrackingPolicy("DEFERRED_EXPLICIT") */ class DDC444User -{ +{ /** - * @Id @Column(name="id", type="integer") + * @Id @Column(name="id", type="integer") * @GeneratedValue(strategy="AUTO") */ public $id; - + /** * @Column(name="name", type="string") */ diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC501Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC501Test.php index 45c4340dc..22897eed9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC501Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC501Test.php @@ -82,7 +82,7 @@ class DDC501Test extends OrmFunctionalTestCase $this->assertEquals(4, count($userFromEntityManager->getPhonenumbers())); // This works fine as long as cmUser::groups doesn't cascade "merge" - // Otherwise group memberships are physically deleted now! + // Otherwise group memberships are physically deleted now! $this->assertEquals(2, count($userClone->getGroups())); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC512Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC512Test.php index b9c74d399..97245efa7 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC512Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC512Test.php @@ -24,7 +24,7 @@ class DDC512Test extends \Doctrine\Tests\OrmFunctionalTestCase $customer2 = new DDC512Customer(); $this->_em->persist($customer2); - + $this->_em->flush(); $this->_em->clear(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php index f251522ee..f029e95e9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC522Test.php @@ -32,7 +32,7 @@ class DDC522Test extends \Doctrine\Tests\OrmFunctionalTestCase public function testJoinColumnWithSameNameAsAssociationField() { //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); - + $cust = new DDC522Customer; $cust->name = "name"; $cart = new DDC522Cart; @@ -47,7 +47,7 @@ class DDC522Test extends \Doctrine\Tests\OrmFunctionalTestCase $r = $this->_em->createQuery("select ca,c from ".get_class($cart)." ca join ca.customer c") ->getResult(); - + $this->assertInstanceOf(__NAMESPACE__ . '\DDC522Cart', $r[0]); $this->assertInstanceOf(__NAMESPACE__ . '\DDC522Customer', $r[0]->customer); $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $r[0]->customer); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC531Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC531Test.php index 7ce19cfab..5e22c2cbe 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC531Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC531Test.php @@ -25,7 +25,7 @@ class DDC531Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->persist($item2); $this->_em->flush(); $this->_em->clear(); - + $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. diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC618Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC618Test.php index 82cf765c3..b51ed39ba 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC618Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC618Test.php @@ -39,7 +39,7 @@ class DDC618Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->flush(); $this->_em->clear(); } catch(\Exception $e) { - + } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php index 0dd24d50c..2ec438325 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC633Test.php @@ -17,7 +17,7 @@ class DDC633Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC633Appointment'), )); } catch(\Exception $e) { - + } } @@ -64,7 +64,7 @@ class DDC633Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->clear(); $appointments = $this->_em->createQuery("SELECT a FROM " . __NAMESPACE__ . "\DDC633Appointment a")->getResult(); - + foreach ($appointments AS $eagerAppointment) { $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $eagerAppointment->patient); $this->assertTrue($eagerAppointment->patient->__isInitialized__, "Proxy should already be initialized due to eager loading!"); @@ -79,7 +79,7 @@ class DDC633Appointment { /** @Id @Column(type="integer") @GeneratedValue */ public $id; - + /** * @OneToOne(targetEntity="DDC633Patient", inversedBy="appointment", fetch="EAGER") */ diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC656Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC656Test.php index bd8ce5357..f2bbc2aa9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC656Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC656Test.php @@ -16,7 +16,7 @@ class DDC656Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC656Entity') )); } catch(\Exception $e) { - + } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC729Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC729Test.php index 939c35d7b..376249745 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC729Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC729Test.php @@ -37,7 +37,7 @@ class DDC729Test extends \Doctrine\Tests\OrmFunctionalTestCase $a->id = $aId; $this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection', $a->related); - + $a = $this->_em->merge($a); $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $a->related); @@ -68,7 +68,7 @@ class DDC729Test extends \Doctrine\Tests\OrmFunctionalTestCase $a = new DDC729A(); $a->id = $aId; - + $a = $this->_em->merge($a); $a->related->set(0, $this->_em->merge($b1)); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC736Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC736Test.php index de9e275bf..2dfeeec6d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC736Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC736Test.php @@ -24,11 +24,11 @@ class DDC736Test extends \Doctrine\Tests\OrmFunctionalTestCase { $cust = new ECommerceCustomer; $cust->setName('roman'); - + $cart = new ECommerceCart; $cart->setPayment('cash'); $cart->setCustomer($cust); - + $this->_em->persist($cust); $this->_em->persist($cart); $this->_em->flush(); @@ -36,7 +36,7 @@ class DDC736Test extends \Doctrine\Tests\OrmFunctionalTestCase $result = $this->_em->createQuery("select c, c.name, ca, ca.payment from Doctrine\Tests\Models\ECommerce\ECommerceCart ca join ca.customer c") ->getSingleResult(/*\Doctrine\ORM\Query::HYDRATE_ARRAY*/); - + $cart2 = $result[0]; unset($result[0]); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC767Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC767Test.php index e3c3975ac..7ba337ecd 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC767Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC767Test.php @@ -52,7 +52,7 @@ class DDC767Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertNotNull($pUser, "User not retrieved from database."); $groups = array(2, 3); - + try { $this->_em->beginTransaction(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC809Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC809Test.php index 3b0734998..c586afac6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC809Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC809Test.php @@ -28,7 +28,7 @@ class DDC809Test extends \Doctrine\Tests\OrmFunctionalTestCase $conn->insert('variant_test', array('variant_id' => 545208)); $conn->insert('variant_test', array('variant_id' => 545209)); - + $conn->insert('var_spec_value_test', array('variant_id' => 545208, 'specification_value_id' => 94606)); $conn->insert('var_spec_value_test', array('variant_id' => 545208, 'specification_value_id' => 94607)); $conn->insert('var_spec_value_test', array('variant_id' => 545208, 'specification_value_id' => 94609)); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC812Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC812Test.php index 3bb0a51fd..4a80358d4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC812Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC812Test.php @@ -24,12 +24,12 @@ class DDC812Test extends \Doctrine\Tests\OrmFunctionalTestCase $article = new CmsArticle; $article->topic = "hello"; $article->text = "talk talk talk"; - + $comment = new CmsComment; $comment->topic = "good!"; $comment->text = "stuff!"; $comment->article = $article; - + $this->_em->persist($article); $this->_em->persist($comment); $this->_em->flush(); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php index 1d9de5334..599218b07 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php @@ -26,7 +26,7 @@ class DDC832Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC832Like'), )); } catch(\Exception $e) { - + } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC849Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC849Test.php index 45ff132cd..b17e60566 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC849Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC849Test.php @@ -13,71 +13,71 @@ class DDC849Test extends \Doctrine\Tests\OrmFunctionalTestCase private $user; private $group1; private $group2; - + public function setUp() { $this->useModelSet('cms'); parent::setUp(); - + $this->user = new CmsUser(); $this->user->username = "beberlei"; $this->user->name = "Benjamin"; $this->user->status = "active"; - + $this->group1 = new CmsGroup(); $this->group1->name = "Group 1"; $this->group2 = new CmsGroup(); $this->group2->name = "Group 2"; - + $this->user->addGroup($this->group1); $this->user->addGroup($this->group2); - + $this->_em->persist($this->user); $this->_em->persist($this->group1); $this->_em->persist($this->group2); - + $this->_em->flush(); $this->_em->clear(); - + $this->user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->user->getId()); } - + public function testRemoveContains() { $group1 = $this->user->groups[0]; $group2 = $this->user->groups[1]; - + $this->assertTrue($this->user->groups->contains($group1)); $this->assertTrue($this->user->groups->contains($group2)); - + $this->user->groups->removeElement($group1); $this->user->groups->remove(1); - + $this->assertFalse($this->user->groups->contains($group1)); $this->assertFalse($this->user->groups->contains($group2)); } - + public function testClearCount() { $this->user->addGroup(new CmsGroup); $this->assertEquals(3, count($this->user->groups)); - + $this->user->groups->clear(); - + $this->assertEquals(0, $this->user->groups->count()); $this->assertEquals(0, count($this->user->groups)); } - + public function testClearContains() { $group1 = $this->user->groups[0]; $group2 = $this->user->groups[1]; - + $this->assertTrue($this->user->groups->contains($group1)); $this->assertTrue($this->user->groups->contains($group2)); - + $this->user->groups->clear(); - + $this->assertFalse($this->user->groups->contains($group1)); $this->assertFalse($this->user->groups->contains($group2)); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php index fc43c207a..4ef3c08fa 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC881Test.php @@ -18,7 +18,7 @@ class DDC881Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC881Phonecall'), )); } catch (\Exception $e) { - + } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket69.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket69.php index 759a593fd..1ca35115d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket69.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket69.php @@ -58,7 +58,7 @@ class AdvancedAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCase { $relation2->setParent($lemma1); $relation2->setChild($lemma3); $relation2->setType($type1); - + $relation3 = new Relation; $relation3->setParent($lemma1); $relation3->setChild($lemma4); diff --git a/tests/Doctrine/Tests/ORM/Functional/TypeValueSqlTest.php b/tests/Doctrine/Tests/ORM/Functional/TypeValueSqlTest.php index 5a05d76d2..1bd5184d0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/TypeValueSqlTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/TypeValueSqlTest.php @@ -36,9 +36,9 @@ class TypeValueSqlTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->persist($entity); $this->_em->flush(); - + $id = $entity->id; - + $this->_em->clear(); $entity = $this->_em->find('\Doctrine\Tests\Models\CustomType\CustomTypeUpperCase', $id); diff --git a/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php b/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php index d18c4dbb7..785c19b74 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php @@ -18,7 +18,7 @@ class ResultSetMappingTest extends \Doctrine\Tests\OrmTestCase * @var ResultSetMapping */ private $_rsm; - + /** * @var \Doctrine\ORM\EntityManager */ @@ -63,16 +63,16 @@ class ResultSetMappingTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals('username', $this->_rsm->getFieldName('username')); $this->assertEquals('name', $this->_rsm->getFieldName('name')); } - + /** * @group DDC-1057 - * + * * Fluent interface test, not a real result set mapping */ public function testFluentInterface() { $rms = $this->_rsm; - + $rms->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser','u') ->addJoinedEntityResult('Doctrine\Tests\Models\CMS\CmsPhonenumber','p','u','phonenumbers') ->addFieldResult('u', 'id', 'id') @@ -83,8 +83,8 @@ class ResultSetMappingTest extends \Doctrine\Tests\OrmTestCase ->addIndexByScalar('sclr0') ->addScalarResult('sclr0', 'numPhones') ->addMetaResult('a', 'user_id', 'user_id'); - - + + $this->assertTrue($rms->hasIndexBy('id')); $this->assertTrue($rms->isFieldResult('id')); $this->assertTrue($rms->isFieldResult('name')); diff --git a/tests/Doctrine/Tests/ORM/Id/AssignedGeneratorTest.php b/tests/Doctrine/Tests/ORM/Id/AssignedGeneratorTest.php index 6a645d8b0..3a009e5ea 100644 --- a/tests/Doctrine/Tests/ORM/Id/AssignedGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Id/AssignedGeneratorTest.php @@ -36,14 +36,14 @@ class AssignedGeneratorTest extends \Doctrine\Tests\OrmTestCase $this->fail('Assigned generator did not throw exception even though ID was missing.'); } catch (\Doctrine\ORM\ORMException $expected) {} } - + public function testCorrectIdGeneration() { $entity = new AssignedSingleIdEntity; $entity->myId = 1; $id = $this->_assignedGen->generate($this->_em, $entity); $this->assertEquals(array('myId' => 1), $id); - + $entity = new AssignedCompositeIdEntity; $entity->myId2 = 2; $entity->myId1 = 4; diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 2499d4eb6..330955a6f 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -373,22 +373,22 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals(ClassMetadataInfo::GENERATOR_TYPE_NONE, $class->generatorType); } - + /** * @group DDC-1170 */ public function testIdentifierColumnDefinition() { - + $class = $this->createClassMetadata(__NAMESPACE__ . '\DDC1170Entity'); - + $this->assertArrayHasKey('id', $class->fieldMappings); $this->assertArrayHasKey('value', $class->fieldMappings); - + $this->assertArrayHasKey('columnDefinition', $class->fieldMappings['id']); $this->assertArrayHasKey('columnDefinition', $class->fieldMappings['value']); - + $this->assertEquals("INT unsigned NOT NULL", $class->fieldMappings['id']['columnDefinition']); $this->assertEquals("VARCHAR(255) NOT NULL", $class->fieldMappings['value']['columnDefinition']); } @@ -626,13 +626,13 @@ class DDC1170Entity { /** - * @param string $value + * @param string $value */ function __construct($value = null) { $this->value = $value; } - + /** * @Id * @GeneratedValue(strategy="NONE") @@ -644,7 +644,7 @@ class DDC1170Entity * @Column(columnDefinition = "VARCHAR(255) NOT NULL") */ private $value; - + /** * @return integer */ @@ -660,7 +660,7 @@ class DDC1170Entity { return $this->value; } - + public static function loadMetadata(ClassMetadataInfo $metadata) { $metadata->mapField(array( diff --git a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php index 9273f7c6b..dae4cd27a 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php @@ -146,7 +146,7 @@ class AnnotationDriverTest extends AbstractMappingDriverTest "mapped superclass 'Doctrine\Tests\ORM\Mapping\InvalidMappedSuperClass#users'"); $usingInvalidMsc = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\UsingInvalidMappedSuperClass'); } - + /** * @group DDC-1050 */ @@ -164,39 +164,39 @@ class AnnotationDriverTest extends AbstractMappingDriverTest "superclass 'Doctrine\Tests\ORM\Mapping\MappedSuperClassInheritence'."); $usingInvalidMsc = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\MappedSuperClassInheritence'); } - + /** * @group DDC-1034 */ public function testInheritanceSkipsParentLifecycleCallbacks() { $annotationDriver = $this->_loadDriver(); - + $cm = new ClassMetadata('Doctrine\Tests\ORM\Mapping\AnnotationChild'); $em = $this->_getTestEntityManager(); $em->getConfiguration()->setMetadataDriverImpl($annotationDriver); $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory(); $factory->setEntityManager($em); - + $cm = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\AnnotationChild'); $this->assertEquals(array("postLoad" => array("postLoad"), "preUpdate" => array("preUpdate")), $cm->lifecycleCallbacks); - + $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'); } @@ -253,7 +253,7 @@ class UsingInvalidMappedSuperClass extends InvalidMappedSuperClass */ class MappedSuperClassInheritence { - + } /** @@ -268,21 +268,21 @@ class AnnotationParent * @Id @Column(type="integer") @GeneratedValue */ private $id; - + /** * @PostLoad */ public function postLoad() { - + } - + /** * @PreUpdate */ public function preUpdate() { - + } } @@ -292,7 +292,7 @@ class AnnotationParent */ class AnnotationChild extends AnnotationParent { - + } /** diff --git a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php index 1d8d6c118..dfaf8c19a 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php @@ -10,12 +10,12 @@ require_once __DIR__ . '/../../TestInit.php'; class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase { private $_factory; - + protected function setUp() { $this->_factory = new ClassMetadataFactory(); $this->_factory->setEntityManager($this->_getTestEntityManager()); } - + /** * @expectedException Doctrine\ORM\Mapping\MappingException */ @@ -23,60 +23,60 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase { $this->_factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\TransientBaseClass'); } - + public function testGetMetadataForSubclassWithTransientBaseClass() { $class = $this->_factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\EntitySubClass'); - + $this->assertTrue(empty($class->subClasses)); $this->assertTrue(empty($class->parentClasses)); $this->assertTrue(isset($class->fieldMappings['id'])); $this->assertTrue(isset($class->fieldMappings['name'])); } - + public function testGetMetadataForSubclassWithMappedSuperclass() { $class = $this->_factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\EntitySubClass2'); - + $this->assertTrue(empty($class->subClasses)); $this->assertTrue(empty($class->parentClasses)); - + $this->assertTrue(isset($class->fieldMappings['mapped1'])); $this->assertTrue(isset($class->fieldMappings['mapped2'])); $this->assertTrue(isset($class->fieldMappings['id'])); $this->assertTrue(isset($class->fieldMappings['name'])); - + $this->assertFalse(isset($class->fieldMappings['mapped1']['inherited'])); $this->assertFalse(isset($class->fieldMappings['mapped2']['inherited'])); $this->assertFalse(isset($class->fieldMappings['transient'])); - + $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"); @@ -96,29 +96,29 @@ 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 discriminator 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 @@ -126,10 +126,10 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase public function testMappedSuperclassWithId() { $class = $this->_factory->getMetadataFor(__NAMESPACE__ . '\\SuperclassEntity'); - + $this->assertTrue(isset($class->fieldMappings['id'])); } - + /** * @group DDC-1156 * @group DDC-1218 @@ -138,11 +138,11 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase { $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 @@ -151,11 +151,11 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase { $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 @@ -164,7 +164,7 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase { $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); } @@ -285,7 +285,7 @@ class SuperclassEntity extends SuperclassBase abstract class SuperclassBase { /** - * @Column(type="integer") @Id @GeneratedValue(strategy="SEQUENCE") + * @Column(type="integer") @Id @GeneratedValue(strategy="SEQUENCE") * @SequenceGenerator(sequenceName="foo", initialValue=10) * @var int */ @@ -297,7 +297,7 @@ abstract class SuperclassBase */ abstract class MediumSuperclassBase extends SuperclassBase { - + } /** @@ -305,7 +305,7 @@ abstract class MediumSuperclassBase extends SuperclassBase */ class MediumSuperclassEntity extends MediumSuperclassBase { - + } /** @@ -313,5 +313,5 @@ class MediumSuperclassEntity extends MediumSuperclassBase */ class SubclassWithRepository extends \Doctrine\Tests\Models\DDC869\DDC869Payment { - + } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index 00b8f5f16..252428399 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -82,7 +82,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase $this->assertFalse($h2); $this->assertTrue($h1); } - + /** * @group DDC-1512 */ @@ -98,13 +98,13 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase ->method('isTransient') ->with($this->equalTo('Doctrine\Tests\Models\CMS\CmsArticle')) ->will($this->returnValue(false)); - + $em = $this->_createEntityManager($driver); - + $this->assertTrue($em->getMetadataFactory()->isTransient('Doctrine\Tests\Models\CMS\CmsUser')); $this->assertFalse($em->getMetadataFactory()->isTransient('Doctrine\Tests\Models\CMS\CmsArticle')); } - + /** * @group DDC-1512 */ @@ -120,10 +120,10 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase ->method('isTransient') ->with($this->equalTo('Doctrine\Tests\Models\CMS\CmsArticle')) ->will($this->returnValue(false)); - + $em = $this->_createEntityManager($driver); $em->getConfiguration()->addEntityNamespace('CMS', 'Doctrine\Tests\Models\CMS'); - + $this->assertTrue($em->getMetadataFactory()->isTransient('CMS:CmsUser')); $this->assertFalse($em->getMetadataFactory()->isTransient('CMS:CmsArticle')); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataLoadEventTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataLoadEventTest.php index 64357cf99..5ef67c3eb 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataLoadEventTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataLoadEventTest.php @@ -6,7 +6,7 @@ use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Events; require_once __DIR__ . '/../../TestInit.php'; - + class ClassMetadataLoadEventTest extends \Doctrine\Tests\OrmTestCase { public function testEvent() diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php index 55726e387..fb43eeae7 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php @@ -7,7 +7,7 @@ use Doctrine\ORM\Events; require_once __DIR__ . '/../../TestInit.php'; require_once __DIR__ . '/../../Models/Global/GlobalNamespaceModel.php'; - + class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase { public function testClassMetadataInstanceSerialization() @@ -94,7 +94,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals("DoctrineGlobal_User", $cm->associationMappings['author']['targetEntity']); } - + public function testMapManyToManyJoinTableDefaults() { $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); @@ -103,7 +103,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase 'fieldName' => 'groups', 'targetEntity' => 'CmsGroup' )); - + $assoc = $cm->associationMappings['groups']; //$this->assertInstanceOf('Doctrine\ORM\Mapping\ManyToManyMapping', $assoc); $this->assertEquals(array( @@ -236,7 +236,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase $this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $cm->mapField(array('fieldName' => 'name', 'columnName' => 'name')); } - + /** * @group DDC-1224 */ @@ -244,7 +244,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase { $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $cm->setTableName('foo.bar'); - + $this->assertEquals('foo_bar_id_tmp', $cm->getTemporaryIdTableName()); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/DriverChainTest.php b/tests/Doctrine/Tests/ORM/Mapping/DriverChainTest.php index dc8bc695d..2383db64c 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/DriverChainTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/DriverChainTest.php @@ -45,7 +45,7 @@ class DriverChainTest extends \Doctrine\Tests\OrmTestCase $classMetadata = new \Doctrine\ORM\Mapping\ClassMetadata($className); $chain = new DriverChain(); - + $this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $chain->loadMetadataForClass($className, $classMetadata); } @@ -81,7 +81,7 @@ class DriverChainTest extends \Doctrine\Tests\OrmTestCase * @group DDC-706 */ public function testIsTransient() - { + { $chain = new DriverChain(); $chain->addDriver($this->createAnnotationDriver(), 'Doctrine\Tests\Models\CMS'); @@ -92,5 +92,5 @@ class DriverChainTest extends \Doctrine\Tests\OrmTestCase class DriverChainEntity { - + } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php index 980a720df..e04543db0 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php @@ -53,7 +53,7 @@ class XmlMappingDriverTest extends AbstractMappingDriverTest /** * @group DDC-1468 - * + * * @expectedException Doctrine\ORM\Mapping\MappingException * @expectedExceptionMessage Invalid mapping file 'Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml' for class 'Doctrine\Tests\Models\Generic\SerializationModel'. */ 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 2039578a3..33020aa6b 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 @@ -38,15 +38,15 @@ $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); $metadata->mapOneToOne(array( 'fieldName' => 'address', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Address', - 'cascade' => + 'cascade' => array( 0 => 'remove', ), 'mappedBy' => NULL, 'inversedBy' => 'user', - 'joinColumns' => + 'joinColumns' => array( - 0 => + 0 => array( 'name' => 'address_id', 'referencedColumnName' => 'id', @@ -58,13 +58,13 @@ $metadata->mapOneToOne(array( $metadata->mapOneToMany(array( 'fieldName' => 'phonenumbers', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Phonenumber', - 'cascade' => + 'cascade' => array( 1 => 'persist', ), 'mappedBy' => 'user', 'orphanRemoval' => true, - 'orderBy' => + 'orderBy' => array( 'number' => 'ASC', ), @@ -72,7 +72,7 @@ $metadata->mapOneToMany(array( $metadata->mapManyToMany(array( 'fieldName' => 'groups', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Group', - 'cascade' => + 'cascade' => array( 0 => 'remove', 1 => 'persist', @@ -81,12 +81,12 @@ $metadata->mapManyToMany(array( 4 => 'detach', ), 'mappedBy' => NULL, - 'joinTable' => + 'joinTable' => array( 'name' => 'cms_users_groups', - 'joinColumns' => + 'joinColumns' => array( - 0 => + 0 => array( 'name' => 'user_id', 'referencedColumnName' => 'id', @@ -94,9 +94,9 @@ $metadata->mapManyToMany(array( 'nullable' => false, ), ), - 'inverseJoinColumns' => + 'inverseJoinColumns' => array( - 0 => + 0 => array( 'name' => 'group_id', 'referencedColumnName' => 'id', diff --git a/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php index 01f02c0d9..07a202e4a 100644 --- a/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php @@ -76,7 +76,7 @@ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase $e = microtime(true); echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL; } - + /** * Times for comparison: * @@ -264,7 +264,7 @@ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase $e = microtime(true); echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL; } - + /** * [romanb: 10000 rows => 3 seconds] * @@ -392,7 +392,7 @@ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase $e = microtime(true); echo __FUNCTION__ . " - " . ($e - $s) . " seconds" . PHP_EOL; } - + /** * [romanb: 2000 rows => 0.6 seconds] * diff --git a/tests/Doctrine/Tests/ORM/Performance/InsertPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/InsertPerformanceTest.php index cccc480a2..1c378df6d 100644 --- a/tests/Doctrine/Tests/ORM/Performance/InsertPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/InsertPerformanceTest.php @@ -31,7 +31,7 @@ class InsertPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase $this->setMaxRunningTime(10); //echo "Memory usage before: " . (memory_get_usage() / 1024) . " KB" . PHP_EOL; - + $batchSize = 20; for ($i=1; $i<=10000; ++$i) { $user = new CmsUser; @@ -44,13 +44,13 @@ class InsertPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase $this->_em->clear(); } } - + //gc_collect_cycles(); //echo "Memory usage after: " . (memory_get_usage() / 1024) . " KB" . PHP_EOL; $e = microtime(true); - echo ' Inserted 10000 objects in ' . ($e - $s) . ' seconds' . PHP_EOL; + echo ' Inserted 10000 objects in ' . ($e - $s) . ' seconds' . PHP_EOL; } } diff --git a/tests/Doctrine/Tests/ORM/Performance/UnitOfWorkPerformanceTest.php b/tests/Doctrine/Tests/ORM/Performance/UnitOfWorkPerformanceTest.php index 650228ba4..932082813 100644 --- a/tests/Doctrine/Tests/ORM/Performance/UnitOfWorkPerformanceTest.php +++ b/tests/Doctrine/Tests/ORM/Performance/UnitOfWorkPerformanceTest.php @@ -35,7 +35,7 @@ class UnitOfWorkPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase } $this->_em->flush(); - + foreach ($users AS $user) { $user->status = 'other'; $user->username = $user->username . '++'; diff --git a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php index 47eeb8b9a..fd0dffbf2 100644 --- a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php @@ -18,7 +18,7 @@ class PersistentCollectionTest extends \Doctrine\Tests\OrmTestCase { private $_connectionMock; private $_emMock; - + protected function setUp() { parent::setUp(); diff --git a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php index 04c47893d..d1fe9a6b5 100644 --- a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php +++ b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php @@ -18,13 +18,13 @@ class BasicEntityPersisterTypeValueSqlTest extends \Doctrine\Tests\OrmTestCase protected function setUp() { parent::setUp(); - + if (DBALType::hasType('negative_to_positive')) { DBALType::overrideType('negative_to_positive', '\Doctrine\Tests\DbalTypes\NegativeToPositiveType'); } else { DBALType::addType('negative_to_positive', '\Doctrine\Tests\DbalTypes\NegativeToPositiveType'); } - + if (DBALType::hasType('upper_case_string')) { DBALType::overrideType('upper_case_string', '\Doctrine\Tests\DbalTypes\UpperCaseStringType'); } else { diff --git a/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php b/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php index cf9575869..2305287a4 100644 --- a/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php +++ b/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php @@ -23,7 +23,7 @@ class LanguageRecognitionTest extends \Doctrine\Tests\OrmTestCase if ($debug) { echo $e->getTraceAsString() . PHP_EOL; } - + $this->fail($e->getMessage()); } } @@ -32,7 +32,7 @@ class LanguageRecognitionTest extends \Doctrine\Tests\OrmTestCase { try { $parserResult = $this->parseDql($dql); - + $this->fail('No syntax errors were detected, when syntax errors were expected'); } catch (QueryException $e) { if ($debug) { @@ -41,25 +41,25 @@ class LanguageRecognitionTest extends \Doctrine\Tests\OrmTestCase } } } - + public function parseDql($dql, $hints = array()) { $query = $this->_em->createQuery($dql); $query->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true); $query->setDql($dql); - + foreach ($hints as $key => $value) { $query->setHint($key, $value); } - + $parser = new \Doctrine\ORM\Query\Parser($query); - + // We do NOT test SQL output here. That only unnecessarily slows down the tests! $parser->setCustomOutputTreeWalker('Doctrine\Tests\Mocks\MockTreeWalker'); - + return $parser->parse(); } - + public function testEmptyQueryString() { $this->assertInvalidDQL(''); @@ -99,7 +99,7 @@ class LanguageRecognitionTest extends \Doctrine\Tests\OrmTestCase { $this->assertValidDQL('SELECT COUNT(u.id) FROM Doctrine\Tests\Models\CMS\CmsUser u'); } - + public function testDuplicatedAliasInAggregateFunction() { $this->assertInvalidDQL('SELECT COUNT(u.id) AS num, SUM(u.id) AS num FROM Doctrine\Tests\Models\CMS\CmsUser u'); @@ -119,12 +119,12 @@ class LanguageRecognitionTest extends \Doctrine\Tests\OrmTestCase { $this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE ((u.id + 5000) * u.id + 3) < 10000000'); } - + public function testInExpressionSupportedInWherePart() { $this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id IN (1, 2)'); } - + public function testInExpressionWithoutSpacesSupportedInWherePart() { $this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id IN (1,2,3)'); @@ -159,7 +159,7 @@ class LanguageRecognitionTest extends \Doctrine\Tests\OrmTestCase { $this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u NOT INSTANCE OF ?1'); } - + public function testExistsExpressionSupportedInWherePart() { $this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE EXISTS (SELECT p.phonenumber FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p WHERE p.phonenumber = 1234)'); @@ -332,7 +332,7 @@ class LanguageRecognitionTest extends \Doctrine\Tests\OrmTestCase { $this->assertInvalidDQL("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE id = 1"); } - + public function testDuplicatedAliasDeclaration() { $this->assertInvalidDQL("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.articles u WHERE u.id = 1"); @@ -425,58 +425,58 @@ class LanguageRecognitionTest extends \Doctrine\Tests\OrmTestCase $this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE :param MEMBER OF u.phonenumbers'); //$this->assertValidDQL("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE 'Joe' MEMBER OF u.nicknames"); } - + public function testSizeFunction() { $this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE SIZE(u.phonenumbers) > 1'); } - + public function testEmptyCollectionComparisonExpression() { $this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.phonenumbers IS EMPTY'); } - + public function testSingleValuedAssociationFieldInWhere() { $this->assertValidDQL('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.address = ?1'); $this->assertValidDQL('SELECT p FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p WHERE p.user = ?1'); } - + public function testBooleanLiteralInWhere() { $this->assertValidDQL('SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b WHERE b.booleanField = true'); } - + public function testSubqueryInSelectExpression() { $this->assertValidDQL('select u, (select max(p.phonenumber) from Doctrine\Tests\Models\CMS\CmsPhonenumber p) maxId from Doctrine\Tests\Models\CMS\CmsUser u'); } - + public function testUsageOfQComponentOutsideSubquery() { $this->assertInvalidDQL('select u, (select max(p.phonenumber) from Doctrine\Tests\Models\CMS\CmsPhonenumber p) maxId from Doctrine\Tests\Models\CMS\CmsUser u WHERE p.user = ?1'); } - + public function testUnknownAbstractSchemaName() { $this->assertInvalidDQL('SELECT u FROM UnknownClassName u'); } - + public function testCorrectPartialObjectLoad() { $this->assertValidDQL('SELECT PARTIAL u.{id,name} FROM Doctrine\Tests\Models\CMS\CmsUser u'); } - + public function testIncorrectPartialObjectLoadBecauseOfMissingIdentifier() { $this->assertInvalidDQL('SELECT PARTIAL u.{name} FROM Doctrine\Tests\Models\CMS\CmsUser u'); } - + public function testScalarExpressionInSelect() { $this->assertValidDQL('SELECT u, 42 + u.id AS someNumber FROM Doctrine\Tests\Models\CMS\CmsUser u'); } - + public function testInputParameterInSelect() { $this->assertValidDQL('SELECT u, u.id + ?1 AS someNumber FROM Doctrine\Tests\Models\CMS\CmsUser u'); @@ -514,7 +514,7 @@ class LanguageRecognitionTest extends \Doctrine\Tests\OrmTestCase $this->assertInvalidDQL('SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.address = ?1'); } */ - + /** * @group DDC-617 */ @@ -570,12 +570,12 @@ 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"); diff --git a/tests/Doctrine/Tests/ORM/Query/LexerTest.php b/tests/Doctrine/Tests/ORM/Query/LexerTest.php index f84669554..29bba4bae 100644 --- a/tests/Doctrine/Tests/ORM/Query/LexerTest.php +++ b/tests/Doctrine/Tests/ORM/Query/LexerTest.php @@ -16,7 +16,7 @@ class LexerTest extends \Doctrine\Tests\OrmTestCase public function testScannerRecognizesIdentifierWithLengthOfOneCharacter() { $lexer = new Lexer('u'); - + $lexer->moveNext(); $token = $lexer->lookahead; diff --git a/tests/Doctrine/Tests/ORM/QueryBuilderTest.php b/tests/Doctrine/Tests/ORM/QueryBuilderTest.php index 2b352bdce..93af68ae6 100644 --- a/tests/Doctrine/Tests/ORM/QueryBuilderTest.php +++ b/tests/Doctrine/Tests/ORM/QueryBuilderTest.php @@ -120,7 +120,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase $this->assertValidQueryBuilder($qb, 'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.articles a'); } - + public function testComplexInnerJoin() { $qb = $this->_em->createQueryBuilder() @@ -129,7 +129,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ->innerJoin('u.articles', 'a', 'ON', 'u.id = a.author_id'); $this->assertValidQueryBuilder( - $qb, + $qb, 'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.articles a ON u.id = a.author_id' ); } @@ -153,17 +153,17 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase $this->assertValidQueryBuilder($qb, 'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a INDEX BY a.name'); } - + public function testMultipleFrom() { $qb = $this->_em->createQueryBuilder() ->select('u', 'g') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsGroup', 'g'); - + $this->assertValidQueryBuilder($qb, 'SELECT u, g FROM Doctrine\Tests\Models\CMS\CmsUser u, Doctrine\Tests\Models\CMS\CmsGroup g'); } - + public function testMultipleFromWithJoin() { $qb = $this->_em->createQueryBuilder() @@ -171,10 +171,10 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsGroup', 'g') ->innerJoin('u.articles', 'a', 'ON', 'u.id = a.author_id'); - + $this->assertValidQueryBuilder($qb, 'SELECT u, g FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.articles a ON u.id = a.author_id, Doctrine\Tests\Models\CMS\CmsGroup g'); } - + public function testMultipleFromWithMultipleJoin() { $qb = $this->_em->createQueryBuilder() @@ -184,7 +184,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ->innerJoin('u.groups', 'g') ->leftJoin('u.address', 'ad') ->innerJoin('a.comments', 'c'); - + $this->assertValidQueryBuilder($qb, 'SELECT u, g FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.groups g LEFT JOIN u.address ad, Doctrine\Tests\Models\CMS\CmsArticle a INNER JOIN a.comments c'); } @@ -197,7 +197,7 @@ 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() @@ -205,7 +205,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ->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'); } @@ -345,7 +345,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.username ASC'); } - + public function testOrderByWithExpression() { $qb = $this->_em->createQueryBuilder(); @@ -466,21 +466,21 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid3 OR u.id IN(1)'); } - + public function testWhereInWithStringLiterals() { $qb = $this->_em->createQueryBuilder(); $qb->select('u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->where($qb->expr()->in('u.name', array('one', 'two', 'three'))); - + $this->assertValidQueryBuilder($qb, "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name IN('one', 'two', 'three')"); - + $qb->where($qb->expr()->in('u.name', array("O'Reilly", "O'Neil", 'Smith'))); - + $this->assertValidQueryBuilder($qb, "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name IN('O''Reilly', 'O''Neil', 'Smith')"); } - + public function testWhereInWithObjectLiterals() { $qb = $this->_em->createQueryBuilder(); @@ -488,14 +488,14 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase $qb->select('u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->where($expr->in('u.name', array($expr->literal('one'), $expr->literal('two'), $expr->literal('three')))); - + $this->assertValidQueryBuilder($qb, "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name IN('one', 'two', 'three')"); - + $qb->where($expr->in('u.name', array($expr->literal("O'Reilly"), $expr->literal("O'Neil"), $expr->literal('Smith')))); - + $this->assertValidQueryBuilder($qb, "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name IN('O''Reilly', 'O''Neil', 'Smith')"); } - + public function testNegation() { $expr = $this->_em->getExpressionBuilder(); @@ -510,7 +510,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid3 OR NOT(u.id IN(1))'); } - + public function testSomeAllAny() { $qb = $this->_em->createQueryBuilder(); @@ -521,30 +521,30 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase $qb->select('u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->where($expr->gt('u.id', $expr->all('select a.id from Doctrine\Tests\Models\CMS\CmsArticle a'))); - + $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id > ALL(select a.id from Doctrine\Tests\Models\CMS\CmsArticle a)'); } - + public function testMultipleIsolatedQueryConstruction() { $qb = $this->_em->createQueryBuilder(); $expr = $this->_em->getExpressionBuilder(); - + $qb->select('u')->from('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $qb->where($expr->eq('u.name', ':name')); $qb->setParameter('name', 'romanb'); - + $q1 = $qb->getQuery(); $this->assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = :name', $q1->getDql()); $this->assertEquals(1, count($q1->getParameters())); - + // add another condition and construct a second query $qb->andWhere($expr->eq('u.id', ':id')); $qb->setParameter('id', 42); - + $q2 = $qb->getQuery(); - + $this->assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = :name AND u.id = :id', $q2->getDql()); $this->assertTrue($q1 !== $q2); // two different, independent queries $this->assertEquals(2, count($q2->getParameters())); @@ -638,61 +638,61 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase $expr = $qb->getDQLPart('where'); $this->assertEquals(2, $expr->count(), "Modifying the second query should affect the first one."); - + $qb2 = clone $qb; $qb2->andWhere('u.name = ?3'); $this->assertEquals(2, $expr->count(), "Modifying the second query should affect the first one."); } - + public function testGetRootAlias() { $qb = $this->_em->createQueryBuilder() ->select('u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u'); - + $this->assertEquals('u', $qb->getRootAlias()); } - + public function testGetRootAliases() { $qb = $this->_em->createQueryBuilder() ->select('u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u'); - + $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() ->select('u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u2'); - + $this->assertEquals(array('u', 'u2'), $qb->getRootAliases()); $this->assertEquals('u', $qb->getRootAlias()); } - + public function testBCAddJoinWithoutRootAlias() { $qb = $this->_em->createQueryBuilder() ->select('u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->add('join', array('INNER JOIN u.groups g'), true); - + $this->assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.groups g', $qb->getDQL()); } - + /** * @group DDC-1211 */ @@ -703,10 +703,10 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ->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 */ @@ -717,10 +717,10 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ->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 */ @@ -729,7 +729,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase $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/EntityGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php index f2b298159..faf20afb1 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php @@ -45,7 +45,7 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase $metadata = new ClassMetadataInfo($this->_namespace . '\EntityGeneratorBook'); $metadata->namespace = $this->_namespace; $metadata->customRepositoryClassName = $this->_namespace . '\EntityGeneratorBookRepository'; - + $metadata->table['name'] = 'book'; $metadata->mapField(array('fieldName' => 'name', 'type' => 'string')); $metadata->mapField(array('fieldName' => 'status', 'type' => 'string', 'default' => 'published')); @@ -100,7 +100,7 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase $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', 'addEntityGeneratorComment'), "EntityGeneratorBook::addEntityGeneratorComment() missing."); - + $this->assertEquals('published', $book->getStatus()); $book->setName('Jonathan H. Wage'); @@ -120,7 +120,7 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase { $metadata = $this->generateBookEntityFixture(); $metadata->mapField(array('fieldName' => 'test', 'type' => 'string')); - + $this->_generator->writeEntityClass($metadata, $this->_tmpDir); $this->assertFileExists($this->_tmpDir . "/" . $this->_namespace . "/EntityGeneratorBook.php~"); diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php index 6ff3d1808..2267020e3 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php @@ -136,7 +136,7 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest public function testExportedMetadataCanBeReadBackIn() { $type = $this->_getType(); - + $metadataDriver = $this->_createMetadataDriver($type, __DIR__ . '/export/' . $type); $em = $this->_createEntityManager($metadataDriver); $cmf = $this->_createClassMetadataFactory($em, $type); @@ -145,7 +145,7 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest $this->assertEquals(1, count($metadata)); $class = current($metadata); - + $this->assertEquals('Doctrine\Tests\ORM\Tools\Export\ExportedUser', $class->name); return $class; @@ -251,7 +251,7 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest $this->assertTrue($class->associationMappings['phonenumbers']['isCascadeMerge']); $this->assertFalse($class->associationMappings['phonenumbers']['isCascadeDetach']); $this->assertTrue($class->associationMappings['phonenumbers']['orphanRemoval']); - + return $class; } @@ -339,14 +339,14 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest $this->assertEquals('cascade-all', $nodes[0]->getName()); } elseif ($type == 'yaml') { - + $yaml = new \Symfony\Component\Yaml\Parser(); $value = $yaml->parse(file_get_contents(__DIR__ . '/export/'.$type.'/Doctrine.Tests.ORM.Tools.Export.ExportedUser.dcm.yml')); - + $this->assertTrue(isset($value['Doctrine\Tests\ORM\Tools\Export\ExportedUser']['oneToMany']['interests']['cascade'])); $this->assertEquals(1, count($value['Doctrine\Tests\ORM\Tools\Export\ExportedUser']['oneToMany']['interests']['cascade'])); $this->assertEquals('all', $value['Doctrine\Tests\ORM\Tools\Export\ExportedUser']['oneToMany']['interests']['cascade'][0]); - + } else { $this->markTestSkipped('Test aviable only for '.$type.' dirver'); } 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 c50d2a75b..f90f22071 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 @@ -35,14 +35,14 @@ $metadata->mapOneToOne(array( 'fieldName' => 'address', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Tools\\Export\\Address', 'inversedBy' => 'user', - 'cascade' => + 'cascade' => array( 0 => 'persist', ), 'mappedBy' => NULL, - 'joinColumns' => + 'joinColumns' => array( - 0 => + 0 => array( 'name' => 'address_id', 'referencedColumnName' => 'id', @@ -54,14 +54,14 @@ $metadata->mapOneToOne(array( $metadata->mapOneToMany(array( 'fieldName' => 'phonenumbers', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Tools\\Export\\Phonenumber', - 'cascade' => + 'cascade' => array( 1 => 'persist', 2 => 'merge', ), 'mappedBy' => 'user', 'orphanRemoval' => true, - 'orderBy' => + 'orderBy' => array( 'number' => 'ASC', ), @@ -69,7 +69,7 @@ $metadata->mapOneToMany(array( $metadata->mapManyToMany(array( 'fieldName' => 'groups', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Tools\\Export\\Group', - 'cascade' => + 'cascade' => array( 0 => 'remove', 1 => 'persist', @@ -78,12 +78,12 @@ $metadata->mapManyToMany(array( 4 => 'detach', ), 'mappedBy' => NULL, - 'joinTable' => + 'joinTable' => array( 'name' => 'cms_users_groups', - 'joinColumns' => + 'joinColumns' => array( - 0 => + 0 => array( 'name' => 'user_id', 'referencedColumnName' => 'id', @@ -91,9 +91,9 @@ $metadata->mapManyToMany(array( 'nullable' => false, ), ), - 'inverseJoinColumns' => + 'inverseJoinColumns' => array( - 0 => + 0 => array( 'name' => 'group_id', 'referencedColumnName' => 'id', diff --git a/tests/Doctrine/Tests/ORM/Tools/ResolveTargetEntityListenerTest.php b/tests/Doctrine/Tests/ORM/Tools/ResolveTargetEntityListenerTest.php index b794474a8..3cb627f07 100644 --- a/tests/Doctrine/Tests/ORM/Tools/ResolveTargetEntityListenerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/ResolveTargetEntityListenerTest.php @@ -79,7 +79,7 @@ class ResolveTargetEntity implements ResolveTargetInterface /** * @Id * @Column(type="integer") - * @GeneratedValue(strategy="AUTO") + * @GeneratedValue(strategy="AUTO") */ private $id; @@ -118,7 +118,7 @@ class TargetEntity implements TargetInterface /** * @Id * @Column(type="integer") - * @GeneratedValue(strategy="AUTO") + * @GeneratedValue(strategy="AUTO") */ private $id; diff --git a/tests/Doctrine/Tests/ORM/Tools/SetupTest.php b/tests/Doctrine/Tests/ORM/Tools/SetupTest.php index 643464df0..45c9e3ea7 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SetupTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SetupTest.php @@ -11,62 +11,62 @@ class SetupTest extends \Doctrine\Tests\OrmTestCase { private $originalAutoloaderCount; private $originalIncludePath; - + public function setUp() { if (strpos(\Doctrine\ORM\Version::VERSION, "DEV") === false) { $this->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()); } @@ -87,12 +87,12 @@ class SetupTest extends \Doctrine\Tests\OrmTestCase { $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); diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 5858b5a98..9cc20ad73 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -24,7 +24,7 @@ class UnitOfWorkTest extends \Doctrine\Tests\OrmTestCase private $_connectionMock; // The EntityManager mock that provides the mock persisters private $_emMock; - + protected function setUp() { parent::setUp(); $this->_connectionMock = new ConnectionMock(array(), new \Doctrine\Tests\Mocks\DriverMock()); @@ -33,22 +33,22 @@ class UnitOfWorkTest extends \Doctrine\Tests\OrmTestCase $this->_unitOfWork = new UnitOfWorkMock($this->_emMock); $this->_emMock->setUnitOfWork($this->_unitOfWork); } - + protected function tearDown() { } - + public function testRegisterRemovedOnNewEntityIsIgnored() { $user = new ForumUser(); $user->username = 'romanb'; $this->assertFalse($this->_unitOfWork->isScheduledForDelete($user)); $this->_unitOfWork->scheduleForDelete($user); - $this->assertFalse($this->_unitOfWork->isScheduledForDelete($user)); + $this->assertFalse($this->_unitOfWork->isScheduledForDelete($user)); } - - + + /* Operational tests */ - + public function testSavingSingleEntityWithIdentityColumnForcesInsert() { // Setup fake persister and id generator for identity generation @@ -66,22 +66,22 @@ class UnitOfWorkTest extends \Doctrine\Tests\OrmTestCase // Check $this->assertEquals(0, count($userPersister->getInserts())); $this->assertEquals(0, count($userPersister->getUpdates())); - $this->assertEquals(0, count($userPersister->getDeletes())); + $this->assertEquals(0, count($userPersister->getDeletes())); $this->assertFalse($this->_unitOfWork->isInIdentityMap($user)); // should no longer be scheduled for insert $this->assertTrue($this->_unitOfWork->isScheduledForInsert($user)); - + // Now lets check whether a subsequent commit() does anything $userPersister->reset(); // Test $this->_unitOfWork->commit(); - + // Check. $this->assertEquals(1, count($userPersister->getInserts())); $this->assertEquals(0, count($userPersister->getUpdates())); $this->assertEquals(0, count($userPersister->getDeletes())); - + // should have an id $this->assertTrue(is_numeric($user->id)); } @@ -112,7 +112,7 @@ class UnitOfWorkTest extends \Doctrine\Tests\OrmTestCase $avatar = new ForumAvatar(); $user->avatar = $avatar; $this->_unitOfWork->persist($user); // save cascaded to avatar - + $this->_unitOfWork->commit(); $this->assertTrue(is_numeric($user->id)); @@ -137,7 +137,7 @@ class UnitOfWorkTest extends \Doctrine\Tests\OrmTestCase $entity = new NotifyChangedEntity; $entity->setData('thedata'); $this->_unitOfWork->persist($entity); - + $this->_unitOfWork->commit(); $this->assertEquals(1, count($persister->getInserts())); $persister->reset(); @@ -161,7 +161,7 @@ class UnitOfWorkTest extends \Doctrine\Tests\OrmTestCase $persister->reset(); $itemPersister->reset(); - + $entity->getItems()->removeElement($item); $item->setOwner(null); $this->assertTrue($entity->getItems()->isDirty()); diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index e0b9d7bee..ba54da95c 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -16,7 +16,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase /* Shared connection when a TestCase is run alone (outside of it's functional suite) */ protected static $_sharedConn; - + /** * @var \Doctrine\ORM\EntityManager */ @@ -123,7 +123,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase { $this->_usedModelSets[$setName] = true; } - + /** * Sweeps the database tables and clears the EntityManager. */ @@ -241,10 +241,10 @@ abstract class OrmFunctionalTestCase extends OrmTestCase protected function setUp() { $forceCreateTables = false; - + if ( ! isset(static::$_sharedConn)) { static::$_sharedConn = TestUtil::getConnection(); - + if (static::$_sharedConn->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) { $forceCreateTables = true; } @@ -257,24 +257,24 @@ abstract class OrmFunctionalTestCase extends OrmTestCase static::$_sharedConn->executeQuery('SELECT 1 /*' . get_class($this) . '*/ FROM dual'); } } - + if ( ! $this->_em) { $this->_em = $this->_getEntityManager(); $this->_schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->_em); } $classes = array(); - + foreach ($this->_usedModelSets as $setName => $bool) { if ( ! isset(static::$_tablesCreated[$setName])/* || $forceCreateTables*/) { foreach (static::$_modelSets[$setName] as $className) { $classes[] = $this->_em->getClassMetadata($className); } - + static::$_tablesCreated[$setName] = true; } } - + if ($classes) { $this->_schemaTool->createSchema($classes); } @@ -303,7 +303,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase $this->_sqlLoggerStack = new \Doctrine\DBAL\Logging\DebugStack(); $this->_sqlLoggerStack->enabled = false; - + //FIXME: two different configs! $conn and the created entity manager have // different configs. $config = new \Doctrine\ORM\Configuration(); @@ -313,7 +313,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase $config->setProxyNamespace('Doctrine\Tests\Proxies'); $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver()); - + $conn = static::$_sharedConn; $conn->getConfiguration()->setSQLLogger($this->_sqlLoggerStack); @@ -324,7 +324,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase $evm->removeEventListener(array($event), $listener); } } - + if (isset($GLOBALS['db_event_subscribers'])) { foreach (explode(",", $GLOBALS['db_event_subscribers']) AS $subscriberClass) { $subscriberInstance = new $subscriberClass(); @@ -335,7 +335,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase if (isset($GLOBALS['debug_uow_listener'])) { $evm->addEventListener(array('onFlush'), new \Doctrine\ORM\Tools\DebugUnitOfWorkListener()); } - + return \Doctrine\ORM\EntityManager::create($conn, $config); } @@ -352,7 +352,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase $params = array_map(function($p) { if (is_object($p)) return get_class($p); else return "'".$p."'"; }, $query['params'] ?: array()); $queries .= ($i+1).". SQL: '".$query['sql']."' Params: ".implode(", ", $params).PHP_EOL; } - + $trace = $e->getTrace(); $traceMsg = ""; foreach($trace AS $part) { @@ -375,7 +375,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase /** * Using the SQL Logger Stack this method retrieves the current query count executed in this test. - * + * * @return int */ protected function getCurrentQueryCount() diff --git a/tests/Doctrine/Tests/OrmTestCase.php b/tests/Doctrine/Tests/OrmTestCase.php index 2a7b37dc9..23099ac77 100644 --- a/tests/Doctrine/Tests/OrmTestCase.php +++ b/tests/Doctrine/Tests/OrmTestCase.php @@ -11,7 +11,7 @@ abstract class OrmTestCase extends DoctrineTestCase { /** The metadata cache that is shared between all ORM tests (except functional tests). */ private static $_metadataCacheImpl = null; - + /** The query cache that is shared between all ORM tests (except functional tests). */ private static $_queryCacheImpl = null; @@ -56,10 +56,10 @@ abstract class OrmTestCase extends DoctrineTestCase __DIR__ . "/../../../lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php"); return new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, (array)$paths); } - + /** * Creates an EntityManager for testing purposes. - * + * * NOTE: The created EntityManager will have its dependant DBAL parts completely * mocked out using a DriverMock, ConnectionMock, etc. These mocks can then * be configured in the tests to simulate the DBAL behavior that is desired @@ -69,18 +69,18 @@ abstract class OrmTestCase extends DoctrineTestCase */ protected function _getTestEntityManager($conn = null, $conf = null, $eventManager = null, $withSharedMetadata = true) { - $metadataCache = $withSharedMetadata - ? self::getSharedMetadataCacheImpl() + $metadataCache = $withSharedMetadata + ? self::getSharedMetadataCacheImpl() : new \Doctrine\Common\Cache\ArrayCache; - + $config = new \Doctrine\ORM\Configuration(); - + $config->setMetadataCacheImpl($metadataCache); $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver()); $config->setQueryCacheImpl(self::getSharedQueryCacheImpl()); $config->setProxyDir(__DIR__ . '/Proxies'); $config->setProxyNamespace('Doctrine\Tests\Proxies'); - + if ($conn === null) { $conn = array( 'driverClass' => 'Doctrine\Tests\Mocks\DriverMock', @@ -89,11 +89,11 @@ abstract class OrmTestCase extends DoctrineTestCase 'password' => 'wayne' ); } - + if (is_array($conn)) { $conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, $eventManager); } - + return \Doctrine\Tests\Mocks\EntityManagerMock::create($conn, $config, $eventManager); } @@ -102,16 +102,16 @@ abstract class OrmTestCase extends DoctrineTestCase if (self::$_metadataCacheImpl === null) { self::$_metadataCacheImpl = new \Doctrine\Common\Cache\ArrayCache; } - + return self::$_metadataCacheImpl; } - + private static function getSharedQueryCacheImpl() { if (self::$_queryCacheImpl === null) { self::$_queryCacheImpl = new \Doctrine\Common\Cache\ArrayCache; } - + return self::$_queryCacheImpl; } } diff --git a/tests/NativePhpunitTask.php b/tests/NativePhpunitTask.php index 1ef582dfe..8a3b190c7 100644 --- a/tests/NativePhpunitTask.php +++ b/tests/NativePhpunitTask.php @@ -244,6 +244,6 @@ class NativePhpunitPrinter extends PHPUnit_Util_Printer implements PHPUnit_Frame */ public function endTest(PHPUnit_Framework_Test $test, $time) { - + } } \ No newline at end of file