Skip to content

Commit

Permalink
[DX][Internal] Do not use Alice anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 committed Jan 16, 2025
1 parent 3ad249d commit 72b5dfc
Show file tree
Hide file tree
Showing 26 changed files with 589 additions and 287 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?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\BoardGameBlog\Infrastructure\Foundry\Factory;

use App\BoardGameBlog\Domain\Model\BoardGame;
use App\BoardGameBlog\Domain\ValueObject\BoardGameName;
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;

/**
* @extends PersistentProxyObjectFactory<BoardGame>
*/
final class BoardGameFactory extends PersistentProxyObjectFactory
{
public static function class(): string
{
return BoardGame::class;
}

public function withName(BoardGameName $name): self
{
return $this->with(['name' => $name]);
}

protected function defaults(): array
{
return [
'name' => new BoardGameName(ucfirst(self::faker()->words(2, true))),
];
}

protected function initialize(): static
{
return parent::instantiateWith(function (array $attributes): BoardGame {
return new BoardGame(...$attributes);
});
}
}
43 changes: 43 additions & 0 deletions tests/Application/src/Foundry/Factory/BlogPostFactory.php
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\Factory;

use App\Entity\BlogPost;
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;

/**
* @extends PersistentProxyObjectFactory<BlogPost>
*/
final class BlogPostFactory extends PersistentProxyObjectFactory
{
public static function class(): string
{
return BlogPost::class;
}

public function onDraft(): self
{
return $this->with(['currentPlace' => ['draft' => 1]]);
}

public function reviewed(): self
{
return $this->with(['currentPlace' => ['reviewed' => 1]]);
}

protected function defaults(): array
{
return [];
}
}
47 changes: 47 additions & 0 deletions tests/Application/src/Foundry/Factory/PullRequestFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?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\PullRequest;
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;

/**
* @extends PersistentProxyObjectFactory<PullRequest>
*/
final class PullRequestFactory extends PersistentProxyObjectFactory
{
public static function class(): string
{
return PullRequest::class;
}

public function withCurrentPlace(string $currentPlace): self
{
return $this->with(['currentPlace' => $currentPlace]);
}

protected function defaults(): array
{
return [
'currentPlace' => self::faker()->randomElement([
'start',
'coding',
'test',
'review',
'merged',
'closed',
]),
];
}
}
52 changes: 52 additions & 0 deletions tests/Application/src/Foundry/Factory/ScienceBookFactory.php
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\Author;
use App\Entity\ScienceBook;
use Doctrine\Persistence\Proxy;
use function Zenstruck\Foundry\lazy;
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;

/**
* @extends PersistentProxyObjectFactory<ScienceBook>
*/
final class ScienceBookFactory extends PersistentProxyObjectFactory
{
public static function class(): string
{
return ScienceBook::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
{
return [
'title' => ucfirst(self::faker()->words(2, true)),
'author' => lazy(fn () => AuthorFactory::new()),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?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\Subscription\Foundry\Factory;

use App\Subscription\Entity\Subscription;
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;

/**
* @extends PersistentProxyObjectFactory<Subscription>
*/
final class SubscriptionFactory extends PersistentProxyObjectFactory
{
public static function class(): string
{
return Subscription::class;
}

public function withEmail(string $email): self
{
return $this->with(['email' => $email]);
}

public function accepted(): self
{
return $this->with(['state' => 'accepted']);
}

protected function defaults(): array
{
return [
'email' => self::faker()->email(),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?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\Subscription\Foundry\Story;

use App\Subscription\Foundry\Factory\SubscriptionFactory;
use function Zenstruck\Foundry\Persistence\flush_after;
use Zenstruck\Foundry\Story;

final class DefaultSubscriptionsStory extends Story
{
public function build(): void
{
flush_after(function () {
SubscriptionFactory::new()
->withEmail('marty.mcfly@bttf.com')
->create()
;

SubscriptionFactory::new()
->withEmail('doc.brown@bttf.com')
->create()
;

SubscriptionFactory::new()
->withEmail('biff.tannen@bttf.com')
->accepted()
->create()
;

SubscriptionFactory::new()
->withEmail('lorraine.baines@bttf.com')
->create()
;

SubscriptionFactory::new()
->withEmail('george.mcfly@bttf.com')
->create()
;

SubscriptionFactory::new()
->withEmail('jennifer.parker@bttf.com')
->create()
;
});
}
}
Loading

0 comments on commit 72b5dfc

Please sign in to comment.