|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace DesignPatterns\Tests\Strategy; |
| 4 | + |
| 5 | +use DesignPatterns\Strategy\DateComparator; |
| 6 | +use DesignPatterns\Strategy\IdComparator; |
| 7 | +use DesignPatterns\Strategy\ObjectCollection; |
| 8 | +use DesignPatterns\Strategy\Strategy; |
| 9 | + |
| 10 | +/** |
| 11 | + * Tests for Static Factory pattern |
| 12 | +
|
| 13 | + */ |
| 14 | +class StrategyTest extends \PHPUnit_Framework_TestCase |
| 15 | +{ |
| 16 | + |
| 17 | + public function getIdCollection() |
| 18 | + { |
| 19 | + return array( |
| 20 | + array( |
| 21 | + array(array('id' => 2), array('id' => 1), array('id' => 3)), |
| 22 | + array('id' => 1) |
| 23 | + ), |
| 24 | + array( |
| 25 | + array(array('id' => 3), array('id' => 2), array('id' => 1)), |
| 26 | + array('id' => 1) |
| 27 | + ), |
| 28 | + ); |
| 29 | + } |
| 30 | + |
| 31 | + public function getDateCollection() |
| 32 | + { |
| 33 | + return array( |
| 34 | + array( |
| 35 | + array(array('date' => '2014-03-03'), array('date' => '2015-03-02'), array('date' => '2013-03-01')), |
| 36 | + array('date' => '2013-03-01') |
| 37 | + ), |
| 38 | + array( |
| 39 | + array(array('date' => '2014-02-03'), array('date' => '2013-02-01'), array('date' => '2015-02-02')), |
| 40 | + array('date' => '2013-02-01') |
| 41 | + ), |
| 42 | + ); |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * @dataProvider getIdCollection |
| 47 | + */ |
| 48 | + public function testIdComparator($collection, $expected) |
| 49 | + { |
| 50 | + $obj = new ObjectCollection($collection); |
| 51 | + $obj->setComparator(new IdComparator()); |
| 52 | + $elements = $obj->sort(); |
| 53 | + |
| 54 | + $firstElement = array_shift($elements); |
| 55 | + $this->assertEquals($expected, $firstElement); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * @dataProvider getDateCollection |
| 60 | + */ |
| 61 | + public function testDateComparator($collection, $expected) |
| 62 | + { |
| 63 | + $obj = new ObjectCollection($collection); |
| 64 | + $obj->setComparator(new DateComparator()); |
| 65 | + $elements = $obj->sort(); |
| 66 | + |
| 67 | + $firstElement = array_shift($elements); |
| 68 | + $this->assertEquals($expected, $firstElement); |
| 69 | + } |
| 70 | +} |
0 commit comments