Commit 8e3f6eee authored by romanb's avatar romanb

[2.0][DDC-121] Fixed. Also fixed memcache tests and some small refactorings.

parent 7f725aa7
......@@ -328,7 +328,7 @@ class Connection
}
/**
* Convenience method for PDO::query("...") followed by $stmt->fetchAll(PDO::FETCH_COLUMN, ...).
* Convenience method for PDO::query("...") followed by $stmt->fetchColumn(...).
*
* @param string $statement sql query to be executed
* @param array $params prepared statement params
......@@ -337,7 +337,7 @@ class Connection
*/
public function fetchColumn($statement, array $params = array(), $colnum = 0)
{
return $this->execute($statement, $params)->fetchAll(Connection::FETCH_COLUMN, $colnum);
return $this->execute($statement, $params)->fetchColumn($colnum);
}
/**
......@@ -536,19 +536,6 @@ class Connection
return $this->execute($sql, $params)->fetchAll(Connection::FETCH_ASSOC);
}
/**
* Convenience method for PDO::query("...") followed by $stmt->fetchColumn().
*
* @param string $statement The SQL query.
* @param array $params The query parameters.
* @param int $colnum 0-indexed column number to retrieve
* @return mixed
*/
public function fetchOne($statement, array $params = array(), $colnum = 0)
{
return $this->execute($statement, $params)->fetchColumn($colnum);
}
/**
* Prepares an SQL statement.
*
......
......@@ -35,7 +35,7 @@ interface Connection
function query();
function quote($input);
function exec($statement);
function lastInsertId();
function lastInsertId($name = null);
function beginTransaction();
function commit();
function rollBack();
......
......@@ -43,7 +43,8 @@ final class DriverManager
'pdo_sqlite' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver',
'pdo_pgsql' => 'Doctrine\DBAL\Driver\PDOPgSql\Driver',
'pdo_oci' => 'Doctrine\DBAL\Driver\PDOOracle\Driver',
'pdo_mssql' => 'Doctrine\DBAL\Driver\PDOMsSql\Driver'
'pdo_mssql' => 'Doctrine\DBAL\Driver\PDOMsSql\Driver',
'oci8' => 'Doctrine\DBAL\Driver\OCI8\Driver'
);
/** Private constructor. This class cannot be instantiated. */
......
......@@ -62,7 +62,7 @@ class SequenceGenerator extends AbstractIdGenerator implements \Serializable
// Allocate new values
$conn = $em->getConnection();
$sql = $conn->getDatabasePlatform()->getSequenceNextValSql($this->_sequenceName);
$this->_nextValue = $conn->fetchOne($sql);
$this->_nextValue = $conn->fetchColumn($sql);
$this->_maxValue = $this->_nextValue + $this->_allocationSize;
}
return $this->_nextValue++;
......
......@@ -36,10 +36,10 @@ class SingleScalarHydrator extends AbstractHydrator
$cache = array();
$result = $this->_stmt->fetchAll(Connection::FETCH_ASSOC);
//TODO: Let this exception be raised by Query as QueryException
if (count($result) > 1 || count($result[0]) > 1) {
if (count($result) > 1 || count($result[key($result)]) > 1) {
throw HydrationException::nonUniqueResult();
}
$result = $this->_gatherScalarRowData($result[0], $cache);
$result = $this->_gatherScalarRowData($result[key($result)], $cache);
return array_shift($result);
}
......
......@@ -190,7 +190,7 @@ final class PersistentCollection implements \Doctrine\Common\Collections\Collect
} else {
// ManyToMany
$this->_typeClass->reflFields[$this->_backRefFieldName]
->getValue($element)->add($this->_owner);
->getValue($element)->unwrap()->add($this->_owner);
}
}
}
......@@ -229,8 +229,18 @@ final class PersistentCollection implements \Doctrine\Common\Collections\Collect
private function _initialize()
{
if ( ! $this->_initialized) {
if ($this->_isDirty) {
// Has NEW objects added through add(). Remember them.
$newObjects = $this->_coll->toArray();
}
$this->_coll->clear();
$this->_association->load($this->_owner, $this, $this->_em);
// Reattach NEW objects added through add(), if any.
if (isset($newObjects)) {
foreach ($newObjects as $obj) {
$this->_coll->add($obj);
}
}
$this->_initialized = true;
}
}
......@@ -242,6 +252,7 @@ final class PersistentCollection implements \Doctrine\Common\Collections\Collect
public function takeSnapshot()
{
$this->_snapshot = $this->_coll->toArray();
$this->_isDirty = false;
}
/**
......@@ -267,7 +278,8 @@ final class PersistentCollection implements \Doctrine\Common\Collections\Collect
}
/**
* INTERNAL getInsertDiff
* INTERNAL:
* getInsertDiff
*
* @return array
*/
......@@ -465,6 +477,7 @@ final class PersistentCollection implements \Doctrine\Common\Collections\Collect
*/
public function set($key, $value)
{
$this->_initialize();
$this->_coll->set($key, $value);
$this->_changed();
}
......
......@@ -193,7 +193,7 @@ class StandardEntityPersister
$sql = "SELECT " . $versionFieldColumnName . " FROM " . $class->getQuotedTableName($this->_platform) .
" WHERE " . implode(' = ? AND ', $identifier) . " = ?";
$value = $this->_conn->fetchColumn($sql, (array) $id);
$this->_class->setFieldValue($entity, $versionField, $value[0]);
$this->_class->setFieldValue($entity, $versionField, $value);
}
/**
......@@ -550,7 +550,8 @@ class StandardEntityPersister
$stmt = $this->_conn->prepare($this->_getSelectManyToManyEntityCollectionSql($assoc, $criteria));
$stmt->execute(array_values($criteria));
while ($result = $stmt->fetch(Connection::FETCH_ASSOC)) {
$coll->add($this->_createEntity($result));
//$coll->add($this->_createEntity($result));
$coll->hydrateAdd($this->_createEntity($result));
}
$stmt->closeCursor();
}
......
......@@ -8,9 +8,17 @@ require_once __DIR__ . '/../../TestInit.php';
class MemcacheCacheTest extends \Doctrine\Tests\DoctrineTestCase
{
private $_memcache;
public function setUp()
{
if ( ! extension_loaded('memcache')) {
if (extension_loaded('memcache')) {
$memcache = new \Memcache;
$ok = @$memcache->connect('localhost', 11211);
if (!$ok) {
$this->markTestSkipped('The ' . __CLASS__ .' requires the use of memcache');
}
} else {
$this->markTestSkipped('The ' . __CLASS__ .' requires the use of memcache');
}
}
......@@ -18,6 +26,7 @@ class MemcacheCacheTest extends \Doctrine\Tests\DoctrineTestCase
public function testMemcacheCacheDriver()
{
$cache = new MemcacheCache();
$cache->setMemcache($this->_memcache);
// Test save
$cache->save('test_key', 'testing this out');
......
......@@ -43,7 +43,7 @@ class ConnectionMock extends \Doctrine\DBAL\Connection
/**
* @override
*/
public function fetchOne($statement, array $params = array(), $colnum = 0)
public function fetchColumn($statement, array $params = array(), $colnum = 0)
{
return $this->_fetchOneResult;
}
......
......@@ -8,7 +8,7 @@ class DriverConnectionMock implements \Doctrine\DBAL\Driver\Connection
public function query() {}
public function quote($input) {}
public function exec($statement) {}
public function lastInsertId() {}
public function lastInsertId($name = null) {}
public function beginTransaction() {}
public function commit() {}
public function rollBack() {}
......
......@@ -94,9 +94,9 @@ class AdvancedAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCase
$definitions = $res[0]->getDefinitions();
$this->assertEquals(1, count($res));
$this->assertTrue($definitions[0] instanceof Definition);
$this->assertEquals(2, $definitions->count());
}
public function testManyToMany()
......
......@@ -380,6 +380,48 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
$gblanco->addPhonenumber($newPhone);
$this->assertFalse($gblanco->getPhonenumbers()->isInitialized());
$this->_em->persist($gblanco);
$this->_em->flush();
$this->_em->clear();
$query = $this->_em->createQuery("select u, p from Doctrine\Tests\Models\CMS\CmsUser u join u.phonenumbers p where u.username='gblanco'");
$gblanco2 = $query->getSingleResult();
$this->assertEquals(4, $gblanco2->getPhonenumbers()->count());
}
public function testInitializeCollectionWithNewObjectsRetainsNewObjects()
{
$user = new CmsUser;
$user->name = 'Guilherme';
$user->username = 'gblanco';
$user->status = 'developer';
for ($i=0; $i<3; ++$i) {
$phone = new CmsPhonenumber;
$phone->phonenumber = 100 + $i;
$user->addPhonenumber($phone);
}
$this->_em->persist($user);
$this->_em->flush();
$this->_em->clear();
$this->assertEquals(3, $user->getPhonenumbers()->count());
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username='gblanco'");
$gblanco = $query->getSingleResult();
$this->assertFalse($gblanco->getPhonenumbers()->isInitialized());
$newPhone = new CmsPhonenumber;
$newPhone->phonenumber = 555;
$gblanco->addPhonenumber($newPhone);
$this->assertFalse($gblanco->getPhonenumbers()->isInitialized());
$this->assertEquals(4, $gblanco->getPhonenumbers()->count());
$this->assertTrue($gblanco->getPhonenumbers()->isInitialized());
$this->_em->flush();
$this->_em->clear();
......
......@@ -178,6 +178,7 @@ class IdentityMapTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->flush();
$this->assertEquals(3, count($user->getPhonenumbers()));
$this->assertFalse($user->getPhonenumbers()->isDirty());
//external update to CmsAddress
$this->_em->getConnection()->executeUpdate('insert into cms_phonenumbers (phonenumber, user_id) VALUES (?,?)', array(999, $user->getId()));
......
......@@ -110,7 +110,6 @@ class ManyToManyBidirectionalAssociationTest extends AbstractManyToManyAssociati
$this->assertLoadingOfOwningSide($products);
}
private function _createLoadingFixture()
{
$this->firstProduct->addCategory($this->firstCategory);
......@@ -140,6 +139,7 @@ class ManyToManyBidirectionalAssociationTest extends AbstractManyToManyAssociati
$this->assertEquals(2, count($firstProductCategories));
$this->assertEquals(2, count($secondProductCategories));
$this->assertTrue($firstProductCategories[0] === $secondProductCategories[0]);
$this->assertTrue($firstProductCategories[1] === $secondProductCategories[1]);
......@@ -148,7 +148,7 @@ class ManyToManyBidirectionalAssociationTest extends AbstractManyToManyAssociati
$this->assertEquals(2, count($firstCategoryProducts));
$this->assertEquals(2, count($secondCategoryProducts));
$this->assertTrue($firstCategoryProducts[0] instanceof ECommerceProduct);
$this->assertTrue($firstCategoryProducts[1] instanceof ECommerceProduct);
$this->assertTrue($secondCategoryProducts[0] instanceof ECommerceProduct);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment