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']; + }) ; }