1
0
mirror of synced 2024-12-13 14:56:01 +03:00

New test case for one-one relation fetching.

This commit is contained in:
romanb 2007-06-05 19:33:09 +00:00
parent 1e2b0bf67b
commit cab7c8ea45
4 changed files with 244 additions and 220 deletions

View File

@ -158,13 +158,12 @@ class Doctrine_CustomResultSetOrder_TestCase extends Doctrine_UnitTestCase {
switch ($category->name) { switch ($category->name) {
case 'First': case 'First':
// The first category should have 3 boards, right? // The first category should have 3 boards
// It has only 1! The other two slipped to the 2nd category!
$this->assertEqual(3, $category->Boards->count()); $this->assertEqual(3, $category->Boards->count());
break; break;
case 'Second': case 'Second':
// The second category should have 1 board, but it got 3 now // The second category should have 1 board
$this->assertEqual(1, $category->Boards->count()); $this->assertEqual(1, $category->Boards->count());
break; break;

View File

@ -1,213 +1,213 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* This software consists of voluntary contributions made by many individuals * This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
/** /**
* Doctrine_EventListener_TestCase * Doctrine_EventListener_TestCase
* *
* @package Doctrine * @package Doctrine
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
*/ */
class EventListenerTest extends Doctrine_Record { class EventListenerTest extends Doctrine_Record {
public function setTableDefinition() { public function setTableDefinition() {
$this->hasColumn("name", "string", 100); $this->hasColumn("name", "string", 100);
$this->hasColumn("password", "string", 8); $this->hasColumn("password", "string", 8);
} }
public function setUp() { public function setUp() {
$this->attribute(Doctrine::ATTR_LISTENER, new Doctrine_EventListener_AccessorInvoker()); //$this->attribute(Doctrine::ATTR_LISTENER, new Doctrine_EventListener_AccessorInvoker());
} }
public function getName($name) { public function getName($name) {
return strtoupper($name); return strtoupper($name);
} }
public function setPassword($password) { public function setPassword($password) {
return md5($password); return md5($password);
} }
} }
class Doctrine_EventListener_TestLogger implements Doctrine_Overloadable, Countable { class Doctrine_EventListener_TestLogger implements Doctrine_Overloadable, Countable {
private $messages = array(); private $messages = array();
public function __call($m, $a) { public function __call($m, $a) {
$this->messages[] = $m; $this->messages[] = $m;
} }
public function pop() { public function pop() {
return array_pop($this->messages); return array_pop($this->messages);
} }
public function clear() { public function clear() {
$this->messages = array(); $this->messages = array();
} }
public function getAll() { public function getAll() {
return $this->messages; return $this->messages;
} }
public function count() { public function count() {
return count($this->messages); return count($this->messages);
} }
} }
class Doctrine_EventListener_TestCase extends Doctrine_UnitTestCase { class Doctrine_EventListener_TestCase extends Doctrine_UnitTestCase {
private $logger; private $logger;
public function testSetListener() { public function testSetListener() {
$this->logger = new Doctrine_EventListener_TestLogger(); $this->logger = new Doctrine_EventListener_TestLogger();
$e = new EventListenerTest; $e = new EventListenerTest;
$e->getTable()->setListener($this->logger); $e->getTable()->setListener($this->logger);
$e->name = 'listener'; $e->name = 'listener';
$e->save(); $e->save();
$this->assertEqual($e->getTable()->getListener(), $this->logger); $this->assertEqual($e->getTable()->getListener(), $this->logger);
} }
public function testOnLoad() { public function testOnLoad() {
$this->logger->clear(); $this->logger->clear();
$this->assertEqual($this->connection->getTable('EventListenerTest')->getListener(), $this->logger); $this->assertEqual($this->connection->getTable('EventListenerTest')->getListener(), $this->logger);
$this->connection->clear(); $this->connection->clear();
$e = $this->connection->getTable('EventListenerTest')->find(1); $e = $this->connection->getTable('EventListenerTest')->find(1);
$this->assertEqual($e->getTable()->getListener(), $this->logger); $this->assertEqual($e->getTable()->getListener(), $this->logger);
$this->assertEqual($this->logger->pop(), 'onLoad'); $this->assertEqual($this->logger->pop(), 'onLoad');
$this->assertEqual($this->logger->pop(), 'onPreLoad'); $this->assertEqual($this->logger->pop(), 'onPreLoad');
} }
public function testOnCreate() { public function testOnCreate() {
$e = new EventListenerTest; $e = new EventListenerTest;
$e->setListener($this->logger); $e->setListener($this->logger);
$this->logger->clear(); $this->logger->clear();
$e = new EventListenerTest; $e = new EventListenerTest;
$this->assertEqual($this->logger->pop(), 'onCreate'); $this->assertEqual($this->logger->pop(), 'onCreate');
$this->assertEqual($this->logger->pop(), 'onPreCreate'); $this->assertEqual($this->logger->pop(), 'onPreCreate');
$this->assertEqual($this->logger->count(), 0); $this->assertEqual($this->logger->count(), 0);
} }
public function testOnSleepAndOnWakeUp() { public function testOnSleepAndOnWakeUp() {
$e = new EventListenerTest; $e = new EventListenerTest;
$this->logger->clear(); $this->logger->clear();
$s = serialize($e); $s = serialize($e);
$this->assertEqual($this->logger->pop(), 'onSleep'); $this->assertEqual($this->logger->pop(), 'onSleep');
$this->assertEqual($this->logger->count(), 0); $this->assertEqual($this->logger->count(), 0);
$e = unserialize($s); $e = unserialize($s);
$this->assertEqual($this->logger->pop(), 'onWakeUp'); $this->assertEqual($this->logger->pop(), 'onWakeUp');
$this->assertEqual($this->logger->count(), 0); $this->assertEqual($this->logger->count(), 0);
} }
public function testTransaction() { public function testTransaction() {
$e = new EventListenerTest(); $e = new EventListenerTest();
$e->name = "test 1"; $e->name = "test 1";
$this->logger->clear(); $this->logger->clear();
$e->save(); $e->save();
$this->assertEqual($this->logger->pop(), 'onSave'); $this->assertEqual($this->logger->pop(), 'onSave');
$this->assertEqual($this->logger->pop(), 'onInsert'); $this->assertEqual($this->logger->pop(), 'onInsert');
$this->assertEqual($this->logger->pop(), 'onPreInsert'); $this->assertEqual($this->logger->pop(), 'onPreInsert');
$this->assertEqual($this->logger->pop(), 'onPreSave'); $this->assertEqual($this->logger->pop(), 'onPreSave');
$e->name = "test 2"; $e->name = "test 2";
$e->save(); $e->save();
$this->assertEqual($this->logger->pop(), 'onSave'); $this->assertEqual($this->logger->pop(), 'onSave');
$this->assertEqual($this->logger->pop(), 'onUpdate'); $this->assertEqual($this->logger->pop(), 'onUpdate');
$this->assertEqual($this->logger->pop(), 'onPreUpdate'); $this->assertEqual($this->logger->pop(), 'onPreUpdate');
$this->assertEqual($this->logger->pop(), 'onPreSave'); $this->assertEqual($this->logger->pop(), 'onPreSave');
$this->logger->clear(); $this->logger->clear();
$e->delete(); $e->delete();
$this->assertEqual($this->logger->pop(), 'onDelete'); $this->assertEqual($this->logger->pop(), 'onDelete');
$this->assertEqual($this->logger->pop(), 'onPreDelete'); $this->assertEqual($this->logger->pop(), 'onPreDelete');
} }
public function testTransactionWithConnectionListener() { public function testTransactionWithConnectionListener() {
$e = new EventListenerTest(); $e = new EventListenerTest();
$e->getTable()->getConnection()->setListener($this->logger); $e->getTable()->getConnection()->setListener($this->logger);
$e->name = "test 2"; $e->name = "test 2";
$this->logger->clear(); $this->logger->clear();
$e->save(); $e->save();
$this->assertEqual($this->logger->pop(), 'onTransactionCommit'); $this->assertEqual($this->logger->pop(), 'onTransactionCommit');
$this->assertEqual($this->logger->pop(), 'onPreTransactionCommit'); $this->assertEqual($this->logger->pop(), 'onPreTransactionCommit');
$this->assertEqual($this->logger->pop(), 'onSave'); $this->assertEqual($this->logger->pop(), 'onSave');
$this->assertEqual($this->logger->pop(), 'onInsert'); $this->assertEqual($this->logger->pop(), 'onInsert');
$this->assertEqual($this->logger->pop(), 'onPreInsert'); $this->assertEqual($this->logger->pop(), 'onPreInsert');
$this->assertEqual($this->logger->pop(), 'onPreSave'); $this->assertEqual($this->logger->pop(), 'onPreSave');
$this->assertEqual($this->logger->pop(), 'onTransactionBegin'); $this->assertEqual($this->logger->pop(), 'onTransactionBegin');
$this->assertEqual($this->logger->pop(), 'onPreTransactionBegin'); $this->assertEqual($this->logger->pop(), 'onPreTransactionBegin');
$e->name = "test 1"; $e->name = "test 1";
$e->save(); $e->save();
$this->assertEqual($this->logger->pop(), 'onTransactionCommit'); $this->assertEqual($this->logger->pop(), 'onTransactionCommit');
$this->assertEqual($this->logger->pop(), 'onPreTransactionCommit'); $this->assertEqual($this->logger->pop(), 'onPreTransactionCommit');
$this->assertEqual($this->logger->pop(), 'onSave'); $this->assertEqual($this->logger->pop(), 'onSave');
$this->assertEqual($this->logger->pop(), 'onUpdate'); $this->assertEqual($this->logger->pop(), 'onUpdate');
$this->assertEqual($this->logger->pop(), 'onPreUpdate'); $this->assertEqual($this->logger->pop(), 'onPreUpdate');
$this->assertEqual($this->logger->pop(), 'onPreSave'); $this->assertEqual($this->logger->pop(), 'onPreSave');
$this->assertEqual($this->logger->pop(), 'onTransactionBegin'); $this->assertEqual($this->logger->pop(), 'onTransactionBegin');
$this->assertEqual($this->logger->pop(), 'onPreTransactionBegin'); $this->assertEqual($this->logger->pop(), 'onPreTransactionBegin');
$this->logger->clear(); $this->logger->clear();
$e->delete(); $e->delete();
$this->assertEqual($this->logger->pop(), 'onTransactionCommit'); $this->assertEqual($this->logger->pop(), 'onTransactionCommit');
$this->assertEqual($this->logger->pop(), 'onPreTransactionCommit'); $this->assertEqual($this->logger->pop(), 'onPreTransactionCommit');
$this->assertEqual($this->logger->pop(), 'onDelete'); $this->assertEqual($this->logger->pop(), 'onDelete');
$this->assertEqual($this->logger->pop(), 'onPreDelete'); $this->assertEqual($this->logger->pop(), 'onPreDelete');
$this->assertEqual($this->logger->pop(), 'onTransactionBegin'); $this->assertEqual($this->logger->pop(), 'onTransactionBegin');
$this->assertEqual($this->logger->pop(), 'onPreTransactionBegin'); $this->assertEqual($this->logger->pop(), 'onPreTransactionBegin');
$this->connection->setListener(new Doctrine_EventListener()); $this->connection->setListener(new Doctrine_EventListener());
} }
public function prepareData() { } public function prepareData() { }
public function prepareTables() { public function prepareTables() {
$this->tables = array('EventListenerTest'); $this->tables = array('EventListenerTest');
parent::prepareTables(); parent::prepareTables();
} }
} }
?> ?>

View File

@ -695,9 +695,9 @@ class QueryTest_Entry extends Doctrine_Record
*/ */
public function setTableDefinition() public function setTableDefinition()
{ {
$this->hasColumn('authorId as authorId', 'integer', 4, $this->hasColumn('authorId', 'integer', 4,
array('notnull')); array('notnull'));
$this->hasColumn('date as date', 'integer', 4, $this->hasColumn('date', 'integer', 4,
array('notnull')); array('notnull'));
} }
@ -716,7 +716,32 @@ class QueryTest_User extends Doctrine_Record
public function setTableDefinition() public function setTableDefinition()
{ {
$this->hasColumn('username as username', 'string', 50, $this->hasColumn('username as username', 'string', 50,
array('notnull', 'unique')); array('notnull'));
$this->hasColumn('visibleRankId', 'integer', 4);
}
/**
* Runtime definition of the relationships to other entities.
*/
public function setUp()
{
$this->hasOne('QueryTest_Rank as visibleRank', 'QueryTest_User.visibleRankId');
}
}
class QueryTest_Rank extends Doctrine_Record
{
/**
* Initializes the table definition.
*/
public function setTableDefinition()
{
$this->hasColumn('title as title', 'string', 100,
array('notnull'));
$this->hasColumn('color as color', 'string', 20,
array('notnull', 'regexp' => '/^[a-zA-Z\-]{3,}|#[0-9a-fA-F]{6}$/D'));
$this->hasColumn('icon as icon', 'string', 50,
array('notnull', 'default' => ' ', 'regexp' => '/^[a-zA-Z0-9_\-]+\.(jpg|gif|png)$/D'));
} }
} }

View File

@ -222,7 +222,7 @@ $test->addTestCase(new Doctrine_ColumnAggregationInheritance_TestCase());
$test->addTestCase(new Doctrine_ColumnAlias_TestCase()); $test->addTestCase(new Doctrine_ColumnAlias_TestCase());
$test->addTestCase(new Doctrine_Query_OneToOneFetching_TestCase());
$test->addTestCase(new Doctrine_Cache_Apc_TestCase()); $test->addTestCase(new Doctrine_Cache_Apc_TestCase());
$test->addTestCase(new Doctrine_Cache_Memcache_TestCase()); $test->addTestCase(new Doctrine_Cache_Memcache_TestCase());