Compare commits

..

45 Commits

Author SHA1 Message Date
Luís Cobucci 93103f44a3 Preparing v2.5.13 release 2017-11-28 00:25:55 +01:00
Luís Cobucci ffdb769564 Merge pull request #6818 from vkurdin/patch-1
BasicEntityPersister::count() return type fix
2017-11-27 23:08:51 +01:00
Vasiliy Kurdin 95344d019f BasicEntityPersister::count() return type fix
Resolve #6810 by casting return value to integer
2017-11-27 22:21:04 +01:00
Luís Cobucci 640d9af50f Merge pull request #6852 from gigi/2.5
Backport #6167 from 2.6 to 2.5.x branch
2017-11-27 22:12:53 +01:00
Alexey Snigirev a23e909158 #6167 - code cleanup for 2.5.x version 2017-11-27 14:58:44 +02:00
Marco Pivetta a857a610db #6167 #6168 rewrote SequenceGeneratorTest for better readability and error messages
(cherry picked from commit a97c265)
2017-11-27 12:28:35 +02:00
Marco Pivetta f0006eb42d #6167 #6168 - better connection mock documentation/docblocks/return-types
(cherry picked from commit 462481e)
2017-11-27 12:26:27 +02:00
Marco Pivetta 7ea97e69ca #6167 #6168 - clarifying on the reasoning why query is used instead of fetchColumn
(cherry picked from commit d2be4a2)
2017-11-27 12:24:31 +02:00
Michał Kurzeja de4b40b29f #6167 Code review updates, better readability
(cherry picked from commit 571115c)
2017-11-27 12:24:28 +02:00
Michał Kurzeja e21217dd0e #6167 - tests - throw exception if wrong method used to get sequence nextval
(cherry picked from commit 71b040c)
2017-11-27 12:24:23 +02:00
Michał Kurzeja b82aef2748 #6167 - fixed tests and added info why query is used in SequenceGenerator
(cherry picked from commit edffb4d)
2017-11-27 12:24:17 +02:00
Michał Kurzeja 44b3405714 Fixes #6167 - nextval issue on master-slave PostgreSQL setup
(cherry picked from commit 60b6073)
2017-11-27 12:22:54 +02:00
Luís Cobucci e874d93f61 Merge branch 'backport/bugfix/xml_sequence_params' into 2.5
Backporting: https://github.com/doctrine/doctrine2/pull/6683
2017-11-26 16:46:56 +01:00
Sasha Alex Romanenko bb31472727 Enforce sequence XSD requirement
Supply default values for allocationSize and initialValue optional parameters.

Related to: https://github.com/doctrine/doctrine2/issues/6682
2017-11-26 16:36:51 +01:00
Luís Cobucci fd72aa08d2 Merge branch 'backport/DDC288' into 2.5
Backporting: https://github.com/doctrine/doctrine2/pull/6740
2017-11-26 14:15:46 +01:00
Mathieu Duplouy 21f73cf923 Add operator to walkComparison output 2017-11-26 14:08:23 +01:00
Mathieu Duplouy 2701f5058e Add failing test for DCOM-288
Reported on: https://github.com/doctrine/common/issues/600
2017-11-26 14:07:58 +01:00
Luís Cobucci 4bd2f68483 Merge branch 'backport/cache-namespace-fix' into 2.5
Backporting: https://github.com/doctrine/doctrine2/pull/6848
Backporting: https://github.com/doctrine/doctrine2/pull/5904
2017-11-26 13:22:59 +01:00
Jan Jakes 823da6d839 Fix overwriting explicit cache namespace 2017-11-26 12:59:53 +01:00
Luís Cobucci 6318796965 Fix incorrect arguments on SetupTest
Which was only caught by adding proper type declaration on private
methods.
2017-11-26 12:38:01 +01:00
Luís Cobucci c811c3ac84 Merge branch 'backport/ticket/6699' into 2.5
Backporting: https://github.com/doctrine/doctrine2/pull/6705
2017-11-24 02:43:33 +01:00
Luís Cobucci aba62edcc8 Fix parameter name comparison in QueryBuilder#setParameter() with different types 2017-11-24 02:37:13 +01:00
Michael Moravec 0b4e5b42e1 Fix parameter name comparison in AbstractQuery#setParameter() with different types 2017-11-24 02:35:10 +01:00
Michael Moravec 3d4f236052 Add failing test for #6699 2017-11-24 02:31:48 +01:00
Luís Cobucci 049470c787 Merge pull request #6821 from remicollet/issue-count
For PHP 7.2
2017-11-12 12:25:46 +01:00
Remi Collet cfaad4fedc fix skip condition for APC 2017-11-10 15:54:09 +01:00
Remi Collet e8a89c3bc3 Fix ReflectionException: Given object is not an instance of the class this property was declared in 2017-11-10 15:54:04 +01:00
Remi Collet 497be59f5c fix for 7.2, ensure mocked ParserResult::getParameterMappings returns an array 2017-11-10 15:53:18 +01:00
Jonathan H. Wage e1b851f2e9 Bumping development version to v2.5.13-DEV 2017-10-23 13:26:03 -05:00
Jonathan H. Wage 984535cadc Preparing v2.5.12 release 2017-10-23 13:21:04 -05:00
Jonathan H. Wage 35a579efdc Merge pull request #6733 from fabpot/patch-2
Allow Symfony 4
2017-10-23 12:50:36 -05:00
Fabien Potencier a2b4e5b293 Allow Symfony 4 2017-09-27 15:33:54 -07:00
Marco Pivetta 24d95796bb Bumping development version to v2.5.12-DEV 2017-09-18 08:52:10 +02:00
Marco Pivetta 249b737094 Preparing v2.5.11 release 2017-09-18 08:50:20 +02:00
Marco Pivetta 36dc28d43e Merge pull request #6635 from davidbarratt/instantiator
Allow installation of `doctrine/instantiator:^1.0.1`
2017-08-19 18:47:32 +02:00
David Barratt 0ec9e53c8d Fix doctrine/instantiator constraint
The current constraint prevents doctrine from being installed on PHP 7.1
2017-08-19 11:51:46 -04:00
Marco Pivetta aa80f6c0b5 Removed PHPUnit 5.6+ API usage 2017-08-18 21:24:47 +02:00
Marco Pivetta fd6d4890c4 Bumping development release to 2.5.11-DEV 2017-08-18 21:23:23 +02:00
Marco Pivetta c78afd5172 Preparing v2.5.10 release 2017-08-18 21:17:35 +02:00
Marco Pivetta fb7b78c004 Merge branch 'fix/#6633-#3788-avoid-xml-external-entity-loading-errors-in-xml-mapping-driver-2.5' into 2.5
Backport #6633
Backport #3788
2017-08-18 21:12:12 +02:00
Marco Pivetta 0de69e5a80 #6633 #3788 documenting why simplexml_load_file() was not used 2017-08-18 21:10:45 +02:00
Aljosha Papsch d7e1f883d8 XmlDriver: Avoid PHP bug #62577 by avoiding simplexml_load_file.
Doctrine is affected by PHP bug #62577. simplexml_load_file is not
able to load files if libxml_disable_entity_loader(true) has been
called. simplexml_load_file fails with the message:

