1
0
mirror of synced 2024-12-13 22:56:04 +03:00
This commit is contained in:
zYne 2007-05-27 18:56:54 +00:00
parent fa11260e75
commit 8386d6915e
9 changed files with 160 additions and 64 deletions

48
tests/NewCoreTestCase.php Normal file
View File

@ -0,0 +1,48 @@
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_NewCore_TestCase
*
* @package Doctrine
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
*/
class Doctrine_NewCore_TestCase extends Doctrine_UnitTestCase
{
public function testFromParser()
{
$q = new Doctrine_Query();
$q->load('User u', true);
$this->assertEqual($q->getQueryPart('from'), array('entity e'));
$this->assertEqual(count($q->getAliasMap()), 1);
$q->load('u.Phonenumber p', false);
$this->assertEqual($q->getQueryPart('from'), array('entity e', 'LEFT JOIN phonenumber p ON e.id = p.entity_id'));
}
}

View File

@ -32,24 +32,12 @@
*/
class Doctrine_Query_Cache_TestCase extends Doctrine_UnitTestCase
{
public function testParserCacheAddsQueriesToCache()
{
$q = new Doctrine_Query();
$cache = new Doctrine_Cache_Array();
$q->setOption('parserCache', $cache);
$q->select('u.name')->from('User u');
$q->getQuery();
$this->assertEqual($cache->count(), 1);
}
public function testResultSetCacheAddsResultSetsIntoCache()
{
$q = new Doctrine_Query();
$cache = new Doctrine_Cache_Array();
$q->setOption('resultSetCache', $cache);
$q->setCache($cache);
$q->select('u.name')->from('User u');
$coll = $q->execute();
@ -63,12 +51,12 @@ class Doctrine_Query_Cache_TestCase extends Doctrine_UnitTestCase
$this->assertTrue($coll instanceof Doctrine_Collection);
$this->assertEqual($coll->count(), 8);
}
public function testResultSetCacheAddsResultSetsIntoCache2()
public function testResultSetCacheSupportsQueriesWithJoins()
{
$q = new Doctrine_Query();
$cache = new Doctrine_Cache_Array();
$q->setOption('resultSetCache', $cache);
$q->setCache($cache);
$q->select('u.name')->from('User u')->leftJoin('u.Phonenumber p');
$coll = $q->execute();
@ -82,4 +70,5 @@ class Doctrine_Query_Cache_TestCase extends Doctrine_UnitTestCase
$this->assertTrue($coll instanceof Doctrine_Collection);
$this->assertEqual($coll->count(), 8);
}
}

View File

@ -0,0 +1,35 @@
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Record_Filter_TestCase
*
* @package Doctrine
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
*/
class Doctrine_Record_Filter_TestCase extends Doctrine_UnitTestCase
{
}

View File

@ -122,16 +122,17 @@ class Doctrine_Relation_ManyToMany_TestCase extends Doctrine_UnitTestCase {
}
$this->assertEqual($rel->getForeign(), 'oid');
}
/**
public function testManyToManyRelationFetchingWithAliasesAndCustomPKs() {
$q = new Doctrine_Query();
try {
$q->from('M2MTest2 m LEFT JOIN m.RTC5');
$this->pass();
} catch(Doctrine_Exception $e) {
$this->fail();
}
try {
$q->execute();
$this->pass();
@ -139,7 +140,7 @@ class Doctrine_Relation_ManyToMany_TestCase extends Doctrine_UnitTestCase {
$this->fail();
}
}
*/
public function testManyToManyRelationFetchingWithAliasesAndCustomPKs2() {
$q = new Doctrine_Query();

View File

@ -195,4 +195,6 @@ class Doctrine_Relation_Parser_TestCase extends Doctrine_UnitTestCase
$rel = $r->getRelation('EntityReference');
$this->assertTrue($rel instanceof Doctrine_Relation_ForeignKey);
}
// TODO: BETTER ASSOCIATION TABLE GUESSING
}

View File

@ -231,7 +231,9 @@ class Doctrine_UnitTestCase extends UnitTestCase {
if ( ! $this->init) {
$this->init();
}
$this->objTable->clear();
if (isset($this->objTable)) {
$this->objTable->clear();
}
$this->init = true;
}

View File

