|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Markup\Contentful\Tests\Filter; |
| 4 | + |
| 5 | +use Markup\Contentful\Filter\DecidesCacheKeyInterface; |
| 6 | +use Markup\Contentful\Filter\BeforeFilter; |
| 7 | +use Markup\Contentful\Filter\PropertyFilter; |
| 8 | +use Markup\Contentful\FilterInterface; |
| 9 | +use Markup\Contentful\PropertyInterface; |
| 10 | +use Mockery as m; |
| 11 | +use Mockery\Adapter\Phpunit\MockeryTestCase; |
| 12 | + |
| 13 | +class BeforeFilterTest extends MockeryTestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * @var PropertyInterface|m\MockInterface |
| 17 | + */ |
| 18 | + private $property; |
| 19 | + |
| 20 | + /** |
| 21 | + * @var string |
| 22 | + */ |
| 23 | + private $relativeTime; |
| 24 | + |
| 25 | + /** |
| 26 | + * @var BeforeFilter |
| 27 | + */ |
| 28 | + private $filter; |
| 29 | + |
| 30 | + protected function setUp() |
| 31 | + { |
| 32 | + $this->property = m::mock(PropertyInterface::class); |
| 33 | + $this->relativeTime = 'now'; |
| 34 | + $this->filter = new BeforeFilter($this->property, $this->relativeTime); |
| 35 | + } |
| 36 | + |
| 37 | + public function testIsFilter() |
| 38 | + { |
| 39 | + $this->assertInstanceOf(FilterInterface::class, $this->filter); |
| 40 | + } |
| 41 | + |
| 42 | + public function testIsPropertyFilter() |
| 43 | + { |
| 44 | + $this->assertInstanceOf(PropertyFilter::class, $this->filter); |
| 45 | + } |
| 46 | + |
| 47 | + public function testGetKeyUsesLessThan() |
| 48 | + { |
| 49 | + $propertyKey = 'created'; |
| 50 | + $this->property |
| 51 | + ->shouldReceive('getKey') |
| 52 | + ->andReturn($propertyKey); |
| 53 | + $this->assertEquals('created[lt]', $this->filter->getKey()); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * @group time-sensitive |
| 58 | + */ |
| 59 | + public function testGetDateTimeValue() |
| 60 | + { |
| 61 | + $nowValue = \DateTime::createFromFormat('U', time())->format('Y-m-d\TH:i:s\Z'); |
| 62 | + $this->assertEquals($nowValue, $this->filter->getValue()); |
| 63 | + } |
| 64 | + |
| 65 | + public function testDecidesCacheKey() |
| 66 | + { |
| 67 | + $this->assertInstanceOf(DecidesCacheKeyInterface::class, $this->filter); |
| 68 | + $propertyName = 'published'; |
| 69 | + $this->property |
| 70 | + ->shouldReceive('getKey') |
| 71 | + ->andReturn($propertyName); |
| 72 | + $this->assertEquals('|before|published↦now', $this->filter->getCacheKey()); |
| 73 | + } |
| 74 | +} |
0 commit comments