From 98891fd79d977084c24ce5e87a6a6b993b3e4380 Mon Sep 17 00:00:00 2001 From: Vincent Chalamon <407859+vincentchalamon@users.noreply.github.com> Date: Fri, 25 Aug 2023 21:58:03 +0200 Subject: [PATCH] fix: ci --- .github/workflows/ci.yml | 3 ++ api/src/DataFixtures/Factory/BookFactory.php | 35 +++++++++++++++----- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 59dc67867..17a918e16 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -107,6 +107,9 @@ jobs: docker-compose.yml docker-compose.prod.yml set: | + php.image=$PHP_DOCKER_IMAGE + caddy.image=$CADDY_DOCKER_IMAGE + pwa.image=$PWA_DOCKER_IMAGE *.cache-from=type=gha,scope=${{github.ref}}-e2e *.cache-from=type=gha,scope=${{github.ref}} *.cache-from=type=gha,scope=refs/heads/main diff --git a/api/src/DataFixtures/Factory/BookFactory.php b/api/src/DataFixtures/Factory/BookFactory.php index 4f0453711..8a614770a 100644 --- a/api/src/DataFixtures/Factory/BookFactory.php +++ b/api/src/DataFixtures/Factory/BookFactory.php @@ -49,12 +49,16 @@ */ final class BookFactory extends ModelFactory { + private readonly array $data; + /** * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services */ - public function __construct(private readonly DecoderInterface $decoder) + public function __construct(readonly DecoderInterface $decoder) { parent::__construct(); + + $this->data = $decoder->decode(file_get_contents(__DIR__.'/../books.json'), 'json'); } /** @@ -62,13 +66,7 @@ public function __construct(private readonly DecoderInterface $decoder) */ protected function getDefaults(): array { - $data = $this->decoder->decode(file_get_contents(__DIR__.'/../books.json'), 'json'); - $datum = $data[array_rand($data)]; - return [ - 'book' => $datum['book'], - 'title' => $datum['title'], - 'author' => $datum['author'], 'condition' => self::faker()->randomElement(BookCondition::getCases()), ]; } @@ -79,7 +77,28 @@ protected function getDefaults(): array protected function initialize(): self { return $this - // ->afterInstantiate(function(Book $book): void {}) + ->afterInstantiate(function(Book $book): void { + if ($book->book && $book->title && $book->author) { + return; + } + + $book->book ??= $this->data[array_rand($this->data)]['book']; + + if ($book->title && $book->author) { + return; + } + + $datum = current(array_filter($this->data, static function (array $datum) use ($book) { + return $book->book === $datum['book']; + })) ?? [ + 'book' => $book->book, + 'title' => self::faker()->title(), + 'author' => self::faker()->name(), + ]; + + $book->title ??= $datum['title']; + $book->author ??= $datum['author']; + }) ; }