-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PROGRAMMES-5737 Adding new service methods (#197)
- Loading branch information
Showing
6 changed files
with
208 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
tests/Service/ProgrammesAggregationService/FindStreamableDescendantEpisodesTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Tests\BBC\ProgrammesPagesService\Service\ProgrammesAggregationService; | ||
|
||
use BBC\ProgrammesPagesService\Domain\Entity\Episode; | ||
use BBC\ProgrammesPagesService\Domain\Entity\Programme; | ||
|
||
class FindStreamableDescendantEpisodesTest extends AbstractProgrammesAggregationTest | ||
{ | ||
/** | ||
* @dataProvider paginationProvider | ||
*/ | ||
public function testProtocolWithRepositoryCollaborator(int $expectedLimit, int $expectedOffset, array $paramsPagination) | ||
{ | ||
$stubProgramme = $this->createConfiguredMock(Programme::class, ['getDbAncestryIds' => [11, 12]]); | ||
|
||
$this->mockRepository->expects($this->once()) | ||
->method('findStreamableDescendantsByType') | ||
->with($stubProgramme->getDbAncestryIds(), 'Episode', $expectedLimit, $expectedOffset); | ||
|
||
$this->service()->findStreamableDescendantEpisodes($stubProgramme, ...$paramsPagination); | ||
} | ||
|
||
public function paginationProvider(): array | ||
{ | ||
return [ | ||
// [expectedLimit, expectedOffset, [limit, page]] | ||
'default pagination' => [300, 0, []], | ||
'custom pagination' => [3, 12, [3, 5]], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider dbEpisodesProvider | ||
*/ | ||
public function testResults(array $expectedEpisodesPids, array $dbEpisodesProvided) | ||
{ | ||
$this->mockRepository->method('findStreamableDescendantsByType')->willReturn($dbEpisodesProvided); | ||
|
||
$episodes = $this->service()->findStreamableDescendantEpisodes($this->createMock(Programme::class)); | ||
|
||
$this->assertContainsOnlyInstancesOf(Episode::class, $episodes); | ||
$this->assertCount(count($dbEpisodesProvided), $episodes); | ||
foreach ($expectedEpisodesPids as $i => $expectedPid) { | ||
$this->assertEquals($expectedPid, $episodes[$i]->getPid()); | ||
} | ||
} | ||
|
||
public function dbEpisodesProvider(): array | ||
{ | ||
return [ | ||
'CASE: episodes results found' => [ | ||
['p002b7q9', 'p002kzxk'], | ||
[['type' => 'episode', 'pid' => 'p002b7q9'], ['type' => 'episode', 'pid' => 'p002kzxk']], | ||
], | ||
'CASE: episodes results NOT found' => [[], []], | ||
]; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
tests/Service/ProgrammesAggregationService/FindUpcomingStreamableDescendantEpisodesTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Tests\BBC\ProgrammesPagesService\Service\ProgrammesAggregationService; | ||
|
||
use BBC\ProgrammesPagesService\Domain\Entity\Episode; | ||
use BBC\ProgrammesPagesService\Domain\Entity\Programme; | ||
|
||
class FindUpcomingStreamableDescendantEpisodesTest extends AbstractProgrammesAggregationTest | ||
{ | ||
/** | ||
* @dataProvider paginationProvider | ||
*/ | ||
public function testProtocolWithRepositoryCollaborator(int $expectedLimit, int $expectedOffset, array $paramsPagination) | ||
{ | ||
$stubProgramme = $this->createConfiguredMock(Programme::class, ['getDbAncestryIds' => [11, 12]]); | ||
|
||
$this->mockRepository->expects($this->once()) | ||
->method('findUpcomingStreamableDescendantsByType') | ||
->with($stubProgramme->getDbAncestryIds(), 'Episode', $expectedLimit, $expectedOffset); | ||
|
||
$this->service()->findUpcomingStreamableDescendantEpisodes($stubProgramme, ...$paramsPagination); | ||
} | ||
|
||
public function paginationProvider(): array | ||
{ | ||
return [ | ||
// [expectedLimit, expectedOffset, [limit, page]] | ||
'default pagination' => [300, 0, []], | ||
'custom pagination' => [3, 12, [3, 5]], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider dbEpisodesProvider | ||
*/ | ||
public function testResults(array $expectedEpisodesPids, array $dbEpisodesProvided) | ||
{ | ||
$this->mockRepository->method('findUpcomingStreamableDescendantsByType')->willReturn($dbEpisodesProvided); | ||
|
||
$episodes = $this->service()->findUpcomingStreamableDescendantEpisodes($this->createMock(Programme::class)); | ||
|
||
$this->assertContainsOnlyInstancesOf(Episode::class, $episodes); | ||
$this->assertCount(count($dbEpisodesProvided), $episodes); | ||
foreach ($expectedEpisodesPids as $i => $expectedPid) { | ||
$this->assertEquals($expectedPid, $episodes[$i]->getPid()); | ||
} | ||
} | ||
|
||
public function dbEpisodesProvider(): array | ||
{ | ||
return [ | ||
'CASE: episodes results found' => [ | ||
['p002b7q9', 'p002kzxk'], | ||
[['type' => 'episode', 'pid' => 'p002b7q9'], ['type' => 'episode', 'pid' => 'p002kzxk']], | ||
], | ||
'CASE: episodes results NOT found' => [[], []], | ||
]; | ||
} | ||
} |