summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjavalizard <>2010-04-17 04:36:46 +0000
committerjavalizard <>2010-04-17 04:36:46 +0000
commit34fb3ab1cbceb2e739578398748ded5524c46ad2 (patch)
treeabf5175f9e9785ea71be1a04076f05b9fa55013e
parent0b7c1b5adb708eafd79fb77ea2e534ef158b59aa (diff)
Added Unit tests for insertBefore/After. Change code to expected behavior.
-rw-r--r--framework/Collections/TList.php6
-rw-r--r--tests/unit/Collections/TListTest.php12
2 files changed, 12 insertions, 6 deletions
diff --git a/framework/Collections/TList.php b/framework/Collections/TList.php
index bef39648..cc0eab6d 100644
--- a/framework/Collections/TList.php
+++ b/framework/Collections/TList.php
@@ -252,7 +252,8 @@ class TList extends TComponent implements IteratorAggregate,ArrayAccess,Countabl
*/
public function insertBefore($baseitem, $item)
{
- if(($index = $this->indexOf($baseitem)) == -1) return null;
+ if(($index = $this->indexOf($baseitem)) == -1)
+ throw new TInvalidDataValueException('list_item_inexistent');
$this->insertAt($index, $item);
@@ -268,7 +269,8 @@ class TList extends TComponent implements IteratorAggregate,ArrayAccess,Countabl
*/
public function insertAfter($baseitem, $item)
{
- if(($index = $this->indexOf($baseitem)) == -1) return null;
+ if(($index = $this->indexOf($baseitem)) == -1)
+ throw new TInvalidDataValueException('list_item_inexistent');
$this->insertAt($index + 1, $item);
diff --git a/tests/unit/Collections/TListTest.php b/tests/unit/Collections/TListTest.php
index 7b0c74c3..26f05e6f 100644
--- a/tests/unit/Collections/TListTest.php
+++ b/tests/unit/Collections/TListTest.php
@@ -79,7 +79,7 @@ class TListTest extends PHPUnit_Framework_TestCase {
} catch(TInvalidDataValueException $e) {
}
$this->assertEquals(2,$this->list->getCount());
- $this->list->insertBefore($this->item1,$this->item3);
+ $this->assertEquals($this->list,$this->list->insertBefore($this->item1,$this->item3));
$this->assertEquals(3,$this->list->getCount());
$this->assertEquals(0,$this->list->indexOf($this->item3));
$this->assertEquals(1,$this->list->indexOf($this->item1));
@@ -93,7 +93,7 @@ class TListTest extends PHPUnit_Framework_TestCase {
} catch(TInvalidDataValueException $e) {
}
$this->assertEquals(2,$this->list->getCount());
- $this->list->insertAfter($this->item2,$this->item3);
+ $this->assertEquals($this->list,$this->list->insertAfter($this->item2,$this->item3));
$this->assertEquals(3,$this->list->getCount());
$this->assertEquals(0,$this->list->indexOf($this->item1));
$this->assertEquals(1,$this->list->indexOf($this->item2));
@@ -104,10 +104,14 @@ class TListTest extends PHPUnit_Framework_TestCase {
$list = new TList(array(), true);
try {
$list->insertAt(1, 2);
+ self::fail('An expected TInvalidOperationException was not raised');
+ } catch(TInvalidOperationException $e) {
+ }
+ try {
+ $list->insertAt(0, 2);
+ self::fail('An expected TInvalidOperationException was not raised');
} catch(TInvalidOperationException $e) {
- return;
}
- self::fail('An expected TInvalidOperationException was not raised');
}
public function testRemove() {