mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-02-24 17:52:25 +01:00
71 lines
1.9 KiB
PHP
71 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace DesignPatterns\Tests\Strategy;
|
|
|
|
use DesignPatterns\Strategy\DateComparator;
|
|
use DesignPatterns\Strategy\IdComparator;
|
|
use DesignPatterns\Strategy\ObjectCollection;
|
|
use DesignPatterns\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);
|
|
}
|
|
}
|