1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PODEntender\Application\Service\Post; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use PODEntender\Domain\Model\Post\AudioEpisode; |
7
|
|
|
use PODEntender\Domain\Model\Post\AudioEpisodeCollection; |
8
|
|
|
use PODEntender\Domain\Model\Post\PostRepository; |
9
|
|
|
|
10
|
|
|
class FetchLatestEpisodesTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
/** @var PostRepository */ |
13
|
|
|
private $postRepository; |
14
|
|
|
|
15
|
|
|
/** @var FetchLatestEpisodes */ |
16
|
|
|
private $fetchLatestEpisodesService; |
17
|
|
|
|
18
|
|
|
protected function setUp(): void |
19
|
|
|
{ |
20
|
|
|
$this->postRepository = $this->prophesize(PostRepository::class); |
|
|
|
|
21
|
|
|
$this->fetchLatestEpisodesService = new FetchLatestEpisodes( |
22
|
|
|
$this->postRepository->reveal() |
23
|
|
|
); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testExecuteFetchesExactAmount(): void |
27
|
|
|
{ |
28
|
|
|
$audioEpisodeCollection = $this->createDefaultAudioEpisodeCollection() |
29
|
|
|
->sortByDesc(function (AudioEpisode $episode) { |
30
|
|
|
return $episode->createdAt(); |
31
|
|
|
}); |
32
|
|
|
|
33
|
|
|
$this->postRepository->withAudio()->willReturn($audioEpisodeCollection); |
|
|
|
|
34
|
|
|
|
35
|
|
|
$result = $this->fetchLatestEpisodesService->execute(2, null); |
36
|
|
|
$this->assertEquals(2, $result->count()); |
37
|
|
|
|
38
|
|
|
$lastEpisode = $result->first(); |
39
|
|
|
$episodeBeforeLast = $result->last(); |
40
|
|
|
|
41
|
|
|
$this->assertEquals($audioEpisodeCollection->take(2)->first()->guid(), $lastEpisode->guid()); |
42
|
|
|
$this->assertEquals($audioEpisodeCollection->take(2)->last()->guid(), $episodeBeforeLast->guid()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testExecuteFiltersCategoryName(): void |
46
|
|
|
{ |
47
|
|
|
$audioEpisodeCollection = $this->createDefaultAudioEpisodeCollection() |
48
|
|
|
->sortByDesc(function (AudioEpisode $episode) { |
49
|
|
|
return $episode->createdAt(); |
50
|
|
|
}); |
51
|
|
|
|
52
|
|
|
$this->postRepository->withAudio()->willReturn($audioEpisodeCollection); |
53
|
|
|
|
54
|
|
|
$result = $this->fetchLatestEpisodesService->execute(2, 'Entrevista'); |
55
|
|
|
$this->assertEquals(2, $result->count()); |
56
|
|
|
|
57
|
|
|
$lastEpisode = $result->first(); |
58
|
|
|
$episodeBeforeLast = $result->last(); |
59
|
|
|
|
60
|
|
|
$this->assertEquals($audioEpisodeCollection->take(2)->last()->guid(), $lastEpisode->guid()); |
61
|
|
|
$this->assertEquals($audioEpisodeCollection->last()->guid(), $episodeBeforeLast->guid()); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
private function createDefaultAudioEpisodeCollection(): AudioEpisodeCollection |
65
|
|
|
{ |
66
|
|
|
$episode01 = $this->prophesize(AudioEpisode::class); |
67
|
|
|
$episode01->guid()->willReturn('ep01'); |
68
|
|
|
$episode01->category()->willReturn('Entrevista'); |
69
|
|
|
$episode01->createdAt()->willReturn(new \DateTime('2019-01-01')); |
70
|
|
|
|
71
|
|
|
$episode02 = $this->prophesize(AudioEpisode::class); |
72
|
|
|
$episode02->guid()->willReturn('ep02'); |
73
|
|
|
$episode02->category()->willReturn('Entrevista'); |
74
|
|
|
$episode02->createdAt()->willReturn(new \DateTime('2019-02-01')); |
75
|
|
|
|
76
|
|
|
$episode03 = $this->prophesize(AudioEpisode::class); |
77
|
|
|
$episode03->guid()->willReturn('ep03'); |
78
|
|
|
$episode03->category()->willReturn('News'); |
79
|
|
|
$episode03->createdAt()->willReturn(new \DateTime('2019-03-01')); |
80
|
|
|
|
81
|
|
|
return new AudioEpisodeCollection([ |
82
|
|
|
$episode01->reveal(), |
83
|
|
|
$episode02->reveal(), |
84
|
|
|
$episode03->reveal(), |
85
|
|
|
]); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..