-
-
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.
- Loading branch information
Showing
7 changed files
with
252 additions
and
82 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
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,52 @@ | ||
<?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\Book; | ||
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory; | ||
|
||
/** | ||
* @extends PersistentProxyObjectFactory<Book> | ||
*/ | ||
final class BookFactory extends PersistentProxyObjectFactory | ||
{ | ||
public static function class(): string | ||
{ | ||
return Book::class; | ||
} | ||
|
||
public function withTranslations(array $translations): self | ||
{ | ||
return $this->with(['translations' => $translations]); | ||
} | ||
|
||
public function withTitle(string $title): self | ||
{ | ||
return $this->with(['title' => $title]); | ||
} | ||
|
||
public function withAuthor(string $author): self | ||
{ | ||
return $this->with(['author' => $author]); | ||
} | ||
|
||
protected function defaults(): array | ||
{ | ||
return [ | ||
'fallbackLocale' => 'en_US', | ||
'currentLocale' => 'en_US', | ||
'author' => self::faker()->firstName() . ' ' . self::faker()->lastName(), | ||
]; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
tests/Application/src/Foundry/Factory/BookTranslationFactory.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,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\BookTranslation; | ||
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory; | ||
|
||
/** | ||
* @extends PersistentProxyObjectFactory<BookTranslation> | ||
*/ | ||
final class BookTranslationFactory extends PersistentProxyObjectFactory | ||
{ | ||
public static function class(): string | ||
{ | ||
return BookTranslation::class; | ||
} | ||
|
||
public function withLocale(string $locale): self | ||
{ | ||
return $this->with(['locale' => $locale]); | ||
} | ||
|
||
public function withTitle(string $title): self | ||
{ | ||
return $this->with(['title' => $title]); | ||
} | ||
|
||
protected function defaults(): array | ||
{ | ||
return [ | ||
'locale' => self::faker()->locale(), | ||
'title' => ucfirst(self::faker()->words(2, true)), | ||
]; | ||
} | ||
} |
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,43 @@ | ||
<?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\BookFactory; | ||
use App\Foundry\Factory\BookTranslationFactory; | ||
use Zenstruck\Foundry\Story; | ||
|
||
final class DefaultBooksStory extends Story | ||
{ | ||
public function build(): void | ||
{ | ||
BookFactory::new() | ||
->withTranslations([ | ||
BookTranslationFactory::new() | ||
->withLocale('en_US') | ||
->withTitle('Lord of The Rings'), | ||
BookTranslationFactory::new() | ||
->withLocale('pl_PL') | ||
->withTitle('Władca Pierścieni'), | ||
]) | ||
->withAuthor('J.R.R. Tolkien') | ||
->create() | ||
; | ||
|
||
BookFactory::new() | ||
->withTitle('Game of Thrones') | ||
->withAuthor('George R. R. Martin') | ||
->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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?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\BookFactory; | ||
use function Zenstruck\Foundry\Persistence\flush_after; | ||
use Zenstruck\Foundry\Story; | ||
|
||
final class MoreBooksStory extends Story | ||
{ | ||
public function build(): void | ||
{ | ||
flush_after(function () { | ||
foreach (range(1, 22) as $number) { | ||
BookFactory::new() | ||
->withTitle('Book ' . $number) | ||
->create() | ||
; | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.