From e7ad02a3622aba2d1522ff86fc51f8321c935cc3 Mon Sep 17 00:00:00 2001 From: Xavier Leune Date: Tue, 17 Nov 2026 17:44:57 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Ajoute=20un=20bloc=20=C2=AB=20Derni=C3=A8re?= =?UTF-8?q?s=20vid=C3=A9os=20=C2=BB=20sur=20la=20home?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit La home ne mettait en avant aucune vidéo de conférence, alors que c'est le contenu le plus consulté du site. Le bloc liste les 6 derniers talks publiés avec vidéo (planifiés, affichés dans l'historique, date de publication passée, créneau de planning terminé, youtube_id renseigné), du créneau terminé le plus récent au plus ancien, avec vignette YouTube, titre, événement et un lien vers /talks/. Une seule requête (talk + événement) alimente le bloc. Son résultat est mis en cache une heure dans un pool dédié adossé à cache.app : une vidéo est publiée quelques jours après l'événement, une heure de délai ne gêne pas. En test, le pool utilise un adaptateur array pour que chaque scénario Behat voie les données rechargées et la date simulée. Les données de test vivent dans un seed dédié (une édition passée à part) pour ne pas modifier les autres éditions ni db/seeds/Session.php. --- config/packages/cache.yaml | 17 ++++ db/seeds/TalksWithVideo.php | 88 +++++++++++++++++++ .../Controller/Website/Global/HomeAction.php | 3 + .../Event/Model/Repository/TalkRepository.php | 43 +++++++++ sources/AppBundle/Event/Talk/LatestVideo.php | 25 ++++++ sources/AppBundle/Event/Talk/LatestVideos.php | 53 +++++++++++ templates/site/home.html.twig | 35 ++++++++ tests/behat/features/PublicSite/Home.feature | 28 ++++++ .../AppBundle/Event/Talk/LatestVideosTest.php | 51 +++++++++++ 9 files changed, 343 insertions(+) create mode 100644 config/packages/cache.yaml create mode 100644 db/seeds/TalksWithVideo.php create mode 100644 sources/AppBundle/Event/Talk/LatestVideo.php create mode 100644 sources/AppBundle/Event/Talk/LatestVideos.php create mode 100644 tests/unit/AppBundle/Event/Talk/LatestVideosTest.php diff --git a/config/packages/cache.yaml b/config/packages/cache.yaml new file mode 100644 index 000000000..013f6da11 --- /dev/null +++ b/config/packages/cache.yaml @@ -0,0 +1,17 @@ +framework: + cache: + pools: + # Bloc « Dernières vidéos » de la home : une heure suffit, une vidéo est + # publiée quelques jours après l'événement, pas à la minute près. + cache.latest_videos: + adapter: cache.app + default_lifetime: 3600 + +when@test: + framework: + cache: + pools: + # Pas de cache persistant en test : chaque scénario Behat recharge + # la base et peut changer la date courante. + cache.latest_videos: + adapter: cache.adapter.array diff --git a/db/seeds/TalksWithVideo.php b/db/seeds/TalksWithVideo.php new file mode 100644 index 000000000..2de3e8044 --- /dev/null +++ b/db/seeds/TalksWithVideo.php @@ -0,0 +1,88 @@ +table('afup_forum') + ->insert([ + 'id' => self::ID_EVENT, + 'titre' => 'Rencontres vidéo 2019', + 'path' => 'rencontres-video-2019', + 'nb_places' => 100, + 'date_debut' => '2019-05-23', + 'date_fin' => '2019-05-24', + 'annee' => 2019, + ]) + ->save(); + + $notEndedYet = new \DateTime('+10 days 10:00:00')->format('Y-m-d H:i:s'); + + $talks = [ + 100 => ['titre' => 'PHP 8 en production', 'fin' => '2019-05-24 10:00:00'], + 101 => ['titre' => 'Les fibers expliquées', 'fin' => '2019-05-24 17:00:00'], + 102 => ['titre' => 'Sécuriser une API', 'fin' => '2019-05-24 11:00:00'], + 103 => ['titre' => 'Domain-Driven Design au quotidien', 'fin' => '2019-05-24 15:00:00'], + 104 => ['titre' => 'Le plus ancien talk en vidéo', 'fin' => '2019-05-23 10:00:00'], + 105 => ['titre' => 'Une clinique filmée', 'fin' => '2019-05-24 18:00:00', 'genre' => 6], + 106 => ['titre' => 'Un talk sans vidéo', 'fin' => '2019-05-24 18:00:00', 'youtube_id' => ''], + 107 => ['titre' => 'Un talk non planifié', 'fin' => '2019-05-24 18:00:00', 'plannifie' => 0], + 108 => ['titre' => 'Un talk au créneau pas terminé', 'fin' => $notEndedYet], + ]; + + $sessions = []; + $speakers = []; + $plannings = []; + foreach ($talks as $sessionId => $talk) { + $sessions[] = [ + 'session_id' => $sessionId, + 'id_forum' => self::ID_EVENT, + 'date_soumission' => '2019-01-15', + 'titre' => $talk['titre'], + 'abstract' => 'Résumé du talk « ' . $talk['titre'] . ' ».', + 'genre' => $talk['genre'] ?? 1, + 'skill' => 0, + 'plannifie' => $talk['plannifie'] ?? 1, + 'youtube_id' => $talk['youtube_id'] ?? 'video' . $sessionId, + 'language_code' => 'fr', + ]; + $speakers[] = [ + 'session_id' => $sessionId, + 'conferencier_id' => Conferenciers::ID_CONFERENCIER, + ]; + $end = new \DateTime($talk['fin']); + $plannings[] = [ + 'id' => $sessionId, + 'id_session' => $sessionId, + 'debut' => (clone $end)->modify('-40 minutes')->format('U'), + 'fin' => $end->format('U'), + 'id_forum' => self::ID_EVENT, + 'keynote' => 0, + ]; + } + + $this->table('afup_sessions')->insert($sessions)->save(); + $this->table('afup_conferenciers_sessions')->insert($speakers)->save(); + $this->table('afup_forum_planning')->insert($plannings)->save(); + } +} diff --git a/sources/AppBundle/Controller/Website/Global/HomeAction.php b/sources/AppBundle/Controller/Website/Global/HomeAction.php index c0bb5ff62..7448cb5b2 100644 --- a/sources/AppBundle/Controller/Website/Global/HomeAction.php +++ b/sources/AppBundle/Controller/Website/Global/HomeAction.php @@ -6,6 +6,7 @@ use AppBundle\Event\Entity\Repository\MeetupRepository; use AppBundle\Event\Model\Repository\EventRepository; +use AppBundle\Event\Talk\LatestVideos; use AppBundle\Site\ArticleImageStorage; use AppBundle\Site\Entity\Repository\ArticleRepository; use AppBundle\Twig\ViewRenderer; @@ -20,6 +21,7 @@ public function __construct( private readonly MeetupRepository $meetupRepository, private readonly EventRepository $eventRepository, private readonly ArticleImageStorage $articleImageStorage, + private readonly LatestVideos $latestVideos, ) {} public function __invoke(): Response @@ -32,6 +34,7 @@ public function __invoke(): Response 'meetups' => $meetups, 'lastArticleImageUrl' => $this->articleImageStorage->getUrl($articles[0]) ?? 'images/article-default-image.svg', 'currentEvent' => $this->eventRepository->getMostRecentEvent(), + 'latestVideos' => $this->latestVideos->get(), ]); } } diff --git a/sources/AppBundle/Event/Model/Repository/TalkRepository.php b/sources/AppBundle/Event/Model/Repository/TalkRepository.php index 967add9b4..4272d4aaa 100644 --- a/sources/AppBundle/Event/Model/Repository/TalkRepository.php +++ b/sources/AppBundle/Event/Model/Repository/TalkRepository.php @@ -15,6 +15,7 @@ use CCMBenchmark\Ting\Driver\Mysqli\Serializer\Boolean; use CCMBenchmark\Ting\Query\QueryException; use CCMBenchmark\Ting\Repository\CollectionInterface; +use CCMBenchmark\Ting\Repository\Hydrator; use CCMBenchmark\Ting\Repository\HydratorArray; use CCMBenchmark\Ting\Repository\HydratorSingleObject; use CCMBenchmark\Ting\Repository\Metadata; @@ -380,6 +381,48 @@ public function getScheduledTalksByEvent(int $eventId): CollectionInterface return $query->query($this->getCollection(new HydratorSingleObject())); } + /** + * Derniers talks publiés avec une vidéo, du créneau terminé le plus récent au plus ancien. + * « Publié » reprend les règles de la page talk : talk planifié, affiché dans l'historique + * (ni clinique, ni introduction des speakers), date de publication passée ou vide, + * et tous ses créneaux de planning terminés. + * + * @return list + */ + public function getLatestPublishedWithVideo(\DateTimeInterface $now, int $limit): array + { + $query = $this->getPreparedQuery( + 'SELECT talk.session_id, talk.titre, talk.youtube_id, event.id, event.titre + FROM afup_sessions AS talk + INNER JOIN ( + SELECT id_session, MAX(fin) AS fin + FROM afup_forum_planning + GROUP BY id_session + ) AS planning ON planning.id_session = talk.session_id + INNER JOIN afup_forum AS event ON event.id = talk.id_forum + WHERE talk.plannifie = 1 + AND talk.genre NOT IN (:clinic, :speakerIntroductions) + AND LENGTH(talk.youtube_id) > 0 + AND (talk.date_publication IS NULL OR talk.date_publication < :now) + AND planning.fin <= :nowTimestamp + ORDER BY planning.fin DESC, talk.session_id DESC + LIMIT ' . $limit, + )->setParams([ + 'clinic' => Talk::TYPE_CLINIC, + 'speakerIntroductions' => Talk::TYPE_SPEAKER_INTRODUCTIONS, + 'now' => $now->format('Y-m-d H:i:s'), + 'nowTimestamp' => $now->getTimestamp(), + ]); + + $latest = []; + /** @var array{talk: Talk, event: Event} $row */ + foreach ($query->query($this->getCollection(new Hydrator())) as $row) { + $latest[] = ['talk' => $row['talk'], 'event' => $row['event']]; + } + + return $latest; + } + public function getAllPastTalks(\DateTime $dateTime) { $query = $this->getPreparedQuery( diff --git a/sources/AppBundle/Event/Talk/LatestVideo.php b/sources/AppBundle/Event/Talk/LatestVideo.php new file mode 100644 index 000000000..8b1efb123 --- /dev/null +++ b/sources/AppBundle/Event/Talk/LatestVideo.php @@ -0,0 +1,25 @@ +youtubeId) . '/hqdefault.jpg'; + } +} diff --git a/sources/AppBundle/Event/Talk/LatestVideos.php b/sources/AppBundle/Event/Talk/LatestVideos.php new file mode 100644 index 000000000..ed26a59be --- /dev/null +++ b/sources/AppBundle/Event/Talk/LatestVideos.php @@ -0,0 +1,53 @@ + + */ + public function get(): array + { + $cacheItem = $this->cache->getItem(self::CACHE_KEY); + + if (!$cacheItem->isHit()) { + $videos = []; + foreach ($this->talkRepository->getLatestPublishedWithVideo($this->clock->now(), self::LIMIT) as $row) { + $videos[] = new LatestVideo( + (int) $row['talk']->getId(), + $row['talk']->getSlug(), + $row['talk']->getTitle(), + (string) $row['talk']->getYoutubeId(), + (string) $row['event']->getTitle(), + ); + } + + $cacheItem->set($videos); + $this->cache->save($cacheItem); + } + + /** @var list $videos */ + $videos = $cacheItem->get(); + + return $videos; + } +} diff --git a/templates/site/home.html.twig b/templates/site/home.html.twig index f166f9134..4030f7864 100644 --- a/templates/site/home.html.twig +++ b/templates/site/home.html.twig @@ -173,6 +173,41 @@ + {% if latestVideos is not empty %} +
+

