From fa3a2e469db519571fa7dc13bc832e7de1f8057f Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Wed, 20 Mar 2013 10:46:37 +0100 Subject: throw exceptions when attributes dont exist --- tests/db/EntityTest.php | 52 ++++++++++++++++++++++++++++++--------------- tests/db/ItemMapperTest.php | 6 +++--- tests/db/ItemTest.php | 43 ++++++------------------------------- 3 files changed, 45 insertions(+), 56 deletions(-) (limited to 'tests') diff --git a/tests/db/EntityTest.php b/tests/db/EntityTest.php index 793ca8ded..9002f5f5e 100644 --- a/tests/db/EntityTest.php +++ b/tests/db/EntityTest.php @@ -36,8 +36,10 @@ class TestEntity extends Entity { class EntityTest extends \PHPUnit_Framework_TestCase { - protected function setUp(){ + private $entity; + protected function setUp(){ + $this->entity = new TestEntity(); } @@ -46,54 +48,70 @@ class EntityTest extends \PHPUnit_Framework_TestCase { 'pre_name' => 'john', 'email' => 'john@something.com' ); - $entity = new TestEntity(); + $this->entity = new TestEntity(); - $entity->fromRow($row); + $this->entity->fromRow($row); - $this->assertEquals($row['pre_name'], $entity->getPreName()); - $this->assertEquals($row['email'], $entity->getEmail()); + $this->assertEquals($row['pre_name'], $this->entity->getPreName()); + $this->assertEquals($row['email'], $this->entity->getEmail()); } public function testGetSetId(){ $id = 3; - $entity = new TestEntity(); - $entity->setId(3); + $this->entity->setId(3); - $this->assertEquals($id, $entity->getId()); + $this->assertEquals($id, $this->entity->getId()); } public function testColumnToPropertyNoReplacement(){ $column = 'my'; - $entity = new TestEntity(); $this->assertEquals('my', - $entity->columnToProperty($column)); + $this->entity->columnToProperty($column)); } public function testColumnToProperty(){ $column = 'my_attribute'; - $entity = new TestEntity(); $this->assertEquals('myAttribute', - $entity->columnToProperty($column)); + $this->entity->columnToProperty($column)); } public function testPropertyToColumnNoReplacement(){ $property = 'my'; - $entity = new TestEntity(); $this->assertEquals('my', - $entity->propertyToColumn($property)); + $this->entity->propertyToColumn($property)); } public function testSetterMarksFieldUpdated(){ $id = 3; - $entity = new TestEntity(); - $entity->setId(3); + $this->entity->setId(3); + + $this->assertContains('id', $this->entity->getUpdatedFields()); + } + + + public function testCallShouldOnlyWorkForGetterSetter(){ + $this->setExpectedException('\BadFunctionCallException'); + + $this->entity->something(); + } + + + public function testGetterShouldFailIfAttributeNotDefined(){ + $this->setExpectedException('\BadFunctionCallException'); + + $this->entity->getTest(); + } + + + public function testSetterShouldFailIfAttributeNotDefined(){ + $this->setExpectedException('\BadFunctionCallException'); - $this->assertContains('id', $entity->getUpdatedFields()); + $this->entity->setTest(); } } \ No newline at end of file diff --git a/tests/db/ItemMapperTest.php b/tests/db/ItemMapperTest.php index ab7cfa043..40ff691b6 100644 --- a/tests/db/ItemMapperTest.php +++ b/tests/db/ItemMapperTest.php @@ -59,9 +59,9 @@ class Test extends \OCA\AppFramework\Utility\MapperTestUtility { array('test' => 1), array('test' => 2) ); - $sql = 'SELECT * FROM `*PREFIX*news_items` - WHERE user_id = ? - AND feed_id = ?'; + $sql = 'SELECT * FROM `*PREFIX*news_items` ' . + 'WHERE user_id = ? ' . + 'AND feed_id = ?'; $this->setMapperResult($sql, array($feedId, $userId), $rows); diff --git a/tests/db/ItemTest.php b/tests/db/ItemTest.php index 35eb2bec4..a590856c4 100644 --- a/tests/db/ItemTest.php +++ b/tests/db/ItemTest.php @@ -30,46 +30,17 @@ require_once(__DIR__ . "/../classloader.php"); class ItemTest extends \PHPUnit_Framework_TestCase { + private $item; - protected function assertSetterGetter($name){ - $value = 'value'; - - $item = new Item(); - $setMethod = 'set' . $name; - $getMethod = 'get' . $name; - $item->$setMethod($value); - - $this->assertEquals($value, $item->$getMethod()); - } - - - public function testGetUrl(){ - $this->assertSetterGetter('Url'); - } - - - public function testSetFeedId(){ - $this->assertSetterGetter('FeedId'); - } - - - public function testSetGUID(){ - $this->assertSetterGetter('GUID'); - } - - - public function testSetStatus(){ - $this->assertSetterGetter('Status'); - } - - - public function testSetTitle(){ - $this->assertSetterGetter('Title'); + protected function setUp(){ + $this->item = new Item(); + $this->item->setStatus(0); } + public function testSetRead(){ + $this->item->setRead(); - public function testSetFeedTitle(){ - $this->assertSetterGetter('FeedTitle'); + $this->assertTrue($this->item->isRead()); } } \ No newline at end of file -- cgit v1.2.3