create a Test folder for each pattern

This commit is contained in:
Antonio Spinelli
2014-05-05 12:00:18 -03:00
parent 14a9dfe7cf
commit 0c774a89e4
31 changed files with 43 additions and 36 deletions

View File

@@ -0,0 +1,70 @@
<?php
namespace DesignPatterns\Behavioral\Strategy\Tests;
use DesignPatterns\Behavioral\Strategy\DateComparator;
use DesignPatterns\Behavioral\Strategy\IdComparator;
use DesignPatterns\Behavioral\Strategy\ObjectCollection;
use DesignPatterns\Behavioral\Strategy\Strategy;
/**
* Tests for Static Factory pattern
*/
class StrategyTest extends \PHPUnit_Framework_TestCase
{
public function getIdCollection()
{
return array(
array(
array(array('id' => 2), array('id' => 1), array('id' => 3)),
array('id' => 1)
),
array(
array(array('id' => 3), array('id' => 2), array('id' => 1)),
array('id' => 1)
),
);
}
public function getDateCollection()
{
return array(
array(
array(array('date' => '2014-03-03'), array('date' => '2015-03-02'), array('date' => '2013-03-01')),
array('date' => '2013-03-01')
),
array(
array(array('date' => '2014-02-03'), array('date' => '2013-02-01'), array('date' => '2015-02-02')),
array('date' => '2013-02-01')
),
);
}
/**
* @dataProvider getIdCollection
*/
public function testIdComparator($collection, $expected)
{
$obj = new ObjectCollection($collection);
$obj->setComparator(new IdComparator());
$elements = $obj->sort();
$firstElement = array_shift($elements);
$this->assertEquals($expected, $firstElement);
}
/**
* @dataProvider getDateCollection
*/
public function testDateComparator($collection, $expected)
{
$obj = new ObjectCollection($collection);
$obj->setComparator(new DateComparator());
$elements = $obj->sort();
$firstElement = array_shift($elements);
$this->assertEquals($expected, $firstElement);
}
}