-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
251 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
/** | ||
* @licence GPL-v2 | ||
*/ | ||
namespace App\Libraries\Interfaces; | ||
|
||
/** | ||
* Define an element as measurable | ||
* | ||
* @since 0.2 | ||
* @author Romain L. | ||
*/ | ||
interface IMeasurable | ||
{ | ||
/** | ||
* Return element's length | ||
* | ||
* @return int | ||
* @access public | ||
*/ | ||
public function length(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?php | ||
/** | ||
* @licence GPL-v2 | ||
*/ | ||
namespace Tests\Units\App\Libraries; | ||
|
||
use \Tests\Units\TestCase; | ||
use \App\Libraries\Collection as _Collection; | ||
|
||
/** | ||
* Unit testing on collection of displayable item | ||
* | ||
* @since 0.2 | ||
* @author Romain L. | ||
* @see \App\Libraries\Collection | ||
*/ | ||
class Collection extends TestCase | ||
{ | ||
/** | ||
* Tests constructing a collection | ||
* | ||
* @since 0.2 | ||
* @author Romain L. | ||
* @see \App\Libraries\Collection | ||
*/ | ||
public function test__construct() | ||
{ | ||
$this->mockGenerator->orphanize('__construct'); | ||
$item = new \mock\App\Item\Browser; | ||
$item->getMockController()->display = 'Rose Tyler'; | ||
|
||
$collection = new _Collection($item); | ||
|
||
$this->integer($collection->key())->isIdenticalTo(0); | ||
$this->string($collection->current()->display())->isIdenticalTo('Rose Tyler'); | ||
} | ||
|
||
/** | ||
* Tests incrementing position | ||
* | ||
* @return void | ||
* @access public | ||
*/ | ||
public function testNext() | ||
{ | ||
$this->mockGenerator->orphanize('__construct'); | ||
$item1 = new \mock\App\Item\Browser; | ||
$item1->getMockController()->display = 'Rose Tyler'; | ||
$collection = new _Collection($item1); | ||
$item2 = new \mock\App\Item\Browser; | ||
$item2->getMockController()->display = 'Martha Jones'; | ||
$collection->push($item2); | ||
|
||
$collection->next(); | ||
|
||
$this->string($collection->current()->display())->isIdenticalTo('Martha Jones'); | ||
} | ||
|
||
/** | ||
* Test rewinding | ||
* | ||
* @return void | ||
* @access public | ||
*/ | ||
public function testRewind() | ||
{ | ||
$this->mockGenerator->orphanize('__construct'); | ||
$item1 = new \mock\App\Item\Browser; | ||
$item1->getMockController()->display = 'Rose Tyler'; | ||
$collection = new _Collection($item1); | ||
$item2 = new \mock\App\Item\Browser; | ||
$item2->getMockController()->display = 'Martha Jones'; | ||
$collection->push($item2); | ||
$collection->next(); | ||
|
||
$collection->rewind(); | ||
|
||
$this->string($collection->current()->display())->isIdenticalTo('Rose Tyler'); | ||
} | ||
|
||
/** | ||
* Tests checking item existence | ||
* | ||
* @return void | ||
* @access public | ||
*/ | ||
public function testValid() | ||
{ | ||
$this->mockGenerator->orphanize('__construct'); | ||
$item = new \mock\App\Item\Browser; | ||
$item->getMockController()->display = 'Rose Tyler'; | ||
$collection = new _Collection($item); | ||
$collection->next(); | ||
|
||
$valid = $collection->valid(); | ||
|
||
$this->boolean($valid)->isFalse(); | ||
} | ||
|
||
/** | ||
* Tests poping collection | ||
* | ||
* @return void | ||
* @access public | ||
*/ | ||
public function testPop() | ||
{ | ||
$this->mockGenerator->orphanize('__construct'); | ||
$item1 = new \mock\App\Item\Browser; | ||
$item1->getMockController()->display = 'Rose Tyler'; | ||
$collection = new _Collection($item1); | ||
$item2 = new \mock\App\Item\Browser; | ||
$item2->getMockController()->display = 'Martha Jones'; | ||
$collection->push($item2); | ||
|
||
$itemX = $collection->pop(); | ||
|
||
$this->object($itemX)->isInstanceOf('\App\Item\Browser'); | ||
$this->integer($collection->length())->isIdenticalTo(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters