-
-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DX][Internal] use Foundry for comic books
- Loading branch information
Showing
7 changed files
with
195 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Foundry\Factory; | ||
|
||
use App\Entity\Author; | ||
use Zenstruck\Foundry\ObjectFactory; | ||
|
||
/** | ||
* @extends ObjectFactory<Author> | ||
*/ | ||
final class AuthorFactory extends ObjectFactory | ||
{ | ||
public static function class(): string | ||
{ | ||
return Author::class; | ||
} | ||
|
||
public function withFirstName(string $firstName): self | ||
{ | ||
return $this->with(['firstName' => $firstName]); | ||
} | ||
|
||
public function withLastName(string $lastName): self | ||
{ | ||
return $this->with(['lastName' => $lastName]); | ||
} | ||
|
||
protected function defaults(): array | ||
{ | ||
return [ | ||
'firstName' => self::faker()->firstName(), | ||
'lastName' => self::faker()->lastName(), | ||
]; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
tests/Application/src/Foundry/Factory/ComicBookFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Foundry\Factory; | ||
|
||
use App\Entity\Author; | ||
use App\Entity\ComicBook; | ||
use Doctrine\Persistence\Proxy; | ||
use Zenstruck\Foundry\LazyValue; | ||
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory; | ||
|
||
/** | ||
* @extends PersistentProxyObjectFactory<ComicBook> | ||
*/ | ||
final class ComicBookFactory extends PersistentProxyObjectFactory | ||
{ | ||
public static function class(): string | ||
{ | ||
return ComicBook::class; | ||
} | ||
|
||
public function withTitle(string $title): self | ||
{ | ||
return $this->with(['title' => $title]); | ||
} | ||
|
||
/** | ||
* @param AuthorFactory|Proxy<Author> $author | ||
*/ | ||
public function withAuthor(AuthorFactory|Proxy $author): self | ||
{ | ||
return $this->with(['author' => $author]); | ||
} | ||
|
||
protected function defaults(): array | ||
{ | ||
$author = LazyValue::memoize(fn () => AuthorFactory::createOne()); | ||
|
||
return [ | ||
'title' => ucfirst(self::faker()->words(2, true)), | ||
'author' => $author, | ||
]; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
tests/Application/src/Foundry/Story/DefaultComicBooksStory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Foundry\Story; | ||
|
||
use App\Foundry\Factory\AuthorFactory; | ||
use App\Foundry\Factory\ComicBookFactory; | ||
use Zenstruck\Foundry\Story; | ||
|
||
final class DefaultComicBooksStory extends Story | ||
{ | ||
public function build(): void | ||
{ | ||
ComicBookFactory::new() | ||
->withTitle('Old Man Logan') | ||
->withAuthor( | ||
AuthorFactory::new() | ||
->withFirstName('Andrea') | ||
->withLastName('Sorrentino'), | ||
) | ||
->create() | ||
; | ||
|
||
ComicBookFactory::new() | ||
->withTitle('Civil War II') | ||
->withAuthor( | ||
AuthorFactory::new() | ||
->withFirstName('Brian Michael') | ||
->withLastName('Bendis'), | ||
) | ||
->create() | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
tests/Application/src/Tests/DataFixtures/ORM/comic_books.yml
This file was deleted.
Oops, something went wrong.