+ Dernières vidéos +

+ + + + + Toutes les vidéos + +
+ {% endif %} +
Dans les antennes diff --git a/tests/behat/features/PublicSite/Home.feature b/tests/behat/features/PublicSite/Home.feature index 45ce13746..572ebb70c 100644 --- a/tests/behat/features/PublicSite/Home.feature +++ b/tests/behat/features/PublicSite/Home.feature @@ -45,3 +45,31 @@ Feature: Site Public - Home When I am on "/home" Then the response status code should be 301 And the response header "Location" should match "#^(https?://[^/]+)?/$#" + + @reloadDbWithTestData + Scenario: Bloc des dernières vidéos + Given I am on the homepage + Then I should see "Dernières vidéos" in the "#dernieres-videos h2" element + # Les 6 talks publiés avec vidéo dont le créneau s'est terminé le plus récemment, du plus récent au plus ancien + And I should see 6 "#dernieres-videos li" elements + And I should see "REST ou GraphQL ? Exemples illustrés avec Symfony et API Platform" in the "#dernieres-videos li:nth-child(1)" element + And the "#dernieres-videos li:nth-child(1)" element should contain "href=\"/talks/2-rest-ou-graphql-exemples-illustres-avec-symfony-et-api-platform\"" + And the "#dernieres-videos li:nth-child(1)" element should contain "https://img.youtube.com/vi/QhAToFl_Omo/hqdefault.jpg" + And I should see "forum" in the "#dernieres-videos li:nth-child(1)" element + And I should see "Jouons tous ensemble à un petit jeu" in the "#dernieres-videos li:nth-child(2)" element + And I should see "Les fibers expliquées" in the "#dernieres-videos li:nth-child(3)" element + And the "#dernieres-videos li:nth-child(3)" element should contain "href=\"/talks/101-les-fibers-expliquees\"" + And I should see "Rencontres vidéo 2019" in the "#dernieres-videos li:nth-child(3)" element + And I should see "Domain-Driven Design au quotidien" in the "#dernieres-videos li:nth-child(4)" element + And I should see "Sécuriser une API" in the "#dernieres-videos li:nth-child(5)" element + And I should see "PHP 8 en production" in the "#dernieres-videos li:nth-child(6)" element + # Au-delà des 6 plus récents + And I should not see "Le plus ancien talk en vidéo" in the "#dernieres-videos" element + # Talks non publiés ou sans vidéo + And I should not see "Révolutionons PHP" in the "#dernieres-videos" element + And I should not see "Une clinique filmée" in the "#dernieres-videos" element + And I should not see "Un talk sans vidéo" in the "#dernieres-videos" element + And I should not see "Un talk non planifié" in the "#dernieres-videos" element + And I should not see "Un talk au créneau pas terminé" in the "#dernieres-videos" element + When I follow "Toutes les vidéos" + Then the url should match "/talks/$" diff --git a/tests/unit/AppBundle/Event/Talk/LatestVideosTest.php b/tests/unit/AppBundle/Event/Talk/LatestVideosTest.php new file mode 100644 index 000000000..87b6c62ba --- /dev/null +++ b/tests/unit/AppBundle/Event/Talk/LatestVideosTest.php @@ -0,0 +1,51 @@ +setId(42); + $talk->setTitle('Les fibers expliquées'); + $talk->setYoutubeId('abc123'); + + $event = new Event(); + $event->setTitle('Forum PHP 2026'); + + $talkRepository = $this->createMock(TalkRepository::class); + $talkRepository + ->expects(self::once()) + ->method('getLatestPublishedWithVideo') + ->with($now, LatestVideos::LIMIT) + ->willReturn([['talk' => $talk, 'event' => $event]]); + + $latestVideos = new LatestVideos($talkRepository, new MockClock($now), new ArrayAdapter()); + + $expected = [new LatestVideo(42, 'les-fibers-expliquees', 'Les fibers expliquées', 'abc123', 'Forum PHP 2026')]; + self::assertEquals($expected, $latestVideos->get()); + // Le second appel est servi par le cache : le repository n'est appelé qu'une fois. + self::assertEquals($expected, $latestVideos->get()); + } + + public function testThumbnailUrl(): void + { + $video = new LatestVideo(42, 'slug', 'Titre', 'abc123', 'Forum PHP 2026'); + + self::assertSame('https://img.youtube.com/vi/abc123/hqdefault.jpg', $video->getThumbnailUrl()); + } +} From 52fdb763b3a165d7c5d93d6c09c519e14ad00bf2 Mon Sep 17 00:00:00 2001 From: Xavier Leune Date: Fri, 20 Nov 2026 15:23:26 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Passe=20la=20requ=C3=AAte=20des=20derni?= =?UTF-8?q?=C3=A8res=20vid=C3=A9os=20en=20DBAL=20suivant=20l'ADR-002?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Event/Model/Repository/TalkRepository.php | 43 ------------- .../Event/Talk/LatestVideoRepository.php | 64 +++++++++++++++++++ sources/AppBundle/Event/Talk/LatestVideos.php | 16 +---- .../AppBundle/Event/Talk/LatestVideosTest.php | 48 ++++++-------- 4 files changed, 85 insertions(+), 86 deletions(-) create mode 100644 sources/AppBundle/Event/Talk/LatestVideoRepository.php diff --git a/sources/AppBundle/Event/Model/Repository/TalkRepository.php b/sources/AppBundle/Event/Model/Repository/TalkRepository.php index 4272d4aaa..967add9b4 100644 --- a/sources/AppBundle/Event/Model/Repository/TalkRepository.php +++ b/sources/AppBundle/Event/Model/Repository/TalkRepository.php @@ -15,7 +15,6 @@ use CCMBenchmark\Ting\Driver\Mysqli\Serializer\Boolean; use CCMBenchmark\Ting\Query\QueryException; use CCMBenchmark\Ting\Repository\CollectionInterface; -use CCMBenchmark\Ting\Repository\Hydrator; use CCMBenchmark\Ting\Repository\HydratorArray; use CCMBenchmark\Ting\Repository\HydratorSingleObject; use CCMBenchmark\Ting\Repository\Metadata; @@ -381,48 +380,6 @@ public function getScheduledTalksByEvent(int $eventId): CollectionInterface return $query->query($this->getCollection(new HydratorSingleObject())); } - /** - * Derniers talks publiés avec une vidéo, du créneau terminé le plus récent au plus ancien. - * « Publié » reprend les règles de la page talk : talk planifié, affiché dans l'historique - * (ni clinique, ni introduction des speakers), date de publication passée ou vide, - * et tous ses créneaux de planning terminés. - * - * @return list - */ - public function getLatestPublishedWithVideo(\DateTimeInterface $now, int $limit): array - { - $query = $this->getPreparedQuery( - 'SELECT talk.session_id, talk.titre, talk.youtube_id, event.id, event.titre - FROM afup_sessions AS talk - INNER JOIN ( - SELECT id_session, MAX(fin) AS fin - FROM afup_forum_planning - GROUP BY id_session - ) AS planning ON planning.id_session = talk.session_id - INNER JOIN afup_forum AS event ON event.id = talk.id_forum - WHERE talk.plannifie = 1 - AND talk.genre NOT IN (:clinic, :speakerIntroductions) - AND LENGTH(talk.youtube_id) > 0 - AND (talk.date_publication IS NULL OR talk.date_publication < :now) - AND planning.fin <= :nowTimestamp - ORDER BY planning.fin DESC, talk.session_id DESC - LIMIT ' . $limit, - )->setParams([ - 'clinic' => Talk::TYPE_CLINIC, - 'speakerIntroductions' => Talk::TYPE_SPEAKER_INTRODUCTIONS, - 'now' => $now->format('Y-m-d H:i:s'), - 'nowTimestamp' => $now->getTimestamp(), - ]); - - $latest = []; - /** @var array{talk: Talk, event: Event} $row */ - foreach ($query->query($this->getCollection(new Hydrator())) as $row) { - $latest[] = ['talk' => $row['talk'], 'event' => $row['event']]; - } - - return $latest; - } - public function getAllPastTalks(\DateTime $dateTime) { $query = $this->getPreparedQuery( diff --git a/sources/AppBundle/Event/Talk/LatestVideoRepository.php b/sources/AppBundle/Event/Talk/LatestVideoRepository.php new file mode 100644 index 000000000..61bf3a2e1 --- /dev/null +++ b/sources/AppBundle/Event/Talk/LatestVideoRepository.php @@ -0,0 +1,64 @@ + + */ + public function getLatest(\DateTimeInterface $now, int $limit): array + { + /** @var list $rows */ + $rows = $this->connection->fetchAllAssociative( + 'SELECT talk.session_id, talk.titre, talk.youtube_id, event.titre AS event_title + FROM afup_sessions AS talk + INNER JOIN ( + SELECT id_session, MAX(fin) AS fin + FROM afup_forum_planning + GROUP BY id_session + ) AS planning ON planning.id_session = talk.session_id + INNER JOIN afup_forum AS event ON event.id = talk.id_forum + WHERE talk.plannifie = 1 + AND talk.genre NOT IN (:clinic, :speakerIntroductions) + AND LENGTH(talk.youtube_id) > 0 + AND (talk.date_publication IS NULL OR talk.date_publication < :now) + AND planning.fin <= :nowTimestamp + ORDER BY planning.fin DESC, talk.session_id DESC + LIMIT :limit', + [ + 'clinic' => Talk::TYPE_CLINIC, + 'speakerIntroductions' => Talk::TYPE_SPEAKER_INTRODUCTIONS, + 'now' => $now->format('Y-m-d H:i:s'), + 'nowTimestamp' => $now->getTimestamp(), + 'limit' => $limit, + ], + ['limit' => ParameterType::INTEGER], + ); + + return array_map( + static fn(array $row): LatestVideo => new LatestVideo( + (int) $row['session_id'], + // Slug construit par le modèle, pour rester identique à celui de la page talk + (new Talk())->setTitle($row['titre'])->getSlug(), + $row['titre'], + $row['youtube_id'], + $row['event_title'], + ), + $rows, + ); + } +} diff --git a/sources/AppBundle/Event/Talk/LatestVideos.php b/sources/AppBundle/Event/Talk/LatestVideos.php index ed26a59be..a8e5e2952 100644 --- a/sources/AppBundle/Event/Talk/LatestVideos.php +++ b/sources/AppBundle/Event/Talk/LatestVideos.php @@ -4,7 +4,6 @@ namespace AppBundle\Event\Talk; -use AppBundle\Event\Model\Repository\TalkRepository; use Psr\Cache\CacheItemPoolInterface; use Psr\Clock\ClockInterface; use Symfony\Component\DependencyInjection\Attribute\Autowire; @@ -15,7 +14,7 @@ private const string CACHE_KEY = 'latest_videos'; public function __construct( - private TalkRepository $talkRepository, + private LatestVideoRepository $latestVideoRepository, private ClockInterface $clock, // Durée de vie du cache définie sur le pool (config/packages/cache.yaml). #[Autowire('@cache.latest_videos')] @@ -30,18 +29,7 @@ public function get(): array $cacheItem = $this->cache->getItem(self::CACHE_KEY); if (!$cacheItem->isHit()) { - $videos = []; - foreach ($this->talkRepository->getLatestPublishedWithVideo($this->clock->now(), self::LIMIT) as $row) { - $videos[] = new LatestVideo( - (int) $row['talk']->getId(), - $row['talk']->getSlug(), - $row['talk']->getTitle(), - (string) $row['talk']->getYoutubeId(), - (string) $row['event']->getTitle(), - ); - } - - $cacheItem->set($videos); + $cacheItem->set($this->latestVideoRepository->getLatest($this->clock->now(), self::LIMIT)); $this->cache->save($cacheItem); } diff --git a/tests/unit/AppBundle/Event/Talk/LatestVideosTest.php b/tests/unit/AppBundle/Event/Talk/LatestVideosTest.php index 87b6c62ba..f849cea20 100644 --- a/tests/unit/AppBundle/Event/Talk/LatestVideosTest.php +++ b/tests/unit/AppBundle/Event/Talk/LatestVideosTest.php @@ -4,48 +4,38 @@ namespace AppBundle\Tests\Event\Talk; -use AppBundle\Event\Model\Event; -use AppBundle\Event\Model\Repository\TalkRepository; -use AppBundle\Event\Model\Talk; use AppBundle\Event\Talk\LatestVideo; +use AppBundle\Event\Talk\LatestVideoRepository; use AppBundle\Event\Talk\LatestVideos; +use Doctrine\DBAL\Connection; use PHPUnit\Framework\TestCase; use Symfony\Component\Cache\Adapter\ArrayAdapter; use Symfony\Component\Clock\MockClock; final class LatestVideosTest extends TestCase { - public function testMapsTalksToVideosAndCachesTheResult(): void + public function testMapsRowsToVideosAndCachesTheResult(): void { - $now = new \DateTimeImmutable('2026-11-17 12:00:00'); - - $talk = new Talk(); - $talk->setId(42); - $talk->setTitle('Les fibers expliquées'); - $talk->setYoutubeId('abc123'); - - $event = new Event(); - $event->setTitle('Forum PHP 2026'); - - $talkRepository = $this->createMock(TalkRepository::class); - $talkRepository + $connection = $this->createMock(Connection::class); + $connection ->expects(self::once()) - ->method('getLatestPublishedWithVideo') - ->with($now, LatestVideos::LIMIT) - ->willReturn([['talk' => $talk, 'event' => $event]]); - - $latestVideos = new LatestVideos($talkRepository, new MockClock($now), new ArrayAdapter()); + ->method('fetchAllAssociative') + ->willReturn([[ + 'session_id' => '42', + 'titre' => 'Les fibers expliquées', + 'youtube_id' => 'abc123', + 'event_title' => 'Forum PHP 2026', + ]]); + + $latestVideos = new LatestVideos( + new LatestVideoRepository($connection), + new MockClock(new \DateTimeImmutable('2026-11-17 12:00:00')), + new ArrayAdapter(), + ); $expected = [new LatestVideo(42, 'les-fibers-expliquees', 'Les fibers expliquées', 'abc123', 'Forum PHP 2026')]; self::assertEquals($expected, $latestVideos->get()); - // Le second appel est servi par le cache : le repository n'est appelé qu'une fois. + // Le second appel est servi par le cache : la base n'est interrogée qu'une fois. self::assertEquals($expected, $latestVideos->get()); } - - public function testThumbnailUrl(): void - { - $video = new LatestVideo(42, 'slug', 'Titre', 'abc123', 'Forum PHP 2026'); - - self::assertSame('https://img.youtube.com/vi/abc123/hqdefault.jpg', $video->getThumbnailUrl()); - } }