Skip to content

Commit

Permalink
add moveObject
Browse files Browse the repository at this point in the history
  • Loading branch information
anton committed Jun 4, 2014
1 parent 2320790 commit f4d07d8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Kachit/Collection/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public function jsonSerialize() {
return $this->toArray();
}


/**
* To array
*
Expand Down Expand Up @@ -110,13 +109,25 @@ public function getObject($index = null) {
/**
* Get cloned object
*
* @param $index
* @param mixed $index
* @return ItemInterface
*/
public function cloneObject($index) {
return clone $this->getObject($index);
}

/**
* Move object from collection
*
* @param mixed $index
* @return ItemInterface
*/
public function moveObject($index) {
$object = $this->getObject($index);
$this->deleteObject($index);
return $object;
}

/**
* Get first object
*
Expand Down
12 changes: 12 additions & 0 deletions tests/Kachit/Collection/Test/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ public function testGetFirstObject() {
$this->assertEquals(1, $result->getId());
}

/**
* RTFN
*/
public function testMoveObject() {
$result = $this->testable->moveObject(1);
$this->assertNotEmpty($result);
$this->assertTrue(is_object($result));
$this->assertInstanceOf('Kachit\Collection\ItemInterface', $result);
$this->assertEquals(1, $result->getId());
$this->assertEquals(9, $this->testable->count());
}

/**
* RTFN
*/
Expand Down

0 comments on commit f4d07d8

Please sign in to comment.