Skip to content

Commit

Permalink
Tests: ensure models contain only one record per file
Browse files Browse the repository at this point in the history
  • Loading branch information
thePanz committed Jun 26, 2024
1 parent 5ef8287 commit f47a790
Show file tree
Hide file tree
Showing 20 changed files with 136 additions and 127 deletions.
26 changes: 0 additions & 26 deletions tests/MigrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,29 +128,3 @@ public function testMigrationClassNameInflected()
}
}
}

class MigrationPhonenumber extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('user_id', 'integer');
$this->hasColumn('phonenumber', 'string', 255);
}
}

class MigrationUser extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('username', 'string', 255);
$this->hasColumn('password', 'string', 255);
}
}

class MigrationProfile extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('name', 'string', 255);
}
}
32 changes: 16 additions & 16 deletions tests/Relation/OneToOneTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
* @since 1.0
* @version $Revision$
*/
class Doctrine_Relation_OneToOne_TestCase extends Doctrine_UnitTestCase
class Doctrine_Relation_OneToOne_TestCase extends Doctrine_UnitTestCase
{
public function prepareData()
public function prepareData()
{ }
public function prepareTables()
{
$this->tables = array('gnatUser','gnatEmail','Email','Entity','Record_City', 'Record_Country', 'SelfRefTest');
public function prepareTables()
{
$this->tables = array('GnatUser','GnatEmail','Email','Entity','Record_City', 'Record_Country', 'SelfRefTest');

parent::prepareTables();
}

Expand All @@ -46,27 +46,27 @@ public function testOneToOneAggregateRelationWithAliasesIsSupported()
$city = new Record_City();
$country = $city->Country;

$this->assertTrue($country instanceof Record_Country);
$this->assertTrue($country instanceof Record_Country);
}

public function testSelfReferentialOneToOneRelationsAreSupported()
{
$ref = new SelfRefTest();

$rel = $ref->getTable()->getRelation('createdBy');

$this->assertEqual($rel->getForeign(), 'id');
$this->assertEqual($rel->getLocal(), 'created_by');

$ref->name = 'ref 1';
$ref->createdBy->name = 'ref 2';

$ref->save();
}
public function testSelfReferentialOneToOneRelationsAreSupported2()
{
$this->connection->clear();

$ref = $this->conn->queryOne("FROM SelfRefTest s WHERE s.name = 'ref 1'");
$this->assertEqual($ref->name, 'ref 1');
$this->assertEqual($ref->createdBy->name, 'ref 2');
Expand All @@ -88,14 +88,14 @@ public function testUnsetRelation()

public function testSavingRelatedObjects()
{
$user = new gnatUser();
$user = new GnatUser();
$user->name = 'test';
$email = new gnatEmail();
$email = new GnatEmail();
$email->address = '[email protected]';
$user->Email = $email;
$user->save();
$this->assertTrue($user->Email instanceOf gnatEmail);
$this->assertTrue($user->Email instanceOf GnatEmail);
$this->assertEqual($user->foreign_id, $user->Email->id);

}
}
20 changes: 0 additions & 20 deletions tests/models/Blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,3 @@ public function setUp()
$this->actAs('Taggable');
}
}
class Taggable extends Doctrine_Template
{
public function setUp()
{
//$this->hasMany('[Component]TagTemplate as Tag');
}
}
class TagTemplate extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('name', 'string', 100);
$this->hasColumn('description', 'string');
}

public function setUp()
{
//$this->hasOne('[Component]', array('onDelete' => 'CASCADE'));
}
}
4 changes: 1 addition & 3 deletions tests/models/gnatEmail.php → tests/models/GnatEmail.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?php
class gnatEmail extends Doctrine_Record
class GnatEmail extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('address', 'string', 150);
}


}
15 changes: 6 additions & 9 deletions tests/models/gnatUser.php → tests/models/GnatUser.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
<?php
class gnatUserTable { }

class gnatUser extends Doctrine_Record
<?php
class GnatUser extends Doctrine_Record
{
public function setTableDefinition()
public function setTableDefinition()
{
$this->hasColumn('name', 'string', 150);
$this->hasColumn('foreign_id', 'integer', 10, array ('unique' => true,));
}

public function setUp()
{
parent::setUp();
$this->hasOne('gnatEmail as Email', array('local'=> 'foreign_id', 'foreign'=>'id', 'onDelete'=>'CASCADE'));
$this->hasOne('GnatEmail as Email', array('local'=> 'foreign_id', 'foreign'=>'id', 'onDelete'=>'CASCADE'));
}

}

}
3 changes: 3 additions & 0 deletions tests/models/GnatUserTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

