From eeba947ea7f0f5f18672c368398f105a93e58545 Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Sun, 16 Oct 2011 02:10:59 -0200 Subject: [PATCH] Code optimizations. Fixed unused argument in OrmTestCase as referred in DDC-766. --- lib/Doctrine/ORM/Query/Parser.php | 27 ++++++++++++--------------- tests/Doctrine/Tests/OrmTestCase.php | 26 +++++++++++++++----------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 08e036c1a..9fc30bb8c 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -1328,18 +1328,18 @@ class Parser // We need to check if we are in a IdentificationVariable or SingleValuedPathExpression $glimpse = $this->_lexer->glimpse(); - if ($glimpse['type'] != Lexer::T_DOT) { - $token = $this->_lexer->lookahead; - $identVariable = $this->IdentificationVariable(); + if ($glimpse['type'] == Lexer::T_DOT) { + return $this->SingleValuedPathExpression(); + } + + $token = $this->_lexer->lookahead; + $identVariable = $this->IdentificationVariable(); - if (!isset($this->_queryComponents[$identVariable])) { - $this->semanticalError('Cannot group by undefined identification variable.'); - } - - return $identVariable; + if (!isset($this->_queryComponents[$identVariable])) { + $this->semanticalError('Cannot group by undefined identification variable.'); } - return $this->SingleValuedPathExpression(); + return $identVariable; } /** @@ -1354,12 +1354,9 @@ class Parser // We need to check if we are in a ResultVariable or StateFieldPathExpression $glimpse = $this->_lexer->glimpse(); - if ($glimpse['type'] != Lexer::T_DOT) { - $token = $this->_lexer->lookahead; - $expr = $this->ResultVariable(); - } else { - $expr = $this->SingleValuedPathExpression(); - } + $expr = ($glimpse['type'] != Lexer::T_DOT) + ? $this->ResultVariable() + : $this->SingleValuedPathExpression(); $item = new AST\OrderByItem($expr); diff --git a/tests/Doctrine/Tests/OrmTestCase.php b/tests/Doctrine/Tests/OrmTestCase.php index 678478633..fa9938d09 100644 --- a/tests/Doctrine/Tests/OrmTestCase.php +++ b/tests/Doctrine/Tests/OrmTestCase.php @@ -11,6 +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; @@ -66,30 +67,31 @@ abstract class OrmTestCase extends DoctrineTestCase */ protected function _getTestEntityManager($conn = null, $conf = null, $eventManager = null, $withSharedMetadata = true) { + $metadataCache = $withSharedMetadata + ? self::getSharedMetadataCacheImpl() + : new \Doctrine\Common\Cache\ArrayCache; + $config = new \Doctrine\ORM\Configuration(); - if($withSharedMetadata) { - $config->setMetadataCacheImpl(self::getSharedMetadataCacheImpl()); - } else { - $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache); - } - + + $config->setMetadataCacheImpl($metadataCache); $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver()); - $config->setQueryCacheImpl(self::getSharedQueryCacheImpl()); $config->setProxyDir(__DIR__ . '/Proxies'); $config->setProxyNamespace('Doctrine\Tests\Proxies'); - $eventManager = new \Doctrine\Common\EventManager(); + if ($conn === null) { $conn = array( - 'driverClass' => 'Doctrine\Tests\Mocks\DriverMock', + 'driverClass' => 'Doctrine\Tests\Mocks\DriverMock', 'wrapperClass' => 'Doctrine\Tests\Mocks\ConnectionMock', - 'user' => 'john', - 'password' => 'wayne' + 'user' => 'john', + 'password' => 'wayne' ); } + if (is_array($conn)) { $conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, $eventManager); } + return \Doctrine\Tests\Mocks\EntityManagerMock::create($conn, $config, $eventManager); } @@ -98,6 +100,7 @@ abstract class OrmTestCase extends DoctrineTestCase if (self::$_metadataCacheImpl === null) { self::$_metadataCacheImpl = new \Doctrine\Common\Cache\ArrayCache; } + return self::$_metadataCacheImpl; } @@ -106,6 +109,7 @@ abstract class OrmTestCase extends DoctrineTestCase if (self::$_queryCacheImpl === null) { self::$_queryCacheImpl = new \Doctrine\Common\Cache\ArrayCache; } + return self::$_queryCacheImpl; } }