Skip to content

Commit

Permalink
Add test for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasVHG committed Feb 24, 2025
1 parent 7750dc2 commit 2073769
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion tests/Kinepolis/Trailer/YoutubeTrailerRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use CultuurNet\UDB3\Model\ValueObject\Translation\Language;
use CultuurNet\UDB3\Model\ValueObject\Web\Url;
use CultuurNet\UDB3\SampleFiles;
use Google\Service\Exception as GoogleException;
use Google\Service\YouTube\Resource\Search;
use Google_Service_YouTube;
use PHPUnit\Framework\MockObject\MockObject;
Expand All @@ -32,19 +33,25 @@ final class YoutubeTrailerRepositoryTest extends TestCase
*/
private $search;

/**
* @var LoggerInterface&MockObject
*/
private $logger;

public function setUp(): void
{
$this->search = $this->createMock(Search::class);
$youtubeClient = $this->createMock(Google_Service_YouTube::class);
$youtubeClient->search = $this->search;
$this->channelId = 'mockChannelId';
$this->uuidGenerator = $this->createMock(UuidGeneratorInterface::class);
$this->logger = $this->createMock(LoggerInterface::class);

$this->trailerRepository = new YoutubeTrailerRepository(
$youtubeClient,
$this->channelId,
$this->uuidGenerator,
$this->createMock(LoggerInterface::class),
$this->logger,
true
);
}
Expand Down Expand Up @@ -96,4 +103,24 @@ public function it_will_sanitize_searches(): void
$video
);
}

/**
* @test
*/
public function it_should_log_when_the_log_throws_an_exception(): void
{
$this->search->expects($this->once())->method('listSearch')->with('id,snippet', [
'channelId' => $this->channelId,
'q' => 'NotFound',
'maxResults' => 1,
])->willThrowException(new GoogleException('some Google Exception'));

$this->uuidGenerator->expects($this->never())->method('generate');
$this->logger->expects($this->once())
->method('error')
->with('some Google Exception');

$video = $this->trailerRepository->findMatchingTrailer('NotFound');
$this->assertNull($video);
}
}

0 comments on commit 2073769

Please sign in to comment.