class GnatUserTable { }
4 changes: 0 additions & 4 deletions tests/models/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

require_once('Entity.php');

// grouptable doesn't extend Doctrine_Table -> Doctrine_Connection
// won't initialize grouptable when Doctrine_Connection->getTable('Group') is called
class GroupTable { }

class Group extends Entity
{
public function setUp()
Expand Down
5 changes: 5 additions & 0 deletions tests/models/GroupTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

// grouptable doesn't extend Doctrine_Table -> Doctrine_Connection
// won't initialize grouptable when Doctrine_Connection->getTable('Group') is called
class GroupTable { }
10 changes: 10 additions & 0 deletions tests/models/MigrationPhonenumber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

class MigrationPhonenumber extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('user_id', 'integer');
$this->hasColumn('phonenumber', 'string', 255);
}
}
9 changes: 9 additions & 0 deletions tests/models/MigrationProfile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

class MigrationProfile extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('name', 'string', 255);
}
}
10 changes: 10 additions & 0 deletions tests/models/MigrationUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

class MigrationUser extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('username', 'string', 255);
$this->hasColumn('password', 'string', 255);
}
}
16 changes: 0 additions & 16 deletions tests/models/RelationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,3 @@ public function setTableDefinition()
$this->hasColumn('parent_id', 'integer');
}
}

class RelationTestChild extends RelationTest
{
public function setUp()
{
$this->hasOne('RelationTest as Parent', array(
'local' => 'parent_id',
'foreign' => 'id',
'onDelete' => 'CASCADE',
));
$this->hasMany('RelationTestChild as Children', array(
'local' => 'id',
'foreign' => 'parent_id',
));
}
}
19 changes: 19 additions & 0 deletions tests/models/RelationTestChild.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

require_once('RelationTest.php');

class RelationTestChild extends RelationTest
{
public function setUp()
{
$this->hasOne('RelationTest as Parent', array(
'local' => 'parent_id',
'foreign' => 'id',
'onDelete' => 'CASCADE',
));
$this->hasMany('RelationTestChild as Children', array(
'local' => 'id',
'foreign' => 'parent_id',
));
}
}
14 changes: 14 additions & 0 deletions tests/models/TagTemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
class TagTemplate extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('name', 'string', 100);
$this->hasColumn('description', 'string');
}

public function setUp()
{
//$this->hasOne('[Component]', array('onDelete' => 'CASCADE'));
}
}
8 changes: 8 additions & 0 deletions tests/models/Taggable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
class Taggable extends Doctrine_Template
{
public function setUp()
{
//$this->hasMany('[Component]TagTemplate as Tag');
}
}
4 changes: 0 additions & 4 deletions tests/models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

require_once('Entity.php');

// UserTable doesn't extend Doctrine_Table -> Doctrine_Connection
// won't initialize grouptable when Doctrine_Connection->getTable('User') is called
class UserTable extends Doctrine_Table { }

class User extends Entity
{
public function setUp()
Expand Down
5 changes: 5 additions & 0 deletions tests/models/UserTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

// UserTable doesn't extend Doctrine_Table -> Doctrine_Connection
// won't initialize grouptable when Doctrine_Connection->getTable('User') is called
class UserTable extends Doctrine_Table { }
29 changes: 0 additions & 29 deletions tests/models/VersioningTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,3 @@ public function setUp()
$this->actAs('Versionable');
}
}

class VersioningTest2 extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('name', 'string');
$this->hasColumn('version', 'integer');
}
public function setUp()
{
$this->actAs('Versionable', array('auditLog' => false));
}
}

class VersioningTest3 extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('name', 'string');
$this->hasColumn('version', 'integer');
}
public function setUp()
{

$this->actAs('Versionable', array('tableName' => 'tbl_prefix_comments_version',
'className' => 'VersioningTestClass'));

}
}
13 changes: 13 additions & 0 deletions tests/models/VersioningTest2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
class VersioningTest2 extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('name', 'string');
$this->hasColumn('version', 'integer');
}
public function setUp()
{
$this->actAs('Versionable', array('auditLog' => false));
}
}
17 changes: 17 additions & 0 deletions tests/models/VersioningTest3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

class VersioningTest3 extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('name', 'string');
$this->hasColumn('version', 'integer');
}
public function setUp()
{
$this->actAs('Versionable', array(
'tableName' => 'tbl_prefix_comments_version',
'className' => 'VersioningTestClass'
));
}
}

0 comments on commit f47a790

Please sign in to comment.