1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| <?php declare(strict_types = 1);
namespace DesignPatterns\Behavioral\Strategy\Tests;
use DesignPatterns\Behavioral\Strategy\Context; use DesignPatterns\Behavioral\Strategy\DateComparator; use DesignPatterns\Behavioral\Strategy\IdComparator; use PHPUnit\Framework\TestCase;
class StrategyTest extends TestCase { public function provideIntegers() { return [ [ [['id' => 2], ['id' => 1], ['id' => 3]], ['id' => 1], ], [ [['id' => 3], ['id' => 2], ['id' => 1]], ['id' => 1], ], ]; }
public function provideDates() { return [ [ [['date' => '2014-03-03'], ['date' => '2015-03-02'], ['date' => '2013-03-01']], ['date' => '2013-03-01'], ], [ [['date' => '2014-02-03'], ['date' => '2013-02-01'], ['date' => '2015-02-02']], ['date' => '2013-02-01'], ], ]; }
public function testIdComparator($collection, $expected) { $obj = new Context(new IdComparator()); $elements = $obj->executeStrategy($collection);
$firstElement = array_shift($elements); $this->assertSame($expected, $firstElement); }
public function testDateComparator($collection, $expected) { $obj = new Context(new DateComparator()); $elements = $obj->executeStrategy($collection);
$firstElement = array_shift($elements); $this->assertSame($expected, $firstElement); } }
|