Skip to content

Commit

Permalink
fix: ci
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentchalamon committed Aug 25, 2023
1 parent db0a0f9 commit 98891fd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 27 additions & 8 deletions api/src/DataFixtures/Factory/BookFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,24 @@
*/
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');
}

/**
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories
*/
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()),
];
}
Expand All @@ -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'];
})
;
}

Expand Down

0 comments on commit 98891fd

Please sign in to comment.