@ -4,7 +4,9 @@ class Entity extends Doctrine_Record {
$this->ownsOne('Email', 'Entity.email_id');
$this->ownsMany('Phonenumber', 'Phonenumber.entity_id');
$this->ownsOne('Account', 'Account.entity_id');
$this->hasMany('Entity', array('local' => 'entity1', 'foreign' => 'entity2'));
$this->hasMany('Entity', array('local' => 'entity1',
'refClass' => 'EntityReference',
'foreign' => 'entity2'));
}
public function setTableDefinition() {
$this->hasColumn('id', 'integer',20, 'autoincrement|primary');
@ -43,7 +45,7 @@ class Account extends Doctrine_Record {
class EntityAddress extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn('entity_id', 'integer');
$this->hasColumn('user_id', 'integer');
$this->hasColumn('address_id', 'integer');
}
}
@ -617,7 +619,7 @@ class ValidatorTest_Person extends Doctrine_Record {
class ValidatorTest_FootballPlayer extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn('person_id', 'string', 255, 'primary');
$this->hasColumn('person_id', 'string', 255);
$this->hasColumn('team_name', 'string', 255);
$this->hasColumn('goals_count', 'integer', 4);
}

View File

@ -60,7 +60,7 @@ $test = new GroupTest('Doctrine Framework Unit Tests');
// DATABASE ABSTRACTION tests
/**
// Connection drivers (not yet fully tested)
$test->addTestCase(new Doctrine_Connection_Pgsql_TestCase());
$test->addTestCase(new Doctrine_Connection_Oracle_TestCase());
@ -138,7 +138,7 @@ $test->addTestCase(new Doctrine_Expression_Oracle_TestCase());
$test->addTestCase(new Doctrine_Expression_Sqlite_TestCase());
// Core
*/
$test->addTestCase(new Doctrine_Access_TestCase());
//$test->addTestCase(new Doctrine_Configurable_TestCase());
@ -150,15 +150,16 @@ $test->addTestCase(new Doctrine_Table_TestCase());
$test->addTestCase(new Doctrine_UnitOfWork_TestCase());
$test->addTestCase(new Doctrine_Connection_Transaction_TestCase());
$test->addTestCase(new Doctrine_Collection_TestCase());
//$test->addTestCase(new Doctrine_Collection_TestCase());
// Relation handling
$test->addTestCase(new Doctrine_TreeStructure_TestCase());
$test->addTestCase(new Doctrine_Relation_TestCase());
$test->addTestCase(new Doctrine_Relation_Access_TestCase());
$test->addTestCase(new Doctrine_Relation_ManyToMany_TestCase());
//$test->addTestCase(new Doctrine_Relation_Access_TestCase());
//$test->addTestCase(new Doctrine_Relation_ManyToMany_TestCase());
$test->addTestCase(new Doctrine_Relation_OneToOne_TestCase());
$test->addTestCase(new Doctrine_Relation_Parser_TestCase());
// Datatypes
$test->addTestCase(new Doctrine_Enum_TestCase());
@ -167,9 +168,9 @@ $test->addTestCase(new Doctrine_Boolean_TestCase());
// Utility components
$test->addTestCase(new Doctrine_PessimisticLocking_TestCase());
//$test->addTestCase(new Doctrine_PessimisticLocking_TestCase());
$test->addTestCase(new Doctrine_RawSql_TestCase());
$test->addTestCase(new Doctrine_View_TestCase());
$test->addTestCase(new Doctrine_Validator_TestCase());
@ -185,67 +186,87 @@ $test->addTestCase(new Doctrine_Db_Profiler_TestCase());
$test->addTestCase(new Doctrine_EventListener_TestCase());
$test->addTestCase(new Doctrine_EventListener_Chain_TestCase());
// Record
$test->addTestCase(new Doctrine_Record_TestCase());
$test->addTestCase(new Doctrine_Record_State_TestCase());
//$test->addTestCase(new Doctrine_Record_Filter_TestCase());
// Old test cases (should be removed)
$test->addTestCase(new Doctrine_Record_Filter_TestCase());
$test->addTestCase(new Doctrine_SchemaTestCase());
$test->addTestCase(new Doctrine_BatchIterator_TestCase());
$test->addTestCase(new Doctrine_Query_Condition_TestCase());
$test->addTestCase(new Doctrine_CustomPrimaryKey_TestCase());
$test->addTestCase(new Doctrine_CustomResultSetOrderTestCase());
//$test->addTestCase(new Doctrine_Collection_Offset_TestCase());
// Query tests
$test->addTestCase(new Doctrine_Query_MultiJoin_TestCase());
$test->addTestCase(new Doctrine_Query_ReferenceModel_TestCase());
$test->addTestCase(new Doctrine_Query_ComponentAlias_TestCase());
$test->addTestCase(new Doctrine_Query_TestCase());
$test->addTestCase(new Doctrine_Query_ShortAliases_TestCase());
$test->addTestCase(new Doctrine_Query_Delete_TestCase());
$test->addTestCase(new Doctrine_Query_Where_TestCase());
$test->addTestCase(new Doctrine_Query_Limit_TestCase());
$test->addTestCase(new Doctrine_Query_IdentifierQuoting_TestCase());
$test->addTestCase(new Doctrine_Query_Update_TestCase());
$test->addTestCase(new Doctrine_Query_AggregateValue_TestCase());
$test->addTestCase(new Doctrine_Query_Select_TestCase());
$test->addTestCase(new Doctrine_Query_Expression_TestCase());
$test->addTestCase(new Doctrine_Query_Having_TestCase());
$test->addTestCase(new Doctrine_Query_From_TestCase());
$test->addTestCase(new Doctrine_Query_JoinCondition_TestCase());
$test->addTestCase(new Doctrine_ColumnAlias_TestCase());
$test->addTestCase(new Doctrine_ColumnAggregationInheritance_TestCase());
$test->addTestCase(new Doctrine_ColumnAlias_TestCase());
$test->addTestCase(new Doctrine_Query_Join_TestCase());
$test->addTestCase(new Doctrine_Query_Orderby_TestCase());
$test->addTestCase(new Doctrine_Cache_TestCase());
$test->addTestCase(new Doctrine_Cache_Apc_TestCase());
$test->addTestCase(new Doctrine_Cache_Memcache_TestCase());
$test->addTestCase(new Doctrine_Cache_Sqlite_TestCase());
$test->addTestCase(new Doctrine_Query_Check_TestCase());
$test->addTestCase(new Doctrine_Query_Limit_TestCase());
$test->addTestCase(new Doctrine_Query_IdentifierQuoting_TestCase());
$test->addTestCase(new Doctrine_Query_Update_TestCase());
$test->addTestCase(new Doctrine_Query_Delete_TestCase());
$test->addTestCase(new Doctrine_Query_JoinCondition_TestCase());
$test->addTestCase(new Doctrine_Query_Join_TestCase());
$test->addTestCase(new Doctrine_Query_Having_TestCase());
$test->addTestCase(new Doctrine_Query_Where_TestCase());
$test->addTestCase(new Doctrine_RawSql_TestCase());
$test->addTestCase(new Doctrine_Query_Orderby_TestCase());
$test->addTestCase(new Doctrine_Query_Subquery_TestCase());
$test->addTestCase(new Doctrine_Query_AggregateValue_TestCase());
$test->addTestCase(new Doctrine_Query_Select_TestCase());
$test->addTestCase(new Doctrine_Query_From_TestCase());
$test->addTestCase(new Doctrine_NewCore_TestCase());
$test->addTestCase(new Doctrine_Tokenizer_TestCase());
$test->addTestCase(new Doctrine_Collection_Snapshot_TestCase());
// Record
$test->addTestCase(new Doctrine_Record_TestCase());
$test->addTestCase(new Doctrine_Record_State_TestCase());
$test->addTestCase(new Doctrine_Query_Cache_TestCase());
// Cache tests
//$test->addTestCase(new Doctrine_Cache_Query_SqliteTestCase());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
//$test->addTestCase(new Doctrine_Collection_Offset_TestCase());
//$test->addTestCase(new Doctrine_BatchIterator_TestCase());
//$test->addTestCase(new Doctrine_Hydrate_TestCase());
//$test->addTestCase(new Doctrine_Cache_TestCase());
//$test->addTestCase(new Doctrine_Query_TestCase());
class MyReporter extends HtmlReporter {
public function paintHeader() {}

View File

@ -13,7 +13,7 @@ print "<pre>";
$manager = Doctrine_Manager::getInstance();
$dbh = Doctrine_Db::getConnection('sqlite::memory:');
$conn = $manager->openConnection($dbh);
/**
$user = new User();
$user->name = 'zYne';
$user->Phonenumber[0]->phonenumber = '123 123';
@ -27,16 +27,12 @@ $city->District->name = 'District 1';
if ($city->District === $city->district_id) {
print 'case 2 works\n';
}
*/
$c = new Record_Country();
$c->name = 'Some country';
$c->City[0]->name = 'City 1';
$c->City[0]->District->name = 'District 1';
$city = $c->City[0];
$city->name = 'City 1';
$city->District->name = 'District 1';
print $c->City[0]->District . "\n";
print $c->City[0]->get('district_id'). "\n";
if ($c->City[0]->get('district_id') == $c->City[0]->District) {
print "case 3 works!\n";
}
$c->save();