1
0
mirror of synced 2025-01-18 06:21:40 +03:00

DDC-770 - Cleanup Query instance when its cloned

This commit is contained in:
Benjamin Eberlei 2010-08-27 21:28:26 +02:00
parent 241e4d2f53
commit 8a21ab4755
4 changed files with 64 additions and 22 deletions

View File

@ -138,10 +138,16 @@ abstract class AbstractQuery
/**
* Frees the resources used by the query object.
*
* Resets Parameters, Parameter Types and Query Hints.
*
* @return void
*/
public function free()
{
$this->_params = array();
$this->_paramTypes = array();
$this->_hints = array();
}
/**
@ -569,4 +575,14 @@ abstract class AbstractQuery
* @return Doctrine\DBAL\Driver\Statement The executed database statement that holds the results.
*/
abstract protected function _doExecute();
/**
* Cleanup Query resource when clone is called.
*
* @return void
*/
public function __clone()
{
$this->free();
}
}

View File

@ -19,28 +19,6 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->useModelSet('cms');
parent::setUp();
}
/**
* @expectedException Doctrine\ORM\Query\QueryException
*/
public function testParameterIndexZeroThrowsException()
{
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1");
$query->execute(array(42)); // same as array(0 => 42), 0 is invalid parameter position
}
public function testGetParameters()
{
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1");
$this->assertEquals(array(), $query->getParameters());
}
public function testGetParameters_HasSomeAlready()
{
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1");
$query->setParameter(2, 84);
$this->assertEquals(array(2 => 84), $query->getParameters());
}
public function testSimpleQueries()
{

View File

@ -26,6 +26,7 @@ class AllTests
$suite->addTestSuite('Doctrine\Tests\ORM\Query\UpdateSqlGenerationTest');
$suite->addTestSuite('Doctrine\Tests\ORM\Query\ExprTest');
$suite->addTestSuite('Doctrine\Tests\ORM\Query\ParserResultTest');
$suite->addTestSuite('Doctrine\Tests\ORM\Query\QueryTest');
return $suite;
}

View File

@ -0,0 +1,47 @@
<?php
namespace Doctrine\Tests\ORM\Query;
require_once __DIR__ . '/../../TestInit.php';
class QueryTest extends \Doctrine\Tests\OrmTestCase
{
protected $_em = null;
protected function setUp()
{
$this->_em = $this->_getTestEntityManager();
}
/**
* @expectedException Doctrine\ORM\Query\QueryException
*/
public function testParameterIndexZeroThrowsException()
{
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1");
$query->execute(array(42)); // same as array(0 => 42), 0 is invalid parameter position
}
public function testGetParameters()
{
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1");
$this->assertEquals(array(), $query->getParameters());
}
public function testGetParameters_HasSomeAlready()
{
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1");
$query->setParameter(2, 84);
$this->assertEquals(array(2 => 84), $query->getParameters());
}
public function testFree()
{
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1");
$query->setParameter(2, 84, \PDO::PARAM_INT);
$query->free();
$this->assertEquals(array(), $query->getParameters());
}
}