Skip to content

Commit

Permalink
more tests: set_join()
Browse files Browse the repository at this point in the history
  • Loading branch information
francois2metz committed Aug 24, 2009
1 parent 9f76ec0 commit 853afa8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
6 changes: 3 additions & 3 deletions orm/Morm.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class Morm
private $_foreign_values;

/**
* @access private
* @access protected
*/
private $_foreign_object;
protected $_foreign_object;

/**
* @access protected
Expand Down Expand Up @@ -948,7 +948,7 @@ public function getForeignObject ($field)
return $this->_foreign_object[$field];
}
else
throw new Exception($field.' is not a foreign key in table '.$this->_table);
throw new MormSqlException($field.' is not a foreign key in table '.$this->_table);
}

/**
Expand Down
33 changes: 29 additions & 4 deletions tests/oneToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ public function setTable($table_name)

public function setKey($key_name)
{
$this->_foreign_keys['author_id']['key'] = $key_name;
$this->_foreign_keys['author_id']['key'] = $key_name;
}

public function getForeignObjectForTesting()
{
return $this->_foreign_object;
}
}

Expand Down Expand Up @@ -116,6 +121,28 @@ public function testAnotherPolymorphism()
$this->assertEqual('John Doe', $fetch->object->name);
}

public function testSetJoin()
{
$books = new Mormons('books');
$books->set_join('authors');
foreach ($books as $book)
{
$this->assertEqual(1, count($book->getForeignObjectForTesting()));
}
}

public function testNoJoinObject()
{
$books = new Mormons('books');
foreach ($books as $book)
{
$this->assertEqual(0, count($book->getForeignObjectForTesting()));
$name = $book->authors->name;
$this->assertEqual(1, count($book->getForeignObjectForTesting()));
}

}

}

class TestOneToOneRelationsWithADifferentKeyName extends MormUnitTestCase
Expand Down Expand Up @@ -160,6 +187,4 @@ public function TestGetOneBookWithBadKeyThrowException()
$this->pass();
}
}


}
}

0 comments on commit 853afa8

Please sign in to comment.