mirror of
https://github.com/doctrine/orm.git
synced 2026-04-22 22:18:04 +02:00
Compare commits
38 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 93103f44a3 | |||
| ffdb769564 | |||
| 95344d019f | |||
| 640d9af50f | |||
| a23e909158 | |||
| a857a610db | |||
| f0006eb42d | |||
| 7ea97e69ca | |||
| de4b40b29f | |||
| e21217dd0e | |||
| b82aef2748 | |||
| 44b3405714 | |||
| e874d93f61 | |||
| bb31472727 | |||
| fd72aa08d2 | |||
| 21f73cf923 | |||
| 2701f5058e | |||
| 4bd2f68483 | |||
| 823da6d839 | |||
| 6318796965 | |||
| c811c3ac84 | |||
| aba62edcc8 | |||
| 0b4e5b42e1 | |||
| 3d4f236052 | |||
| 049470c787 | |||
| cfaad4fedc | |||
| e8a89c3bc3 | |||
| 497be59f5c | |||
| e1b851f2e9 | |||
| 984535cadc | |||
| 35a579efdc | |||
| a2b4e5b293 | |||
| 24d95796bb | |||
| 249b737094 | |||
| 36dc28d43e | |||
| 0ec9e53c8d | |||
| aa80f6c0b5 | |||
| fd6d4890c4 |
+3
-3
@@ -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": {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.10';
|
||||
const VERSION = '2.5.13';
|
||||
|
||||
/**
|
||||
* Compares a Doctrine version with the current one.
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -20,11 +20,11 @@ class AbstractHydratorTest extends OrmFunctionalTestCase
|
||||
*/
|
||||
public function testOnClearEventListenerIsDetachedOnCleanup()
|
||||
{
|
||||
$mockConnection = $this->createMock('Doctrine\DBAL\Connection');
|
||||
$mockEntityManagerInterface = $this->createMock('Doctrine\ORM\EntityManagerInterface');
|
||||
$mockEventManager = $this->createMock('Doctrine\Common\EventManager');
|
||||
$mockStatement = $this->createMock('Doctrine\DBAL\Driver\Statement');
|
||||
$mockResultMapping = $this->getMockBuilder('Doctrine\ORM\Query\ResultSetMapping');
|
||||
$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);
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user