From 59a17eb51c9d60d56c0720d40cea545ac3899cf2 Mon Sep 17 00:00:00 2001 From: romanb Date: Thu, 10 Dec 2009 21:27:20 +0000 Subject: [PATCH] [2.0][DDC-171] Fixed (second attempt). Some other cleanups. Performance fix for mock Statement used in hydration performance tests for more accurate and better results. --- lib/Doctrine/ORM/PersistentCollection.php | 16 ++---- .../Tests/Common/Cache/MemcacheCacheTest.php | 4 +- .../Tests/Mocks/HydratorMockStatement.php | 53 ++++++++++++++----- .../ORM/Functional/BasicFunctionalTest.php | 15 +++++- 4 files changed, 60 insertions(+), 28 deletions(-) diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index 3a2d6e459..9cca5ecb6 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -157,18 +157,6 @@ final class PersistentCollection implements \Doctrine\Common\Collections\Collect { return $this->_owner; } - - /** - * Gets the class descriptor for the owning entity class. - * - * @return Doctrine\ORM\Mapping\ClassMetadata - * @deprecated - * @todo Remove - */ - public function getOwnerClass() - { - return $this->_typeClass; - } public function getTypeClass() { @@ -194,6 +182,10 @@ final class PersistentCollection implements \Doctrine\Common\Collections\Collect // OneToMany $this->_typeClass->reflFields[$this->_backRefFieldName] ->setValue($element, $this->_owner); + $this->_em->getUnitOfWork()->setOriginalEntityProperty( + spl_object_hash($element), + $this->_backRefFieldName, + $this->_owner); } else { // ManyToMany $this->_typeClass->reflFields[$this->_backRefFieldName] diff --git a/tests/Doctrine/Tests/Common/Cache/MemcacheCacheTest.php b/tests/Doctrine/Tests/Common/Cache/MemcacheCacheTest.php index 52f44c844..2972e2292 100644 --- a/tests/Doctrine/Tests/Common/Cache/MemcacheCacheTest.php +++ b/tests/Doctrine/Tests/Common/Cache/MemcacheCacheTest.php @@ -13,8 +13,8 @@ class MemcacheCacheTest extends \Doctrine\Tests\DoctrineTestCase public function setUp() { if (extension_loaded('memcache')) { - $memcache = new \Memcache; - $ok = @$memcache->connect('localhost', 11211); + $this->_memcache = new \Memcache; + $ok = @$this->_memcache->connect('localhost', 11211); if (!$ok) { $this->markTestSkipped('The ' . __CLASS__ .' requires the use of memcache'); } diff --git a/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php b/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php index 81c9d7ab4..555982765 100644 --- a/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php +++ b/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php @@ -3,12 +3,12 @@ namespace Doctrine\Tests\Mocks; /** - * This class is a mock of the PDOStatement class that can be passed in to the Hydrator + * This class is a mock of the Statement interface that can be passed in to the Hydrator * to test the hydration standalone with faked result sets. * * @author Roman Borschel */ -class HydratorMockStatement +class HydratorMockStatement implements \Doctrine\DBAL\Driver\Statement { private $_resultSet; @@ -25,9 +25,6 @@ class HydratorMockStatement /** * Fetches all rows from the result set. * - * NOTE: Must adhere to the PDOStatement::fetchAll() signature that looks as follows: - * array fetchAll ([ int $fetch_style [, int $column_index [, array $ctor_args ]]] ) - * * @return array */ public function fetchAll($fetchStyle = null, $columnIndex = null, array $ctorArgs = null) @@ -37,7 +34,7 @@ class HydratorMockStatement public function fetchColumn($columnNumber = 0) { - $row = array_shift($this->_resultSet); + $row = current($this->_resultSet); if ( ! is_array($row)) return false; $val = array_shift($row); return $val !== null ? $val : false; @@ -45,14 +42,13 @@ class HydratorMockStatement /** * Fetches the next row in the result set. - * - * NOTE: Must adhere to the PDOStatement::fetch() signature that looks as follows: - * mixed fetch ([ int $fetch_style [, int $cursor_orientation [, int $cursor_offset ]]] ) - * + * */ - public function fetch($fetchStyle = null, $cursorOrientation = null, $cursorOffset = null) + public function fetch($fetchStyle = null) { - return array_shift($this->_resultSet); + $current = current($this->_resultSet); + next($this->_resultSet); + return $current; } /** @@ -67,6 +63,39 @@ class HydratorMockStatement public function setResultSet(array $resultSet) { + reset($resultSet); $this->_resultSet = $resultSet; } + + public function bindColumn($column, &$param, $type = null) + { + } + + public function bindValue($param, $value, $type = null) + { + } + + public function bindParam($column, &$variable, $type = null, $length = null, $driverOptions = array()) + { + } + + public function columnCount() + { + } + + public function errorCode() + { + } + + public function errorInfo() + { + } + + public function execute($params = array()) + { + } + + public function rowCount() + { + } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php index 577c084b8..b123db1af 100644 --- a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php @@ -560,13 +560,24 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $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 from Doctrine\Tests\Models\CMS\CmsUser u join u.address a'); + + $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->assertTrue($user2->address instanceof CmsAddress); $oldLogger = $this->_em->getConnection()->getConfiguration()->getSqlLogger(); $debugStack = new \Doctrine\DBAL\Logging\DebugStack;