I/O warning : failed to load external entity "/my/mappings/my_entity.dcm.xml"
in /path-to/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php on line 711

This error occurs even if there are no external entities in the XML file.

Waiting for the PHP bug to be resolved is infeasible, because it is
unresolved since years. Therefore Doctrine needs to circumvent the bug
by replacing simplexml_load_file with simplexml_load_string while getting
the file contents itself. simplexml_load_string is not affected by the
PHP bug.
2017-08-18 21:10:11 +02:00
Marco Pivetta 82e0d7e21a Removing ::class meta-constant for tests that need to run against my grandparents' PHP 2017-08-16 20:06:14 +02:00
Marco Pivetta 26880983fc Removing ::class meta-constant for tests that need to run against my grandparents' PHP 2017-08-16 19:24:39 +02:00
Marco Pivetta d9899732ca Bumping development release to v2.5.10DEV 2017-08-16 15:30:59 +02:00
25 changed files with 663 additions and 121 deletions
+3 -3
View File
@@ -17,13 +17,13 @@
"ext-pdo": "*",
"doctrine/collections": "~1.2",
"doctrine/dbal": ">=2.5-dev,<2.7-dev",
"doctrine/instantiator": "~1.0.1",
"doctrine/instantiator": "^1.0.1",
"doctrine/common": ">=2.5-dev,<2.9-dev",
"doctrine/cache": "~1.4",
"symfony/console": "~2.5|~3.0"
"symfony/console": "~2.5|~3.0|~4.0"
},
"require-dev": {
"symfony/yaml": "~2.3|~3.0",
"symfony/yaml": "~2.3|~3.0|~4.0",
"phpunit/phpunit": "~4.0"
},
"suggest": {
+8 -15
View File
@@ -325,14 +325,14 @@ abstract class AbstractQuery
public function getParameter($key)
{
$filteredParameters = $this->parameters->filter(
function ($parameter) use ($key)
{
// Must not be identical because of string to integer conversion
return ($key == $parameter->getName());
function (Query\Parameter $parameter) use ($key) {
$parameterName = $parameter->getName();
return $key === $parameterName || (string) $key === (string) $parameterName;
}
);
return count($filteredParameters) ? $filteredParameters->first() : null;
return ! $filteredParameters->isEmpty() ? $filteredParameters->first() : null;
}
/**
@@ -373,17 +373,10 @@ abstract class AbstractQuery
*/
public function setParameter($key, $value, $type = null)
{
$filteredParameters = $this->parameters->filter(
function ($parameter) use ($key)
{
// Must not be identical because of string to integer conversion
return ($key == $parameter->getName());
}
);
$existingParameter = $this->getParameter($key);
if (count($filteredParameters)) {
$parameter = $filteredParameters->first();
$parameter->setValue($value, $type);
if ($existingParameter !== null) {
$existingParameter->setValue($value, $type);
return $this;
}
+6 -3
View File
@@ -76,7 +76,8 @@ class SequenceGenerator extends AbstractIdGenerator implements Serializable
$conn = $em->getConnection();
$sql = $conn->getDatabasePlatform()->getSequenceNextValSQL($this->_sequenceName);
$this->_nextValue = (int)$conn->fetchColumn($sql);
// Using `query` to force usage of the master server in MasterSlaveConnection
$this->_nextValue = (int) $conn->query($sql)->fetchColumn();
$this->_maxValue = $this->_nextValue + $this->_allocationSize;
}
@@ -108,10 +109,12 @@ class SequenceGenerator extends AbstractIdGenerator implements Serializable
*/
public function serialize()
{
return serialize(array(
return serialize(
[
'allocationSize' => $this->_allocationSize,
'sequenceName' => $this->_sequenceName
));
]
);
}
/**
@@ -2949,7 +2949,7 @@ class ClassMetadataInfo implements ClassMetadata
*/
public function setSequenceGeneratorDefinition(array $definition)
{
if ( ! isset($definition['sequenceName'])) {
if ( ! isset($definition['sequenceName']) || trim($definition['sequenceName']) === '') {
throw MappingException::missingSequenceName($this->name);
}
@@ -2958,6 +2958,14 @@ class ClassMetadataInfo implements ClassMetadata
$definition['quoted'] = true;
}
if ( ! isset($definition['allocationSize']) || trim($definition['allocationSize']) === '') {
$definition['allocationSize'] = '1';
}
if ( ! isset($definition['initialValue']) || trim($definition['initialValue']) === '') {
$definition['initialValue'] = '1';
}
$this->sequenceGeneratorDefinition = $definition;
}
@@ -811,7 +811,8 @@ class XmlDriver extends FileDriver
protected function loadMappingFile($file)
{
$result = array();
$xmlElement = simplexml_load_file($file);
// Note: we do not use `simplexml_load_file()` because of https://bugs.php.net/bug.php?id=62577
$xmlElement = simplexml_load_string(file_get_contents($file));
if (isset($xmlElement->entity)) {
foreach ($xmlElement->entity as $entityElement) {
@@ -239,9 +239,10 @@ class ManyToManyPersister extends AbstractCollectionPersister
$parameters = $this->expandCriteriaParameters($criteria);
foreach ($parameters as $parameter) {
list($name, $value) = $parameter;
$whereClauses[] = sprintf('te.%s = ?', $name);
$params[] = $value;
list($name, $value, $operator) = $parameter;
$whereClauses[] = sprintf('te.%s %s ?', $name, $operator);
$params[] = $value;
}
$mapping = $collection->getMapping();
@@ -820,7 +820,7 @@ class BasicEntityPersister implements EntityPersister
? $this->expandCriteriaParameters($criteria)
: $this->expandParameters($criteria);
return $this->conn->executeQuery($sql, $params, $types)->fetchColumn();
return (int) $this->conn->executeQuery($sql, $params, $types)->fetchColumn();
}
/**
@@ -61,7 +61,7 @@ class SqlValueVisitor extends ExpressionVisitor
}
$this->values[] = $value;
$this->types[] = array($field, $value);
$this->types[] = array($field, $value, $operator);
}
/**
+9 -18
View File
@@ -529,24 +529,15 @@ class QueryBuilder
*/
public function setParameter($key, $value, $type = null)
{
$filteredParameters = $this->parameters->filter(
function ($parameter) use ($key)
{
// Must not be identical because of string to integer conversion
return ($key == $parameter->getName());
}
);
$existingParameter = $this->getParameter($key);
if (count($filteredParameters)) {
$parameter = $filteredParameters->first();
$parameter->setValue($value, $type);
if ($existingParameter !== null) {
$existingParameter->setValue($value, $type);
return $this;
}
$parameter = new Query\Parameter($key, $value, $type);
$this->parameters->add($parameter);
$this->parameters->add(new Query\Parameter($key, $value, $type));
return $this;
}
@@ -609,14 +600,14 @@ class QueryBuilder
public function getParameter($key)
{
$filteredParameters = $this->parameters->filter(
function ($parameter) use ($key)
{
// Must not be identical because of string to integer conversion
return ($key == $parameter->getName());
function (Query\Parameter $parameter) use ($key) {
$parameterName = $parameter->getName();
return $key === $parameterName || (string) $key === (string) $parameterName;
}
);
return count($filteredParameters) ? $filteredParameters->first() : null;
return ! $filteredParameters->isEmpty() ? $filteredParameters->first() : null;
}
/**
+75 -27
View File
@@ -15,7 +15,7 @@
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
*/
namespace Doctrine\ORM\Tools;
@@ -122,32 +122,7 @@ class Setup
public static function createConfiguration($isDevMode = false, $proxyDir = null, Cache $cache = null)
{
$proxyDir = $proxyDir ?: sys_get_temp_dir();
if ($isDevMode === false && $cache === null) {
if (extension_loaded('apc')) {
$cache = new \Doctrine\Common\Cache\ApcCache();
} elseif (extension_loaded('xcache')) {
$cache = new \Doctrine\Common\Cache\XcacheCache();
} elseif (extension_loaded('memcache')) {
$memcache = new \Memcache();
$memcache->connect('127.0.0.1');
$cache = new \Doctrine\Common\Cache\MemcacheCache();
$cache->setMemcache($memcache);
} elseif (extension_loaded('redis')) {
$redis = new \Redis();
$redis->connect('127.0.0.1');
$cache = new \Doctrine\Common\Cache\RedisCache();
$cache->setRedis($redis);
} else {
$cache = new ArrayCache();
}
} elseif ($cache === null) {
$cache = new ArrayCache();
}
if ($cache instanceof CacheProvider) {
$cache->setNamespace("dc2_" . md5($proxyDir) . "_"); // to avoid collisions
}
$cache = self::createCacheConfiguration($isDevMode, $proxyDir, $cache);
$config = new Configuration();
$config->setMetadataCacheImpl($cache);
@@ -159,4 +134,77 @@ class Setup
return $config;
}
/**
* @param bool $isDevMode
* @param string $proxyDir
* @param Cache|null $cache
*
* @return Cache
*/
private static function createCacheConfiguration($isDevMode, $proxyDir, Cache $cache = null)
{
$cache = self::createCacheInstance($isDevMode, $cache);
if ( ! $cache instanceof CacheProvider) {
return $cache;
}
$namespace = $cache->getNamespace();
if ($namespace !== '') {
$namespace .= ':';
}
$cache->setNamespace($namespace . 'dc2_' . md5($proxyDir) . '_'); // to avoid collisions
return $cache;
}
/**
* @param bool $isDevMode
* @param Cache|null $cache
*
* @return Cache
*/
private static function createCacheInstance($isDevMode, Cache $cache = null)
{
if ($cache !== null) {
return $cache;
}
if ($isDevMode === true) {
return new ArrayCache();
}
if (extension_loaded('apc')) {
return new \Doctrine\Common\Cache\ApcCache();
}
if (extension_loaded('xcache')) {
return new \Doctrine\Common\Cache\XcacheCache();
}
if (extension_loaded('memcache')) {
$memcache = new \Memcache();
$memcache->connect('127.0.0.1');
$cache = new \Doctrine\Common\Cache\MemcacheCache();
$cache->setMemcache($memcache);
return $cache;
}
if (extension_loaded('redis')) {
$redis = new \Redis();
$redis->connect('127.0.0.1');
$cache = new \Doctrine\Common\Cache\RedisCache();
$cache->setRedis($redis);
return $cache;
}
return new ArrayCache();
}
}
+2 -2
View File
@@ -22,7 +22,7 @@ namespace Doctrine\ORM;
/**
* Class to store and retrieve the version of Doctrine
*
*
*
* @link www.doctrine-project.org
* @since 2.0
* @version $Revision$
@@ -36,7 +36,7 @@ class Version
/**
* Current Doctrine Version
*/
const VERSION = '2.5.9';
const VERSION = '2.5.13';
/**
* Compares a Doctrine version with the current one.
+51 -8
View File
@@ -2,16 +2,29 @@
namespace Doctrine\Tests\Mocks;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\Statement;
/**
* Mock class for Connection.
*/
class ConnectionMock extends \Doctrine\DBAL\Connection
class ConnectionMock extends Connection
{
/**
* @var mixed
*/
private $_fetchOneResult;
/**
* @var \Exception|null
*/
private $_fetchOneException;
/**
* @var Statement|null
*/
private $_queryResult;
/**
* @var DatabasePlatformMock
*/
@@ -25,12 +38,12 @@ class ConnectionMock extends \Doctrine\DBAL\Connection
/**
* @var array
*/
private $_inserts = array();
private $_inserts = [];
/**
* @var array
*/
private $_executeUpdates = array();
private $_executeUpdates = [];
/**
* @param array $params
@@ -59,7 +72,7 @@ class ConnectionMock extends \Doctrine\DBAL\Connection
/**
* {@inheritdoc}
*/
public function insert($tableName, array $data, array $types = array())
public function insert($tableName, array $data, array $types = [])
{
$this->_inserts[$tableName][] = $data;
}
@@ -67,9 +80,9 @@ class ConnectionMock extends \Doctrine\DBAL\Connection
/**
* {@inheritdoc}
*/
public function executeUpdate($query, array $params = array(), array $types = array())
public function executeUpdate($query, array $params = [], array $types = [])
{
$this->_executeUpdates[] = array('query' => $query, 'params' => $params, 'types' => $types);
$this->_executeUpdates[] = ['query' => $query, 'params' => $params, 'types' => $types];
}
/**
@@ -83,11 +96,23 @@ class ConnectionMock extends \Doctrine\DBAL\Connection
/**
* {@inheritdoc}
*/
public function fetchColumn($statement, array $params = array(), $colnum = 0, array $types = array())
public function fetchColumn($statement, array $params = [], $colnum = 0, array $types = [])
{
if (null !== $this->_fetchOneException) {
throw $this->_fetchOneException;
}
return $this->_fetchOneResult;
}
/**
* {@inheritdoc}
*/
public function query()
{
return $this->_queryResult;
}
/**
* {@inheritdoc}
*/
@@ -111,6 +136,16 @@ class ConnectionMock extends \Doctrine\DBAL\Connection
$this->_fetchOneResult = $fetchOneResult;
}
/**
* @param \Exception|null $exception
*
* @return void
*/
public function setFetchOneException(\Exception $exception = null)
{
$this->_fetchOneException = $exception;
}
/**
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
*
@@ -131,6 +166,14 @@ class ConnectionMock extends \Doctrine\DBAL\Connection
$this->_lastInsertId = $id;
}
/**
* @param Statement $result
*/
public function setQueryResult(Statement $result)
{
$this->_queryResult = $result;
}
/**
* @return array
*/
@@ -152,7 +195,7 @@ class ConnectionMock extends \Doctrine\DBAL\Connection
*/
public function reset()
{
$this->_inserts = array();
$this->_inserts = [];
$this->_lastInsertId = 0;
}
}
@@ -0,0 +1,65 @@
<?php
namespace Doctrine\Tests\Mocks;
/**
* Simple statement mock that returns result based on array.
* Doesn't support fetch modes
*/
class StatementArrayMock extends StatementMock
{
/**
* @var array
*/
private $_result;
public function __construct($result)
{
$this->_result = $result;
}
public function getIterator()
{
return new \ArrayIterator($this->_result);
}
public function columnCount()
{
$row = reset($this->_result);
if ($row) {
return count($row);
} else {
return 0;
}
}
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
{
return $this->_result;
}
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
{
$current = current($this->_result);
next($this->_result);
return $current;
}
public function fetchColumn($columnIndex = 0)
{
$current = current($this->_result);
if ($current) {
next($this->_result);
return reset($current);
} else {
return false;
}
}
public function rowCount()
{
return count($this->_result);
}
}
@@ -27,7 +27,7 @@ class DefaultRegionTest extends AbstractRegionTest
public function testSharedRegion()
{
if ( ! extension_loaded('apc') || false === @apc_cache_info()) {
if ( ! extension_loaded('apc') || ! is_array(@apc_cache_info("user"))) {
$this->markTestSkipped('The ' . __CLASS__ .' requires the use of APC');
}
@@ -97,4 +97,4 @@ class DefaultRegionTest extends AbstractRegionTest
$this->assertEquals($value1, $actual[0]);
$this->assertEquals($value2, $actual[1]);
}
}
}
@@ -28,7 +28,7 @@ class NonStrictReadWriteCachedEntityPersisterTest extends AbstractEntityPersiste
{
$entity = new Country("Foo");
$persister = $this->createPersisterDefault();
$property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Entity\ReadWriteCachedEntityPersister', 'queuedCache');
$property = new \ReflectionProperty($persister, 'queuedCache');
$property->setAccessible(true);
@@ -50,7 +50,7 @@ class NonStrictReadWriteCachedEntityPersisterTest extends AbstractEntityPersiste
$persister = $this->createPersisterDefault();
$key = new EntityCacheKey(Country::CLASSNAME, array('id'=>1));
$entry = new EntityCacheEntry(Country::CLASSNAME, array('id'=>1, 'name'=>'Foo'));
$property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Entity\ReadWriteCachedEntityPersister', 'queuedCache');
$property = new \ReflectionProperty($persister, 'queuedCache');
$property->setAccessible(true);
@@ -87,7 +87,7 @@ class NonStrictReadWriteCachedEntityPersisterTest extends AbstractEntityPersiste
$persister = $this->createPersisterDefault();
$key = new EntityCacheKey(Country::CLASSNAME, array('id'=>1));
$entry = new EntityCacheEntry(Country::CLASSNAME, array('id'=>1, 'name'=>'Foo'));
$property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Entity\ReadWriteCachedEntityPersister', 'queuedCache');
$property = new \ReflectionProperty($persister, 'queuedCache');
$property->setAccessible(true);
@@ -115,7 +115,7 @@ class NonStrictReadWriteCachedEntityPersisterTest extends AbstractEntityPersiste
$entity = new Country("Foo");
$persister = $this->createPersisterDefault();
$key = new EntityCacheKey(Country::CLASSNAME, array('id'=>1));
$property = new \ReflectionProperty('Doctrine\ORM\Cache\Persister\Entity\ReadWriteCachedEntityPersister', 'queuedCache');
$property = new \ReflectionProperty($persister, 'queuedCache');
$property->setAccessible(true);
@@ -129,6 +129,7 @@ class QueryCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase
->will($this->returnValue( 10 ));
$parserResultMock = $this->getMock('Doctrine\ORM\Query\ParserResult');
$parserResultMock->method('getParameterMappings')->willReturn(array());
$parserResultMock->expects($this->once())
->method('getSqlExecutor')
->will($this->returnValue($sqlExecMock));
@@ -0,0 +1,29 @@
<?php
namespace Doctrine\Test\ORM\Functional\Ticket;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\Tests\OrmFunctionalTestCase;
final class GH6682Test extends OrmFunctionalTestCase
{
/**
* @group 6682
*/
public function testIssue()
{
$parsedDefinition = [
'sequenceName' => 'test_sequence',
'allocationSize' => '',
'initialValue' => '',
];
$classMetadataInfo = new ClassMetadataInfo('test_entity');
$classMetadataInfo->setSequenceGeneratorDefinition($parsedDefinition);
self::assertSame(
['sequenceName' => 'test_sequence', 'allocationSize' => '1', 'initialValue' => '1'],
$classMetadataInfo->sequenceGeneratorDefinition
);
}
}
@@ -0,0 +1,55 @@
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Tests\OrmFunctionalTestCase;
/**
* @group 6699
*/
final class GH6699Test extends OrmFunctionalTestCase
{
protected function setUp()
{
$this->useModelSet('cms');
parent::setUp();
}
public function testMixedParametersWithZeroNumber()
{
$query = $this->_em->createQueryBuilder()
->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->andWhere('u.username = :username')
->andWhere('u.id = ?0')
->getQuery();
$query->setParameter('username', 'bar');
$query->setParameter(0, 0);
$query->execute();
self::assertCount(2, $query->getParameters());
self::assertSame(0, $query->getParameter(0)->getValue());
self::assertSame('bar', $query->getParameter('username')->getValue());
}
public function testMixedParametersWithZeroNumberOnQueryBuilder()
{
$query = $this->_em->createQueryBuilder()
->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->andWhere('u.username = :username')
->andWhere('u.id = ?0')
->setParameter('username', 'bar')
->setParameter(0, 0)
->getQuery();
$query->execute();
self::assertCount(2, $query->getParameters());
self::assertSame(0, $query->getParameter(0)->getValue());
self::assertSame('bar', $query->getParameter('username')->getValue());
}
}
@@ -0,0 +1,108 @@
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Tests\OrmFunctionalTestCase;
use Doctrine\Tests\Models\ECommerce\ECommerceProduct;
use Doctrine\Tests\Models\ECommerce\ECommerceCategory;
use Doctrine\Common\Collections\Criteria;
final class GH6740Test extends OrmFunctionalTestCase
{
/**
* @var int
*/
private $productId;
/**
* @var int
*/
private $firstCategoryId;
/**
* @var int
*/
private $secondCategoryId;
public function setUp()
{
$this->useModelSet('ecommerce');
parent::setUp();
$product = new ECommerceProduct();
$product->setName('First Product');
$firstCategory = new ECommerceCategory();
$secondCategory = new ECommerceCategory();
$firstCategory->setName('Business');
$secondCategory->setName('Home');
$product->addCategory($firstCategory);
$product->addCategory($secondCategory);
$this->_em->persist($product);
$this->_em->flush();
$this->_em->clear();
$this->productId = $product->getId();
$this->firstCategoryId = $firstCategory->getId();
$this->secondCategoryId = $secondCategory->getId();
}
/**
* @group 6740
*/
public function testCollectionFilteringLteOperator()
{
$product = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $this->productId);
$criteria = Criteria::create()->where(Criteria::expr()->lte('id', $this->secondCategoryId));
self::assertCount(2, $product->getCategories()->matching($criteria));
}
/**
* @group 6740
*/
public function testCollectionFilteringLtOperator()
{
$product = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $this->productId);
$criteria = Criteria::create()->where(Criteria::expr()->lt('id', $this->secondCategoryId));
self::assertCount(1, $product->getCategories()->matching($criteria));
}
/**
* @group 6740
*/
public function testCollectionFilteringGteOperator()
{
$product = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $this->productId);
$criteria = Criteria::create()->where(Criteria::expr()->gte('id', $this->firstCategoryId));
self::assertCount(2, $product->getCategories()->matching($criteria));
}
/**
* @group 6740
*/
public function testCollectionFilteringGtOperator()
{
$product = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $this->productId);
$criteria = Criteria::create()->where(Criteria::expr()->gt('id', $this->firstCategoryId));
self::assertCount(1, $product->getCategories()->matching($criteria));
}
/**
* @group 6740
*/
public function testCollectionFilteringEqualsOperator()
{
$product = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $this->productId);
$criteria = Criteria::create()->where(Criteria::expr()->eq('id', $this->firstCategoryId));
self::assertCount(1, $product->getCategories()->matching($criteria));
}
}
@@ -2,12 +2,7 @@
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\ORM\Events;
use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\ORM\Internal\Hydration\AbstractHydrator;
use Doctrine\Tests\OrmFunctionalTestCase;
@@ -25,11 +20,11 @@ class AbstractHydratorTest extends OrmFunctionalTestCase
*/
public function testOnClearEventListenerIsDetachedOnCleanup()
{
$mockConnection = $this->createMock(Connection::class);
$mockEntityManagerInterface = $this->createMock(EntityManagerInterface::class);
$mockEventManager = $this->createMock(EventManager::class);
$mockStatement = $this->createMock(Statement::class);
$mockResultMapping = $this->getMockBuilder(ResultSetMapping::class);
$mockConnection = $this->getMockBuilder('Doctrine\DBAL\Connection')->disableOriginalConstructor()->getMock();
$mockEntityManagerInterface = $this->getMock('Doctrine\ORM\EntityManagerInterface');
$mockEventManager = $this->getMock('Doctrine\Common\EventManager');
$mockStatement = $this->getMock('Doctrine\DBAL\Driver\Statement');
$mockResultMapping = $this->getMock('Doctrine\ORM\Query\ResultSetMapping');
$mockEntityManagerInterface->expects(self::any())->method('getEventManager')->willReturn($mockEventManager);
$mockEntityManagerInterface->expects(self::any())->method('getConnection')->willReturn($mockConnection);
@@ -37,7 +32,7 @@ class AbstractHydratorTest extends OrmFunctionalTestCase
/* @var $mockAbstractHydrator AbstractHydrator */
$mockAbstractHydrator = $this
->getMockBuilder(AbstractHydrator::class)
->getMockBuilder('Doctrine\ORM\Internal\Hydration\AbstractHydrator')
->setConstructorArgs([$mockEntityManagerInterface])
->setMethods(['hydrateAllData'])
->getMock();
@@ -2,37 +2,58 @@
namespace Doctrine\Tests\ORM\Id;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Id\SequenceGenerator;
use Doctrine\Tests\Mocks\ConnectionMock;
use Doctrine\Tests\Mocks\StatementArrayMock;
use Doctrine\Tests\OrmTestCase;
/**
* Description of SequenceGeneratorTest
*
* @author robo
*/
class SequenceGeneratorTest extends \Doctrine\Tests\OrmTestCase
class SequenceGeneratorTest extends OrmTestCase
{
private $_em;
private $_seqGen;
/**
* @var EntityManager
*/
private $entityManager;
/**
* @var SequenceGenerator
*/
private $sequenceGenerator;
/**
* @var ConnectionMock
*/
private $connection;
protected function setUp()
{
$this->_em = $this->_getTestEntityManager();
$this->_seqGen = new SequenceGenerator('seq', 10);
parent::setUp();
$this->entityManager = $this->_getTestEntityManager();
$this->sequenceGenerator = new SequenceGenerator('seq', 10);
$this->connection = $this->entityManager->getConnection();
self::assertInstanceOf('Doctrine\Tests\Mocks\ConnectionMock', $this->connection);
}
public function testGeneration()
{
for ($i=0; $i < 42; ++$i) {
$this->connection->setFetchOneException(new \BadMethodCallException(
'Fetch* method used. Query method should be used instead, '
. 'as NEXTVAL should be run on a master server in master-slave setup.'
));
for ($i = 0; $i < 42; ++$i) {
if ($i % 10 == 0) {
$this->_em->getConnection()->setFetchOneResult((int)($i / 10) * 10);
$this->connection->setQueryResult(new StatementArrayMock([[(int)($i / 10) * 10]]));
}
$id = $this->_seqGen->generate($this->_em, null);
$this->assertEquals($i, $id);
$this->assertEquals((int)($i / 10) * 10 + 10, $this->_seqGen->getCurrentMaxValue());
$this->assertEquals($i + 1, $this->_seqGen->getNextValue());
$id = $this->sequenceGenerator->generate($this->entityManager, null);
self::assertSame($i, $id);
self::assertSame((int)($i / 10) * 10 + 10, $this->sequenceGenerator->getCurrentMaxValue());
self::assertSame($i + 1, $this->sequenceGenerator->getNextValue());
}
}
}
@@ -1083,15 +1083,19 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
/**
* @group DDC-2662
* @group 6682
*/
public function testQuotedSequenceName()
{
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new RuntimeReflectionService());
$cm->initializeReflection(new RuntimeReflectionService());
$cm->setSequenceGeneratorDefinition(array('sequenceName' => '`foo`'));
$this->assertEquals(array('sequenceName' => 'foo', 'quoted' => true), $cm->sequenceGeneratorDefinition);
self::assertSame(
array('sequenceName' => 'foo', 'quoted' => true, 'allocationSize' => '1', 'initialValue' => '1'),
$cm->sequenceGeneratorDefinition
);
}
/**
@@ -197,4 +197,66 @@ class QueryTest extends \Doctrine\Tests\OrmTestCase
$q2 = clone $query;
$this->assertSame($config->getDefaultQueryHints(), $q2->getHints());
}
/**
* @group 6699
*/
public function testGetParameterTypeJuggling()
{
$query = $this->_em->createQuery('select u from Doctrine\Tests\Models\CMS\CmsUser u where u.id = ?0');
$query->setParameter(0, 0);
self::assertCount(1, $query->getParameters());
self::assertSame(0, $query->getParameter(0)->getValue());
self::assertSame(0, $query->getParameter('0')->getValue());
}
/**
* @group 6699
*/
public function testSetParameterWithNameZeroIsNotOverridden()
{
$query = $this->_em->createQuery('select u from Doctrine\Tests\Models\CMS\CmsUser u where u.id != ?0 and u.username = :name');
$query->setParameter(0, 0);
$query->setParameter('name', 'Doctrine');
self::assertCount(2, $query->getParameters());
self::assertSame(0, $query->getParameter('0')->getValue());
self::assertSame('Doctrine', $query->getParameter('name')->getValue());
}
/**
* @group 6699
*/
public function testSetParameterWithNameZeroDoesNotOverrideAnotherParameter()
{
$query = $this->_em->createQuery('select u from Doctrine\Tests\Models\CMS\CmsUser u where u.id != ?0 and u.username = :name');
$query->setParameter('name', 'Doctrine');
$query->setParameter(0, 0);
self::assertCount(2, $query->getParameters());
self::assertSame(0, $query->getParameter(0)->getValue());
self::assertSame('Doctrine', $query->getParameter('name')->getValue());
}
/**
* @group 6699
*/
public function testSetParameterWithTypeJugglingWorks()
{
$query = $this->_em->createQuery('select u from Doctrine\Tests\Models\CMS\CmsUser u where u.id != ?0 and u.username = :name');
$query->setParameter('0', 1);
$query->setParameter('name', 'Doctrine');
$query->setParameter(0, 2);
$query->setParameter('0', 3);
self::assertCount(2, $query->getParameters());
self::assertSame(3, $query->getParameter(0)->getValue());
self::assertSame(3, $query->getParameter('0')->getValue());
self::assertSame('Doctrine', $query->getParameter('name')->getValue());
}
}
@@ -1172,4 +1172,81 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
$this->assertEquals(['u', 'g'], $aliases);
}
/**
* @group 6699
*/
public function testGetParameterTypeJuggling()
{
$builder = $this->_em->createQueryBuilder()
->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->where('u.id = ?0');
$builder->setParameter(0, 0);
self::assertCount(1, $builder->getParameters());
self::assertSame(0, $builder->getParameter(0)->getValue());
self::assertSame(0, $builder->getParameter('0')->getValue());
}
/**
* @group 6699
*/
public function testSetParameterWithNameZeroIsNotOverridden()
{
$builder = $this->_em->createQueryBuilder()
->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->where('u.id != ?0')
->andWhere('u.username = :name');
$builder->setParameter(0, 0);
$builder->setParameter('name', 'Doctrine');
self::assertCount(2, $builder->getParameters());
self::assertSame(0, $builder->getParameter('0')->getValue());
self::assertSame('Doctrine', $builder->getParameter('name')->getValue());
}
/**
* @group 6699
*/
public function testSetParameterWithNameZeroDoesNotOverrideAnotherParameter()
{
$builder = $this->_em->createQueryBuilder()
->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->where('u.id != ?0')
->andWhere('u.username = :name');
$builder->setParameter('name', 'Doctrine');
$builder->setParameter(0, 0);
self::assertCount(2, $builder->getParameters());
self::assertSame(0, $builder->getParameter(0)->getValue());
self::assertSame('Doctrine', $builder->getParameter('name')->getValue());
}
/**
* @group 6699
*/
public function testSetParameterWithTypeJugglingWorks()
{
$builder = $this->_em->createQueryBuilder()
->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->where('u.id != ?0')
->andWhere('u.username = :name');
$builder->setParameter('0', 1);
$builder->setParameter('name', 'Doctrine');
$builder->setParameter(0, 2);
$builder->setParameter('0', 3);
self::assertCount(2, $builder->getParameters());
self::assertSame(3, $builder->getParameter(0)->getValue());
self::assertSame(3, $builder->getParameter('0')->getValue());
self::assertSame('Doctrine', $builder->getParameter('name')->getValue());
}
}
+38 -1
View File
@@ -68,6 +68,43 @@ class SetupTest extends \Doctrine\Tests\OrmTestCase
$this->assertInstanceOf('Doctrine\ORM\Mapping\Driver\YamlDriver', $config->getMetadataDriverImpl());
}
/**
* @group 5904
*/
public function testCacheNamespaceShouldBeGeneratedWhenCacheIsNotGiven()
{
$config = Setup::createConfiguration(false, '/foo');
$cache = $config->getMetadataCacheImpl();
self::assertSame('dc2_1effb2475fcfba4f9e8b8a1dbc8f3caf_', $cache->getNamespace());
}
/**
* @group 5904
*/
public function testCacheNamespaceShouldBeGeneratedWhenCacheIsGivenButHasNoNamespace()
{
$config = Setup::createConfiguration(false, '/foo', new ArrayCache());
$cache = $config->getMetadataCacheImpl();
self::assertSame('dc2_1effb2475fcfba4f9e8b8a1dbc8f3caf_', $cache->getNamespace());
}
/**
* @group 5904
*/
public function testConfiguredCacheNamespaceShouldBeUsedAsPrefixOfGeneratedNamespace()
{
$originalCache = new ArrayCache();
$originalCache->setNamespace('foo');
$config = Setup::createConfiguration(false, '/foo', $originalCache);
$cache = $config->getMetadataCacheImpl();
self::assertSame($originalCache, $cache);
self::assertSame('foo:dc2_1effb2475fcfba4f9e8b8a1dbc8f3caf_', $cache->getNamespace());
}
/**
* @group DDC-1350
*/
@@ -98,7 +135,7 @@ class SetupTest extends \Doctrine\Tests\OrmTestCase
$cache = $this->getMock('Doctrine\Common\Cache\Cache');
$cache->expects($this->never())->method('setNamespace');
$config = Setup::createConfiguration(array(), true, $cache);
$config = Setup::createConfiguration(true, null, $cache);
$this->assertSame($cache, $config->getResultCacheImpl());
$this->assertSame($cache, $config->getMetadataCacheImpl());