From 9f1dfa807065b644f27880bb08e30086468566d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Wed, 15 Jan 2025 17:02:54 +0100 Subject: [PATCH] [DX][Internal] Do not use Alice anymore --- Dockerfile | 2 +- .../Foundry/Factory/BoardGameFactory.php | 48 +++++++ .../src/Foundry/Factory/BlogPostFactory.php | 43 ++++++ .../Foundry/Factory/PullRequestFactory.php | 47 +++++++ .../Foundry/Factory/ScienceBookFactory.php | 54 ++++++++ .../Foundry/Factory/SubscriptionFactory.php | 45 +++++++ .../Story/DefaultSubscriptionsStory.php | 57 ++++++++ .../src/Tests/Controller/BlogPostApiTest.php | 64 ++++++--- .../src/Tests/Controller/BoardGameUiTest.php | 59 +++++---- .../Tests/Controller/PullRequestApiTest.php | 36 +++-- .../Tests/Controller/ScienceBookUiTest.php | 123 ++++++++++++------ .../Controller/SubscriptionJsonApiTest.php | 45 ++++--- .../Tests/Controller/SubscriptionUiTest.php | 107 +++++++-------- .../Controller/SubscriptionXmlApiTest.php | 45 ++++--- .../src/Tests/DataFixtures/ORM/blog-posts.yml | 7 - .../Tests/DataFixtures/ORM/board_games.yml | 11 -- .../src/Tests/DataFixtures/ORM/books.yml | 17 --- .../src/Tests/DataFixtures/ORM/more_books.yml | 6 - .../Tests/DataFixtures/ORM/pull-requests.yml | 3 - .../Tests/DataFixtures/ORM/science_books.yml | 15 --- .../DataFixtures/ORM/single_board_game.yml | 7 - .../DataFixtures/ORM/single_science_book.yml | 9 -- .../DataFixtures/ORM/single_subscription.yml | 3 - .../Tests/DataFixtures/ORM/subscriptions.yml | 14 -- .../Validator/TranslatableValidatorTest.php | 21 ++- 25 files changed, 604 insertions(+), 284 deletions(-) create mode 100644 tests/Application/src/BoardGameBlog/Infrastructure/Foundry/Factory/BoardGameFactory.php create mode 100644 tests/Application/src/Foundry/Factory/BlogPostFactory.php create mode 100644 tests/Application/src/Foundry/Factory/PullRequestFactory.php create mode 100644 tests/Application/src/Foundry/Factory/ScienceBookFactory.php create mode 100644 tests/Application/src/Subscription/Foundry/Factory/SubscriptionFactory.php create mode 100644 tests/Application/src/Subscription/Foundry/Story/DefaultSubscriptionsStory.php delete mode 100644 tests/Application/src/Tests/DataFixtures/ORM/blog-posts.yml delete mode 100644 tests/Application/src/Tests/DataFixtures/ORM/board_games.yml delete mode 100644 tests/Application/src/Tests/DataFixtures/ORM/books.yml delete mode 100644 tests/Application/src/Tests/DataFixtures/ORM/more_books.yml delete mode 100644 tests/Application/src/Tests/DataFixtures/ORM/pull-requests.yml delete mode 100644 tests/Application/src/Tests/DataFixtures/ORM/science_books.yml delete mode 100644 tests/Application/src/Tests/DataFixtures/ORM/single_board_game.yml delete mode 100644 tests/Application/src/Tests/DataFixtures/ORM/single_science_book.yml delete mode 100644 tests/Application/src/Tests/DataFixtures/ORM/single_subscription.yml delete mode 100644 tests/Application/src/Tests/DataFixtures/ORM/subscriptions.yml diff --git a/Dockerfile b/Dockerfile index aff34abd1..4d3c2e154 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,7 @@ COPY . /app WORKDIR /app -ENV PHP_MEMORY_LIMIT=512M +ENV PHP_MEMORY_LIMIT=1G RUN composer global config --no-plugins allow-plugins.symfony/flex true RUN composer global require --no-progress --no-scripts --no-plugins "symfony/flex:^1.10" diff --git a/tests/Application/src/BoardGameBlog/Infrastructure/Foundry/Factory/BoardGameFactory.php b/tests/Application/src/BoardGameBlog/Infrastructure/Foundry/Factory/BoardGameFactory.php new file mode 100644 index 000000000..8ca7157d6 --- /dev/null +++ b/tests/Application/src/BoardGameBlog/Infrastructure/Foundry/Factory/BoardGameFactory.php @@ -0,0 +1,48 @@ + + */ +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); + }); + } +} diff --git a/tests/Application/src/Foundry/Factory/BlogPostFactory.php b/tests/Application/src/Foundry/Factory/BlogPostFactory.php new file mode 100644 index 000000000..0f0afcbd3 --- /dev/null +++ b/tests/Application/src/Foundry/Factory/BlogPostFactory.php @@ -0,0 +1,43 @@ + + */ +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 []; + } +} diff --git a/tests/Application/src/Foundry/Factory/PullRequestFactory.php b/tests/Application/src/Foundry/Factory/PullRequestFactory.php new file mode 100644 index 000000000..78d4b9b36 --- /dev/null +++ b/tests/Application/src/Foundry/Factory/PullRequestFactory.php @@ -0,0 +1,47 @@ + + */ +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', + ]), + ]; + } +} diff --git a/tests/Application/src/Foundry/Factory/ScienceBookFactory.php b/tests/Application/src/Foundry/Factory/ScienceBookFactory.php new file mode 100644 index 000000000..fadf54f20 --- /dev/null +++ b/tests/Application/src/Foundry/Factory/ScienceBookFactory.php @@ -0,0 +1,54 @@ + + */ +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 + */ + 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, + ]; + } +} diff --git a/tests/Application/src/Subscription/Foundry/Factory/SubscriptionFactory.php b/tests/Application/src/Subscription/Foundry/Factory/SubscriptionFactory.php new file mode 100644 index 000000000..fe4967494 --- /dev/null +++ b/tests/Application/src/Subscription/Foundry/Factory/SubscriptionFactory.php @@ -0,0 +1,45 @@ + + */ +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(), + ]; + } +} diff --git a/tests/Application/src/Subscription/Foundry/Story/DefaultSubscriptionsStory.php b/tests/Application/src/Subscription/Foundry/Story/DefaultSubscriptionsStory.php new file mode 100644 index 000000000..e4b6ff005 --- /dev/null +++ b/tests/Application/src/Subscription/Foundry/Story/DefaultSubscriptionsStory.php @@ -0,0 +1,57 @@ +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() + ; + }); + } +} diff --git a/tests/Application/src/Tests/Controller/BlogPostApiTest.php b/tests/Application/src/Tests/Controller/BlogPostApiTest.php index 1a7beeac1..8f75e8226 100644 --- a/tests/Application/src/Tests/Controller/BlogPostApiTest.php +++ b/tests/Application/src/Tests/Controller/BlogPostApiTest.php @@ -14,12 +14,19 @@ namespace App\Tests\Controller; use ApiTestCase\JsonApiTestCase; +use App\Foundry\Factory\BlogPostFactory; +use PHPUnit\Framework\Attributes\Test; use Sylius\Bundle\ResourceBundle\ResourceBundleInterface; use Symfony\Component\HttpFoundation\Response; +use Zenstruck\Foundry\Test\Factories; +use Zenstruck\Foundry\Test\ResetDatabase; final class BlogPostApiTest extends JsonApiTestCase { - /** @test */ + use Factories; + use ResetDatabase; + + #[Test] public function it_allows_creating_a_blog_post(): void { $this->markAsSkippedIfNecessary(); @@ -29,62 +36,77 @@ public function it_allows_creating_a_blog_post(): void $this->assertResponse($response, 'blog-posts/create_response', Response::HTTP_CREATED); } - /** @test */ - public function it_allows_reviewing_a_blog_post() + #[Test] + public function it_allows_reviewing_a_blog_post(): void { $this->markAsSkippedIfNecessary(); - $objects = $this->loadFixturesFromFile('blog-posts.yml'); + $blogPost = BlogPostFactory::new() + ->onDraft() + ->create() + ; - $this->client->request('PUT', '/blog-posts/' . $objects['blog_post_draft']->getId() . '/to_review', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); + $this->client->request('PUT', '/blog-posts/' . $blogPost->getId() . '/to_review', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); $response = $this->client->getResponse(); $this->assertResponse($response, 'blog-posts/to_review_response', Response::HTTP_OK); } - /** @test */ - public function it_allows_publishing_a_blog_post() + #[Test] + public function it_allows_publishing_a_blog_post(): void { $this->markAsSkippedIfNecessary(); - $objects = $this->loadFixturesFromFile('blog-posts.yml'); + $blogPost = BlogPostFactory::new() + ->reviewed() + ->create() + ; - $this->client->request('PUT', '/blog-posts/' . $objects['blog_post_reviewed']->getId() . '/publish', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); + $this->client->request('PUT', '/blog-posts/' . $blogPost->getId() . '/publish', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); $response = $this->client->getResponse(); $this->assertResponse($response, 'blog-posts/publish_response', Response::HTTP_OK); } - /** @test */ - public function it_allows_rejecting_a_blog_post() + #[Test] + public function it_allows_rejecting_a_blog_post(): void { $this->markAsSkippedIfNecessary(); - $objects = $this->loadFixturesFromFile('blog-posts.yml'); + $blogPost = BlogPostFactory::new() + ->reviewed() + ->create() + ; - $this->client->request('PUT', '/blog-posts/' . $objects['blog_post_reviewed']->getId() . '/reject', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); + $this->client->request('PUT', '/blog-posts/' . $blogPost->getId() . '/reject', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); $response = $this->client->getResponse(); $this->assertResponse($response, 'blog-posts/reject_response', Response::HTTP_OK); } - /** @test */ - public function it_does_not_allow_to_publish_a_blog_post_with_draft_status() + #[Test] + public function it_does_not_allow_to_publish_a_blog_post_with_draft_status(): void { $this->markAsSkippedIfNecessary(); - $objects = $this->loadFixturesFromFile('blog-posts.yml'); + $blogPost = BlogPostFactory::new() + ->onDraft() + ->create() + ; - $this->client->request('PUT', '/blog-posts/' . $objects['blog_post_draft']->getId() . '/publish', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); + $this->client->request('PUT', '/blog-posts/' . $blogPost->getId() . '/publish', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); $response = $this->client->getResponse(); $this->assertResponseCode($response, Response::HTTP_BAD_REQUEST); } - /** @test */ - public function it_does_not_allow_to_reject_a_blog_post_with_draft_status() + #[Test] + public function it_does_not_allow_to_reject_a_blog_post_with_draft_status(): void { $this->markAsSkippedIfNecessary(); - $objects = $this->loadFixturesFromFile('blog-posts.yml'); + $blogPost = BlogPostFactory::new() + ->onDraft() + ->create() + ; - $this->client->request('PUT', '/blog-posts/' . $objects['blog_post_draft']->getId() . '/reject', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); + $this->client->request('PUT', '/blog-posts/' . $blogPost->getId() . '/reject', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); $response = $this->client->getResponse(); $this->assertResponseCode($response, Response::HTTP_BAD_REQUEST); } diff --git a/tests/Application/src/Tests/Controller/BoardGameUiTest.php b/tests/Application/src/Tests/Controller/BoardGameUiTest.php index 743922090..207dbd179 100644 --- a/tests/Application/src/Tests/Controller/BoardGameUiTest.php +++ b/tests/Application/src/Tests/Controller/BoardGameUiTest.php @@ -16,30 +16,48 @@ use ApiTestCase\ApiTestCase; use App\BoardGameBlog\Domain\Model\BoardGame; use App\BoardGameBlog\Domain\Repository\BoardGameRepositoryInterface; +use App\BoardGameBlog\Domain\ValueObject\BoardGameName; +use App\BoardGameBlog\Infrastructure\Foundry\Factory\BoardGameFactory; use Coduo\PHPMatcher\Backtrace\VoidBacktrace; use Coduo\PHPMatcher\Matcher; use Symfony\Component\HttpFoundation\Response; +use Zenstruck\Foundry\Test\Factories; +use Zenstruck\Foundry\Test\ResetDatabase; final class BoardGameUiTest extends ApiTestCase { + use Factories; + use ResetDatabase; + /** @test */ public function it_allows_showing_a_board_game(): void { - $boardGames = $this->loadFixturesFromFile('board_games.yml'); + $boardGame = BoardGameFactory::new() + ->withName(new BoardGameName('Ticket to Ride')) + ->create() + ; - $this->client->request('GET', '/admin/board-games/' . $boardGames['ticket_to_ride']->id()); + $this->client->request('GET', '/admin/board-games/' . $boardGame->id()); $response = $this->client->getResponse(); $this->assertResponseCode($response, Response::HTTP_OK); $content = $response->getContent(); - $this->assertStringContainsString(sprintf('ID: %s', $boardGames['ticket_to_ride']->id()), $content); + $this->assertStringContainsString(sprintf('ID: %s', $boardGame->id()), $content); $this->assertStringContainsString('Name: Ticket to Ride', $content); } /** @test */ public function it_allows_browsing_board_games(): void { - $boardGames = $this->loadFixturesFromFile('board_games.yml'); + $stoneAgeBoardGame = BoardGameFactory::new() + ->withName(new BoardGameName('Stone Age')) + ->create() + ; + + $ticketToRideBoardGame = BoardGameFactory::new() + ->withName(new BoardGameName('Ticket to Ride')) + ->create() + ; $this->client->request('GET', '/admin/board-games'); $response = $this->client->getResponse(); @@ -48,21 +66,19 @@ public function it_allows_browsing_board_games(): void $content = $response->getContent(); $this->assertStringContainsString('Stone Age', $content); - $this->assertStringContainsString(sprintf('Show', $boardGames['stone_age']->id()), $content); - $this->assertStringContainsString(sprintf('Edit', $boardGames['stone_age']->id()), $content); - $this->assertStringContainsString(sprintf('
', $boardGames['stone_age']->id()), $content); + $this->assertStringContainsString(sprintf('Show', $stoneAgeBoardGame->id()), $content); + $this->assertStringContainsString(sprintf('Edit', $stoneAgeBoardGame->id()), $content); + $this->assertStringContainsString(sprintf('', $stoneAgeBoardGame->id()), $content); $this->assertStringContainsString('Ticket to Ride', $content); - $this->assertStringContainsString(sprintf('Show', $boardGames['ticket_to_ride']->id()), $content); - $this->assertStringContainsString(sprintf('Edit', $boardGames['ticket_to_ride']->id()), $content); - $this->assertStringContainsString(sprintf('', $boardGames['ticket_to_ride']->id()), $content); + $this->assertStringContainsString(sprintf('Show', $ticketToRideBoardGame->id()), $content); + $this->assertStringContainsString(sprintf('Edit', $ticketToRideBoardGame->id()), $content); + $this->assertStringContainsString(sprintf('', $ticketToRideBoardGame->id()), $content); } /** @test */ public function it_allows_accessing_board_game_creation_page(): void { - $this->loadFixturesFromFile('board_games.yml'); - $this->client->request('GET', '/admin/board-games/new'); $this->assertResponseCode($this->client->getResponse(), Response::HTTP_OK); @@ -71,8 +87,6 @@ public function it_allows_accessing_board_game_creation_page(): void /** @test */ public function it_allows_creating_a_board_game(): void { - $this->loadFixturesFromFile('board_games.yml'); - $this->client->request('GET', '/admin/board-games/new'); $this->client->submitForm('Create', [ 'board_game[name]' => 'Puerto Rico', @@ -90,8 +104,6 @@ public function it_allows_creating_a_board_game(): void /** @test */ public function it_does_not_allow_to_create_a_board_game_if_there_is_a_validation_error(): void { - $this->loadFixturesFromFile('board_games.yml'); - $this->client->request('GET', '/admin/board-games/new'); $this->client->submitForm('Create', [ 'board_game[name]' => null, @@ -103,28 +115,25 @@ public function it_does_not_allow_to_create_a_board_game_if_there_is_a_validatio /** @test */ public function it_allows_updating_a_board_game(): void { - $boardGames = $this->loadFixturesFromFile('board_games.yml'); + $boardGame = BoardGameFactory::createOne(); - $this->client->request('GET', '/admin/board-games/' . $boardGames['stone_age']->id() . '/edit'); + $this->client->request('GET', '/admin/board-games/' . $boardGame->id() . '/edit'); $this->client->submitForm('Save changes', [ 'board_game[name]' => 'Puerto Rico', ]); $this->assertResponseRedirects(null, expectedCode: Response::HTTP_FOUND); - /** @var BoardGame $boardGame */ - $boardGame = static::getContainer()->get(BoardGameRepositoryInterface::class)->findOneBy(['name.value' => 'Puerto Rico']); - - $this->assertNotNull($boardGame); + $boardGame->_refresh(); $this->assertSame('Puerto Rico', (string) $boardGame->name()); } /** @test */ public function it_does_not_allow_to_update_a_board_game_if_there_is_a_validation_error(): void { - $boardGames = $this->loadFixturesFromFile('board_games.yml'); + $boardGame = BoardGameFactory::createOne(); - $this->client->request('GET', '/admin/board-games/' . $boardGames['stone_age']->id() . '/edit'); + $this->client->request('GET', '/admin/board-games/' . $boardGame->id() . '/edit'); $this->client->submitForm('Save changes', [ 'board_game[name]' => null, ]); @@ -135,7 +144,7 @@ public function it_does_not_allow_to_update_a_board_game_if_there_is_a_validatio /** @test */ public function it_allows_deleting_a_board_game(): void { - $this->loadFixturesFromFile('single_board_game.yml'); + BoardGameFactory::createOne(); $this->client->request('GET', '/admin/board-games'); $this->client->submitForm('Delete'); diff --git a/tests/Application/src/Tests/Controller/PullRequestApiTest.php b/tests/Application/src/Tests/Controller/PullRequestApiTest.php index a6047a6bb..2d69ed2b4 100644 --- a/tests/Application/src/Tests/Controller/PullRequestApiTest.php +++ b/tests/Application/src/Tests/Controller/PullRequestApiTest.php @@ -14,11 +14,18 @@ namespace App\Tests\Controller; use ApiTestCase\JsonApiTestCase; +use App\Foundry\Factory\PullRequestFactory; +use PHPUnit\Framework\Attributes\Test; use Symfony\Component\HttpFoundation\Response; +use Zenstruck\Foundry\Test\Factories; +use Zenstruck\Foundry\Test\ResetDatabase; final class PullRequestApiTest extends JsonApiTestCase { - /** @test */ + use Factories; + use ResetDatabase; + + #[Test] public function it_allows_creating_a_pull_request(): void { $this->client->request('POST', '/pull-requests/', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); @@ -26,32 +33,41 @@ public function it_allows_creating_a_pull_request(): void $this->assertResponse($response, 'pull-requests/create_response', Response::HTTP_CREATED); } - /** @test */ + #[Test] public function it_allows_submitting_a_pull_request(): void { - $objects = $this->loadFixturesFromFile('pull-requests.yml'); + $pullRequest = PullRequestFactory::new() + ->withCurrentPlace('start') + ->create() + ; - $this->client->request('PUT', '/pull-requests/' . $objects['pull_request_start']->getId() . '/submit', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); + $this->client->request('PUT', '/pull-requests/' . $pullRequest->getId() . '/submit', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); $response = $this->client->getResponse(); $this->assertResponse($response, 'pull-requests/submit_response', Response::HTTP_OK); } - /** @test */ + #[Test] public function it_allows_waiting_for_review_a_pull_request(): void { - $objects = $this->loadFixturesFromFile('pull-requests.yml'); + $pullRequest = PullRequestFactory::new() + ->withCurrentPlace('test') + ->create() + ; - $this->client->request('PUT', '/pull-requests/' . $objects['pull_request_test']->getId() . '/wait_for_review', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); + $this->client->request('PUT', '/pull-requests/' . $pullRequest->getId() . '/wait_for_review', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); $response = $this->client->getResponse(); $this->assertResponse($response, 'pull-requests/wait_for_review_response', Response::HTTP_OK); } - /** @test */ + #[Test] public function it_does_not_allow_to_wait_for_review_on_pull_request_with_start_status(): void { - $objects = $this->loadFixturesFromFile('pull-requests.yml'); + $pullRequest = PullRequestFactory::new() + ->withCurrentPlace('start') + ->create() + ; - $this->client->request('PUT', '/pull-requests/' . $objects['pull_request_start']->getId() . '/wait_for_review', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); + $this->client->request('PUT', '/pull-requests/' . $pullRequest->getId() . '/wait_for_review', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); $response = $this->client->getResponse(); $this->assertResponseCode($response, Response::HTTP_BAD_REQUEST); } diff --git a/tests/Application/src/Tests/Controller/ScienceBookUiTest.php b/tests/Application/src/Tests/Controller/ScienceBookUiTest.php index 3d35474b0..de1e24af1 100644 --- a/tests/Application/src/Tests/Controller/ScienceBookUiTest.php +++ b/tests/Application/src/Tests/Controller/ScienceBookUiTest.php @@ -15,31 +15,65 @@ use ApiTestCase\ApiTestCase; use App\Entity\ScienceBook; +use App\Foundry\Factory\AuthorFactory; +use App\Foundry\Factory\ScienceBookFactory; use Coduo\PHPMatcher\Backtrace\VoidBacktrace; use Coduo\PHPMatcher\Matcher; +use PHPUnit\Framework\Attributes\Test; use Symfony\Component\HttpFoundation\Response; +use Zenstruck\Foundry\Test\Factories; +use Zenstruck\Foundry\Test\ResetDatabase; final class ScienceBookUiTest extends ApiTestCase { - /** @test */ + use Factories; + use ResetDatabase; + + #[Test] public function it_allows_showing_a_book(): void { - $scienceBooks = $this->loadFixturesFromFile('science_books.yml'); - - $this->client->request('GET', '/science-books/' . $scienceBooks['science-book1']->getId()); + $scienceBook = ScienceBookFactory::new() + ->withTitle('A Brief History of Time') + ->withAuthor( + AuthorFactory::new() + ->withFirstName('Stephen') + ->withLastName('Hawking'), + ) + ->create() + ; + + $this->client->request('GET', '/science-books/' . $scienceBook->getId()); $response = $this->client->getResponse(); $this->assertResponseCode($response, Response::HTTP_OK); $content = $response->getContent(); - $this->assertStringContainsString(sprintf('ID: %d', $scienceBooks['science-book1']->getId()), $content); + $this->assertStringContainsString(sprintf('ID: %d', $scienceBook->getId()), $content); $this->assertStringContainsString('Title: A Brief History of Time', $content); $this->assertStringContainsString('Author: Stephen Hawking', $content); } - /** @test */ + #[Test] public function it_allows_indexing_books(): void { - $scienceBooks = $this->loadFixturesFromFile('science_books.yml'); + $firstBook = ScienceBookFactory::new() + ->withTitle('A Brief History of Time') + ->withAuthor( + AuthorFactory::new() + ->withFirstName('Stephen') + ->withLastName('Hawking'), + ) + ->create() + ; + + $secondBook = ScienceBookFactory::new() + ->withTitle('The Future of Humanity') + ->withAuthor( + AuthorFactory::new() + ->withFirstName('Michio') + ->withLastName('Kaku'), + ) + ->create() + ; $this->client->request('GET', '/science-books/'); $response = $this->client->getResponse(); @@ -48,24 +82,22 @@ public function it_allows_indexing_books(): void $content = $response->getContent(); $this->assertStringContainsString('

Books

', $content); $this->assertStringContainsString( - sprintf('%dA Brief History of TimeStephen Hawking', $scienceBooks['science-book1']->getId()), + sprintf('%dA Brief History of TimeStephen Hawking', $firstBook->getId()), $content, ); $this->assertStringContainsString( - sprintf('%dThe Future of HumanityMichio Kaku', $scienceBooks['science-book2']->getId()), + sprintf('%dThe Future of HumanityMichio Kaku', $secondBook->getId()), $content, ); } - /** @test */ + #[Test] public function it_allows_creating_a_book(): void { $newBookTitle = 'The Book of Why'; $newBookAuthorFirstName = 'Judea'; $newBookAuthorLastName = 'Pearl'; - $this->loadFixturesFromFile('science_books.yml'); - $this->client->request('GET', '/science-books/new'); $this->client->submitForm('Create', [ 'science_book[title]' => $newBookTitle, @@ -84,14 +116,12 @@ public function it_allows_creating_a_book(): void $this->assertSame($newBookAuthorLastName, $book->getAuthorLastName()); } - /** @test */ + #[Test] public function it_does_not_allow_to_create_a_book_if_there_is_a_validation_error(): void { $newBookTitle = 'The Book of Why'; $newBookAuthorLastName = 'Pearl'; - $this->loadFixturesFromFile('science_books.yml'); - $this->client->request('GET', '/science-books/new'); $this->client->submitForm('Create', [ 'science_book[title]' => $newBookTitle, @@ -106,16 +136,16 @@ public function it_does_not_allow_to_create_a_book_if_there_is_a_validation_erro $this->assertNull($book); } - /** @test */ + #[Test] public function it_allows_updating_a_book(): void { + $scienceBook = ScienceBookFactory::createOne(); + $newBookTitle = 'The Book of Why'; $newBookAuthorFirstName = 'Judea'; $newBookAuthorLastName = 'Pearl'; - $scienceBooks = $this->loadFixturesFromFile('science_books.yml'); - - $this->client->request('GET', '/science-books/' . $scienceBooks['science-book1']->getId() . '/edit'); + $this->client->request('GET', '/science-books/' . $scienceBook->getId() . '/edit'); $this->client->submitForm('Save changes', [ 'science_book[title]' => $newBookTitle, 'science_book[author][firstName]' => $newBookAuthorFirstName, @@ -124,24 +154,21 @@ public function it_allows_updating_a_book(): void $this->assertResponseRedirects(null, expectedCode: Response::HTTP_FOUND); - /** @var ScienceBook $book */ - $book = static::getContainer()->get('app.repository.science_book')->findOneBy(['title' => $newBookTitle]); - - $this->assertNotNull($book); - $this->assertSame($newBookTitle, $book->getTitle()); - $this->assertSame($newBookAuthorFirstName, $book->getAuthorFirstName()); - $this->assertSame($newBookAuthorLastName, $book->getAuthorLastName()); + $scienceBook->_refresh(); + $this->assertSame($newBookTitle, $scienceBook->getTitle()); + $this->assertSame($newBookAuthorFirstName, $scienceBook->getAuthorFirstName()); + $this->assertSame($newBookAuthorLastName, $scienceBook->getAuthorLastName()); } - /** @test */ + #[Test] public function it_does_not_allow_to_update_a_book_if_there_is_a_validation_error(): void { + $scienceBook = ScienceBookFactory::createOne(); + $newBookTitle = 'The Book of Why'; $newBookAuthorLastName = 'Pearl'; - $scienceBooks = $this->loadFixturesFromFile('science_books.yml'); - - $this->client->request('GET', '/science-books/' . $scienceBooks['science-book1']->getId() . '/edit'); + $this->client->request('GET', '/science-books/' . $scienceBook->getId() . '/edit'); $this->client->submitForm('Save changes', [ 'science_book[title]' => $newBookTitle, 'science_book[author][firstName]' => null, @@ -150,16 +177,14 @@ public function it_does_not_allow_to_update_a_book_if_there_is_a_validation_erro $this->assertResponseCode($this->client->getResponse(), Response::HTTP_UNPROCESSABLE_ENTITY); - /** @var ScienceBook $book */ - $book = static::getContainer()->get('app.repository.science_book')->findOneBy(['title' => $newBookTitle]); - - $this->assertNull($book); + $scienceBook->_refresh(); + $this->assertNotEquals($newBookTitle, $scienceBook->getTitle()); } - /** @test */ + #[Test] public function it_allows_deleting_a_book(): void { - $this->loadFixturesFromFile('single_science_book.yml'); + ScienceBookFactory::createOne(); $this->client->request('GET', '/science-books/'); $this->client->submitForm('Delete'); @@ -172,10 +197,28 @@ public function it_allows_deleting_a_book(): void $this->assertEmpty($books); } - /** @test */ + #[Test] public function it_allows_filtering_books(): void { - $scienceBooks = $this->loadFixturesFromFile('science_books.yml'); + $firstBook = ScienceBookFactory::new() + ->withTitle('A Brief History of Time') + ->withAuthor( + AuthorFactory::new() + ->withFirstName('Stephen') + ->withLastName('Hawking'), + ) + ->create() + ; + + $secondBook = ScienceBookFactory::new() + ->withTitle('The Future of Humanity') + ->withAuthor( + AuthorFactory::new() + ->withFirstName('Michio') + ->withLastName('Kaku'), + ) + ->create() + ; $this->client->request('GET', '/science-books/?criteria[search][value]=history of time'); $response = $this->client->getResponse(); @@ -184,11 +227,11 @@ public function it_allows_filtering_books(): void $content = $response->getContent(); $this->assertStringContainsString('

Books

', $content); $this->assertStringContainsString( - sprintf('%dA Brief History of TimeStephen Hawking', $scienceBooks['science-book1']->getId()), + sprintf('%dA Brief History of TimeStephen Hawking', $firstBook->getId()), $content, ); $this->assertStringNotContainsString( - sprintf('%dThe Future of HumanityMichio Kaku', $scienceBooks['science-book2']->getId()), + sprintf('%dThe Future of HumanityMichio Kaku', $secondBook->getId()), $content, ); } diff --git a/tests/Application/src/Tests/Controller/SubscriptionJsonApiTest.php b/tests/Application/src/Tests/Controller/SubscriptionJsonApiTest.php index 089c0b77d..00bb40ec9 100644 --- a/tests/Application/src/Tests/Controller/SubscriptionJsonApiTest.php +++ b/tests/Application/src/Tests/Controller/SubscriptionJsonApiTest.php @@ -15,27 +15,38 @@ use ApiTestCase\JsonApiTestCase; use App\Kernel; +use App\Subscription\Foundry\Factory\SubscriptionFactory; +use App\Subscription\Foundry\Story\DefaultSubscriptionsStory; use Coduo\PHPMatcher\Backtrace\VoidBacktrace; use Coduo\PHPMatcher\Matcher; +use PHPUnit\Framework\Attributes\Test; use Symfony\Component\HttpFoundation\Response; +use Zenstruck\Foundry\Test\Factories; +use Zenstruck\Foundry\Test\ResetDatabase; final class SubscriptionJsonApiTest extends JsonApiTestCase { - /** @test */ + use Factories; + use ResetDatabase; + + #[Test] public function it_allows_showing_a_subscription(): void { - $subscriptions = $this->loadFixturesFromFile('subscriptions.yml'); + $subscription = SubscriptionFactory::new() + ->withEmail('marty.mcfly@bttf.com') + ->create() + ; - $this->client->request('GET', '/ajax/subscriptions/' . $subscriptions['subscription_marty']->getId()); + $this->client->request('GET', '/ajax/subscriptions/' . $subscription->getId()); $response = $this->client->getResponse(); $this->assertResponse($response, 'subscriptions/show_response', Response::HTTP_OK); } - /** @test */ + #[Test] public function it_allows_indexing_subscriptions(): void { - $this->loadFixturesFromFile('subscriptions.yml'); + DefaultSubscriptionsStory::load(); $this->client->request('GET', '/ajax/subscriptions'); $response = $this->client->getResponse(); @@ -43,7 +54,7 @@ public function it_allows_indexing_subscriptions(): void $this->assertResponse($response, 'subscriptions/index_response', Response::HTTP_OK); } - /** @test */ + #[Test] public function it_allows_creating_a_subscription(): void { $data = @@ -58,11 +69,9 @@ public function it_allows_creating_a_subscription(): void $this->assertResponse($response, 'subscriptions/create_response', Response::HTTP_CREATED); } - /** @test */ + #[Test] public function it_does_not_allow_to_create_a_subscription_if_there_is_a_validation_error(): void { - $this->loadFixturesFromFile('subscriptions.yml'); - $data = <<assertResponse($this->client->getResponse(), $file, Response::HTTP_UNPROCESSABLE_ENTITY); } - /** @test */ + #[Test] public function it_allows_updating_a_subscription(): void { - $subscriptions = $this->loadFixturesFromFile('subscriptions.yml'); + $subscription = SubscriptionFactory::createOne(); $data = <<client->request('PUT', '/ajax/subscriptions/' . $subscriptions['subscription_marty']->getId(), [], [], ['CONTENT_TYPE' => 'application/json'], $data); + $this->client->request('PUT', '/ajax/subscriptions/' . $subscription->getId(), [], [], ['CONTENT_TYPE' => 'application/json'], $data); $response = $this->client->getResponse(); $this->assertResponseCode($response, Response::HTTP_NO_CONTENT); } - /** @test */ + #[Test] public function it_does_not_allow_to_update_a_subscription_if_there_is_a_validation_error(): void { - $subscriptions = $this->loadFixturesFromFile('subscriptions.yml'); + $subscription = SubscriptionFactory::createOne(); $data = <<client->request('PUT', '/ajax/subscriptions/' . $subscriptions['subscription_marty']->getId(), [], [], ['CONTENT_TYPE' => 'application/json'], $data); + $this->client->request('PUT', '/ajax/subscriptions/' . $subscription->getId(), [], [], ['CONTENT_TYPE' => 'application/json'], $data); $file = Kernel::VERSION_ID >= 60400 ? 'subscriptions/update_validation' : 'subscriptions/update_validation_legacy'; $this->assertResponse($this->client->getResponse(), $file, Response::HTTP_UNPROCESSABLE_ENTITY); } - /** @test */ + #[Test] public function it_allows_removing_a_subscription(): void { - $subscriptions = $this->loadFixturesFromFile('subscriptions.yml'); + $subscription = SubscriptionFactory::createOne(); - $this->client->request('DELETE', '/ajax/subscriptions/' . $subscriptions['subscription_marty']->getId()); + $this->client->request('DELETE', '/ajax/subscriptions/' . $subscription->getId()); $response = $this->client->getResponse(); $this->assertResponseCode($response, Response::HTTP_NO_CONTENT); } diff --git a/tests/Application/src/Tests/Controller/SubscriptionUiTest.php b/tests/Application/src/Tests/Controller/SubscriptionUiTest.php index 052c98d1a..fcab3a05b 100644 --- a/tests/Application/src/Tests/Controller/SubscriptionUiTest.php +++ b/tests/Application/src/Tests/Controller/SubscriptionUiTest.php @@ -15,31 +15,45 @@ use ApiTestCase\ApiTestCase; use App\Subscription\Entity\Subscription; +use App\Subscription\Foundry\Factory\SubscriptionFactory; +use App\Subscription\Foundry\Story\DefaultSubscriptionsStory; use Coduo\PHPMatcher\Backtrace\VoidBacktrace; use Coduo\PHPMatcher\Matcher; +use PHPUnit\Framework\Attributes\Test; use Symfony\Component\HttpFoundation\Response; +use Zenstruck\Foundry\Test\Factories; +use Zenstruck\Foundry\Test\ResetDatabase; final class SubscriptionUiTest extends ApiTestCase { - /** @test */ + use Factories; + use ResetDatabase; + + #[Test] public function it_allows_showing_a_subscription(): void { - $subscriptions = $this->loadFixturesFromFile('subscriptions.yml'); + $subscription = SubscriptionFactory::new() + ->withEmail('marty.mcfly@bttf.com') + ->create() + ; - $this->client->request('GET', '/admin/subscriptions/' . $subscriptions['subscription_marty']->getId()); + $this->client->request('GET', '/admin/subscriptions/' . $subscription->getId()); $response = $this->client->getResponse(); $this->assertResponseCode($response, Response::HTTP_OK); $content = $response->getContent(); - $this->assertStringContainsString(sprintf('ID: %s', $subscriptions['subscription_marty']->getId()), $content); + $this->assertStringContainsString(sprintf('ID: %s', $subscription->getId()), $content); $this->assertStringContainsString('Email: marty.mcfly@bttf.com', $content); $this->assertStringContainsString('Foo: bar', $content); } - /** @test */ + #[Test] public function it_allows_browsing_subscriptions(): void { - $subscriptions = $this->loadFixturesFromFile('subscriptions.yml'); + DefaultSubscriptionsStory::load(); + + $docBrownSubscription = SubscriptionFactory::find(['email' => 'doc.brown@bttf.com']); + $biffTannenSubscription = SubscriptionFactory::find(['email' => 'biff.tannen@bttf.com']); $this->client->request('GET', '/admin/subscriptions'); $response = $this->client->getResponse(); @@ -53,20 +67,20 @@ public function it_allows_browsing_subscriptions(): void } $this->assertStringContainsString('doc.brown@bttf.com', $content); - $this->assertStringContainsString(sprintf('Show', $subscriptions['subscription_doc']->getId()), $content); - $this->assertStringContainsString(sprintf('Edit', $subscriptions['subscription_doc']->getId()), $content); - $this->assertStringContainsString(sprintf('', $subscriptions['subscription_doc']->getId()), $content); + $this->assertStringContainsString(sprintf('Show', $docBrownSubscription->getId()), $content); + $this->assertStringContainsString(sprintf('Edit', $docBrownSubscription->getId()), $content); + $this->assertStringContainsString(sprintf('', $docBrownSubscription->getId()), $content); $this->assertStringContainsString('biff.tannen@bttf.com', $content); - $this->assertStringContainsString(sprintf('Show', $subscriptions['subscription_biff']->getId()), $content); - $this->assertStringContainsString(sprintf('Edit', $subscriptions['subscription_biff']->getId()), $content); - $this->assertStringContainsString(sprintf('', $subscriptions['subscription_biff']->getId()), $content); + $this->assertStringContainsString(sprintf('Show', $biffTannenSubscription->getId()), $content); + $this->assertStringContainsString(sprintf('Edit', $biffTannenSubscription->getId()), $content); + $this->assertStringContainsString(sprintf('', $biffTannenSubscription->getId()), $content); } - /** @test */ + #[Test] public function it_allows_browsing_subscriptions_with_page_limit(): void { - $this->loadFixturesFromFile('subscriptions.yml'); + DefaultSubscriptionsStory::load(); $this->client->request('GET', '/admin/subscriptions?limit=3'); $response = $this->client->getResponse(); @@ -79,10 +93,10 @@ public function it_allows_browsing_subscriptions_with_page_limit(): void } } - /** @test */ + #[Test] public function it_allows_browsing_subscriptions_with_grid_limits(): void { - $this->loadFixturesFromFile('subscriptions.yml'); + DefaultSubscriptionsStory::load(); $this->client->request('GET', '/admin/subscriptions'); $response = $this->client->getResponse(); @@ -95,11 +109,9 @@ public function it_allows_browsing_subscriptions_with_grid_limits(): void } } - /** @test */ + #[Test] public function it_allows_creating_a_subscription(): void { - $this->loadFixturesFromFile('subscriptions.yml'); - $this->client->request('GET', '/admin/subscriptions/new'); $response = $this->client->getResponse(); @@ -120,11 +132,9 @@ public function it_allows_creating_a_subscription(): void $this->assertSame('biff.tannen@bttf.com', (string) $subscription->email); } - /** @test */ + #[Test] public function it_does_not_allow_to_create_a_subscription_if_there_is_a_validation_error(): void { - $this->loadFixturesFromFile('subscriptions.yml'); - $this->client->request('GET', '/admin/subscriptions/new'); $this->client->submitForm('Create', [ 'subscription[email]' => null, @@ -133,31 +143,28 @@ public function it_does_not_allow_to_create_a_subscription_if_there_is_a_validat $this->assertResponseCode($this->client->getResponse(), Response::HTTP_UNPROCESSABLE_ENTITY); } - /** @test */ + #[Test] public function it_allows_updating_a_subscription(): void { - $subscriptions = $this->loadFixturesFromFile('subscriptions.yml'); + $subscription = SubscriptionFactory::createOne(); - $this->client->request('GET', '/admin/subscriptions/' . $subscriptions['subscription_marty']->getId() . '/edit'); + $this->client->request('GET', '/admin/subscriptions/' . $subscription->getId() . '/edit'); $this->client->submitForm('Save changes', [ 'subscription[email]' => 'biff.tannen@bttf.com', ]); $this->assertResponseRedirects(null, expectedCode: Response::HTTP_FOUND); - /** @var Subscription $subscription */ - $subscription = static::getContainer()->get('app.repository.subscription')->findOneBy(['email' => 'biff.tannen@bttf.com']); - - $this->assertNotNull($subscription); + $subscription->_refresh(); $this->assertSame('biff.tannen@bttf.com', (string) $subscription->email); } - /** @test */ + #[Test] public function it_does_not_allow_to_update_a_subscription_if_there_is_a_validation_error(): void { - $subscriptions = $this->loadFixturesFromFile('subscriptions.yml'); + $subscription = SubscriptionFactory::createOne(); - $this->client->request('GET', '/admin/subscriptions/' . $subscriptions['subscription_marty']->getId() . '/edit'); + $this->client->request('GET', '/admin/subscriptions/' . $subscription->getId() . '/edit'); $this->client->submitForm('Save changes', [ 'subscription[email]' => null, ]); @@ -165,10 +172,10 @@ public function it_does_not_allow_to_update_a_subscription_if_there_is_a_validat $this->assertResponseCode($this->client->getResponse(), Response::HTTP_UNPROCESSABLE_ENTITY); } - /** @test */ + #[Test] public function it_allows_deleting_a_subscription(): void { - $this->loadFixturesFromFile('single_subscription.yml'); + SubscriptionFactory::createOne(); $this->client->request('GET', '/admin/subscriptions'); $this->client->submitForm('Delete'); @@ -181,10 +188,10 @@ public function it_allows_deleting_a_subscription(): void $this->assertEmpty($subscriptions); } - /** @test */ + #[Test] public function it_allows_deleting_multiple_subscriptions(): void { - $this->loadFixturesFromFile('subscriptions.yml'); + DefaultSubscriptionsStory::load(); $this->client->request('GET', '/admin/subscriptions?limit=10'); $this->client->submitForm('Bulk delete'); @@ -197,44 +204,38 @@ public function it_allows_deleting_multiple_subscriptions(): void $this->assertEmpty($subscriptions); } - /** @test */ + #[Test] public function it_allows_accepting_a_subscription(): void { - $this->loadFixturesFromFile('single_subscription.yml'); + $subscription = SubscriptionFactory::createOne(); $this->client->request('GET', '/admin/subscriptions'); $this->client->submitForm('Accept'); $this->assertResponseRedirects(null, expectedCode: Response::HTTP_FOUND); - /** @var Subscription $subscription */ - $subscription = static::getContainer()->get('app.repository.subscription')->findOneBy(['email' => 'marty.mcfly@bttf.com']); + $subscription->_refresh(); - $this->assertNotNull($subscription); $this->assertSame('accepted', $subscription->getState()); } - /** @test */ + #[Test] public function it_allows_accepting_multiple_subscription(): void { - $this->loadFixturesFromFile('subscriptions.yml'); + DefaultSubscriptionsStory::load(); + $martyMcFly = SubscriptionFactory::find(['email' => 'marty.mcfly@bttf.com']); + $docBrown = SubscriptionFactory::find(['email' => 'doc.brown@bttf.com']); $this->client->request('GET', '/admin/subscriptions?limit=10'); $this->client->submitForm('Bulk accept'); $this->assertResponseRedirects(null, expectedCode: Response::HTTP_FOUND); - /** @var Subscription $firstSubscription */ - $firstSubscription = static::getContainer()->get('app.repository.subscription')->findOneBy(['email' => 'marty.mcfly@bttf.com']); - - /** @var Subscription $secondSubscription */ - $secondSubscription = static::getContainer()->get('app.repository.subscription')->findOneBy(['email' => 'doc.brown@bttf.com']); - - $this->assertNotNull($firstSubscription); - $this->assertSame('accepted', $firstSubscription->getState()); + $martyMcFly->_refresh(); + $this->assertSame('accepted', $martyMcFly->getState()); - $this->assertNotNull($secondSubscription); - $this->assertSame('accepted', $secondSubscription->getState()); + $docBrown->_refresh(); + $this->assertSame('accepted', $docBrown->getState()); } protected function buildMatcher(): Matcher diff --git a/tests/Application/src/Tests/Controller/SubscriptionXmlApiTest.php b/tests/Application/src/Tests/Controller/SubscriptionXmlApiTest.php index d6a33acec..dc804ae32 100644 --- a/tests/Application/src/Tests/Controller/SubscriptionXmlApiTest.php +++ b/tests/Application/src/Tests/Controller/SubscriptionXmlApiTest.php @@ -14,27 +14,38 @@ namespace App\Tests\Controller; use App\Kernel; +use App\Subscription\Foundry\Factory\SubscriptionFactory; +use App\Subscription\Foundry\Story\DefaultSubscriptionsStory; use Coduo\PHPMatcher\Backtrace\VoidBacktrace; use Coduo\PHPMatcher\Matcher; +use PHPUnit\Framework\Attributes\Test; use Symfony\Component\HttpFoundation\Response; +use Zenstruck\Foundry\Test\Factories; +use Zenstruck\Foundry\Test\ResetDatabase; final class SubscriptionXmlApiTest extends XmlApiTestCase { - /** @test */ + use Factories; + use ResetDatabase; + + #[Test] public function it_allows_showing_a_subscription(): void { - $subscriptions = $this->loadFixturesFromFile('subscriptions.yml'); + $subscription = SubscriptionFactory::new() + ->withEmail('marty.mcfly@bttf.com') + ->create() + ; - $this->client->request('GET', '/ajax/subscriptions/' . $subscriptions['subscription_marty']->getId()); + $this->client->request('GET', '/ajax/subscriptions/' . $subscription->getId()); $response = $this->client->getResponse(); $this->assertResponse($response, 'subscriptions/show_response', Response::HTTP_OK); } - /** @test */ + #[Test] public function it_allows_indexing_subscriptions(): void { - $this->loadFixturesFromFile('subscriptions.yml'); + DefaultSubscriptionsStory::load(); $this->client->request('GET', '/ajax/subscriptions'); $response = $this->client->getResponse(); @@ -42,7 +53,7 @@ public function it_allows_indexing_subscriptions(): void $this->assertResponse($response, 'subscriptions/index_response', Response::HTTP_OK); } - /** @test */ + #[Test] public function it_allows_creating_a_subscription(): void { $data = <<assertResponse($response, 'subscriptions/create_response', Response::HTTP_CREATED); } - /** @test */ + #[Test] public function it_does_not_allow_to_create_a_subscription_if_there_is_a_validation_error(): void { - $this->loadFixturesFromFile('subscriptions.yml'); - $data = << @@ -76,10 +85,10 @@ public function it_does_not_allow_to_create_a_subscription_if_there_is_a_validat $this->assertResponse($this->client->getResponse(), $file, Response::HTTP_UNPROCESSABLE_ENTITY); } - /** @test */ + #[Test] public function it_allows_updating_a_subscription(): void { - $subscriptions = $this->loadFixturesFromFile('subscriptions.yml'); + $subscription = SubscriptionFactory::createOne(); $data = << @@ -88,15 +97,15 @@ public function it_allows_updating_a_subscription(): void EOT; - $this->client->request(method: 'PUT', uri: '/ajax/subscriptions/' . $subscriptions['subscription_marty']->getId(), server: self::$headersWithContentType, content: $data); + $this->client->request(method: 'PUT', uri: '/ajax/subscriptions/' . $subscription->getId(), server: self::$headersWithContentType, content: $data); $response = $this->client->getResponse(); $this->assertResponseCode($response, Response::HTTP_NO_CONTENT); } - /** @test */ + #[Test] public function it_does_not_allow_to_update_a_subscription_if_there_is_a_validation_error(): void { - $subscriptions = $this->loadFixturesFromFile('subscriptions.yml'); + $subscription = SubscriptionFactory::createOne(); $data = << @@ -105,19 +114,19 @@ public function it_does_not_allow_to_update_a_subscription_if_there_is_a_validat EOT; - $this->client->request(method: 'PUT', uri: '/ajax/subscriptions/' . $subscriptions['subscription_marty']->getId(), server: self::$headersWithContentType, content: $data); + $this->client->request(method: 'PUT', uri: '/ajax/subscriptions/' . $subscription->getId(), server: self::$headersWithContentType, content: $data); $file = Kernel::VERSION_ID >= 60400 ? 'subscriptions/update_validation' : 'subscriptions/update_validation_legacy'; $this->assertResponse($this->client->getResponse(), $file, Response::HTTP_UNPROCESSABLE_ENTITY); } - /** @test */ + #[Test] public function it_allows_removing_a_subscription(): void { - $subscriptions = $this->loadFixturesFromFile('subscriptions.yml'); + $subscription = SubscriptionFactory::createOne(); - $this->client->request('DELETE', '/ajax/subscriptions/' . $subscriptions['subscription_marty']->getId()); + $this->client->request('DELETE', '/ajax/subscriptions/' . $subscription->getId()); $response = $this->client->getResponse(); $this->assertResponseCode($response, Response::HTTP_NO_CONTENT); } diff --git a/tests/Application/src/Tests/DataFixtures/ORM/blog-posts.yml b/tests/Application/src/Tests/DataFixtures/ORM/blog-posts.yml deleted file mode 100644 index 467a997d5..000000000 --- a/tests/Application/src/Tests/DataFixtures/ORM/blog-posts.yml +++ /dev/null @@ -1,7 +0,0 @@ -App\Entity\BlogPost: - blog_post_draft: - currentPlace: - draft: 1 - blog_post_reviewed: - currentPlace: - reviewed: 1 diff --git a/tests/Application/src/Tests/DataFixtures/ORM/board_games.yml b/tests/Application/src/Tests/DataFixtures/ORM/board_games.yml deleted file mode 100644 index 48880014c..000000000 --- a/tests/Application/src/Tests/DataFixtures/ORM/board_games.yml +++ /dev/null @@ -1,11 +0,0 @@ -App\BoardGameBlog\Domain\ValueObject\BoardGameName: - stone_age_name: - __construct: ['Stone Age'] - ticket_to_ride_name: - __construct: ['Ticket to Ride'] - -App\BoardGameBlog\Domain\Model\BoardGame: - stone_age: - __construct: ['@stone_age_name'] - ticket_to_ride: - __construct: ['@ticket_to_ride_name'] diff --git a/tests/Application/src/Tests/DataFixtures/ORM/books.yml b/tests/Application/src/Tests/DataFixtures/ORM/books.yml deleted file mode 100644 index 2bfda8010..000000000 --- a/tests/Application/src/Tests/DataFixtures/ORM/books.yml +++ /dev/null @@ -1,17 +0,0 @@ -App\Entity\Book: - book1: - fallbackLocale: en_US - currentLocale: en_US - title: "Lord of The Rings" - author: "J.R.R. Tolkien" - book2: - fallbackLocale: en_US - currentLocale: en_US - title: "Game of Thrones" - author: "George R. R. Martin" - -App\Entity\BookTranslation: - book1_pl_PL: - title: "Władca Pierścieni" - locale: "pl_PL" - translatable: "@book1" diff --git a/tests/Application/src/Tests/DataFixtures/ORM/more_books.yml b/tests/Application/src/Tests/DataFixtures/ORM/more_books.yml deleted file mode 100644 index 58708c0aa..000000000 --- a/tests/Application/src/Tests/DataFixtures/ORM/more_books.yml +++ /dev/null @@ -1,6 +0,0 @@ -App\Entity\Book: - book{1..22}: - fallbackLocale: en_US - currentLocale: en_US - title: Book - author: diff --git a/tests/Application/src/Tests/DataFixtures/ORM/pull-requests.yml b/tests/Application/src/Tests/DataFixtures/ORM/pull-requests.yml deleted file mode 100644 index 5f8941a60..000000000 --- a/tests/Application/src/Tests/DataFixtures/ORM/pull-requests.yml +++ /dev/null @@ -1,3 +0,0 @@ -App\Entity\PullRequest: - pull_request_{start, coding, test, review, merged, closed}: - currentPlace: diff --git a/tests/Application/src/Tests/DataFixtures/ORM/science_books.yml b/tests/Application/src/Tests/DataFixtures/ORM/science_books.yml deleted file mode 100644 index 8538fd61d..000000000 --- a/tests/Application/src/Tests/DataFixtures/ORM/science_books.yml +++ /dev/null @@ -1,15 +0,0 @@ -App\Entity\ScienceBook: - science-book1: - title: "A Brief History of Time" - author: "@stephen-hawking" - science-book2: - title: "The Future of Humanity" - author: "@michio-kaku" - -App\Entity\Author: - stephen-hawking: - firstName: "Stephen" - lastName: "Hawking" - michio-kaku: - firstName: "Michio" - lastName: "Kaku" diff --git a/tests/Application/src/Tests/DataFixtures/ORM/single_board_game.yml b/tests/Application/src/Tests/DataFixtures/ORM/single_board_game.yml deleted file mode 100644 index 54a976bcb..000000000 --- a/tests/Application/src/Tests/DataFixtures/ORM/single_board_game.yml +++ /dev/null @@ -1,7 +0,0 @@ -App\BoardGameBlog\Domain\ValueObject\BoardGameName: - ticket_to_ride_name: - __construct: ['Ticket to Ride'] - -App\BoardGameBlog\Domain\Model\BoardGame: - ticket_to_ride: - __construct: ['@ticket_to_ride_name'] diff --git a/tests/Application/src/Tests/DataFixtures/ORM/single_science_book.yml b/tests/Application/src/Tests/DataFixtures/ORM/single_science_book.yml deleted file mode 100644 index 7351dcc9f..000000000 --- a/tests/Application/src/Tests/DataFixtures/ORM/single_science_book.yml +++ /dev/null @@ -1,9 +0,0 @@ -App\Entity\ScienceBook: - science-book1: - title: "A Brief History of Time" - author: "@stephen-hawking" - -App\Entity\Author: - stephen-hawking: - firstName: "Stephen" - lastName: "Hawking" diff --git a/tests/Application/src/Tests/DataFixtures/ORM/single_subscription.yml b/tests/Application/src/Tests/DataFixtures/ORM/single_subscription.yml deleted file mode 100644 index 9df86d1ab..000000000 --- a/tests/Application/src/Tests/DataFixtures/ORM/single_subscription.yml +++ /dev/null @@ -1,3 +0,0 @@ -App\Subscription\Entity\Subscription: - subscription_marty: - email: 'marty.mcfly@bttf.com' diff --git a/tests/Application/src/Tests/DataFixtures/ORM/subscriptions.yml b/tests/Application/src/Tests/DataFixtures/ORM/subscriptions.yml deleted file mode 100644 index fcb0769cd..000000000 --- a/tests/Application/src/Tests/DataFixtures/ORM/subscriptions.yml +++ /dev/null @@ -1,14 +0,0 @@ -App\Subscription\Entity\Subscription: - subscription_marty: - email: 'marty.mcfly@bttf.com' - subscription_doc: - email: 'doc.brown@bttf.com' - subscription_biff: - email: 'biff.tannen@bttf.com' - state: accepted - subscription_lorraine: - email: 'lorraine.baines@bttf.com' - subscription_george: - email: 'george.mcfly@bttf.com' - subscription_jennifer: - email: 'jennifer.parker@bttf.com' diff --git a/tests/Application/src/Tests/Validator/TranslatableValidatorTest.php b/tests/Application/src/Tests/Validator/TranslatableValidatorTest.php index 626bbc1a0..07061052f 100644 --- a/tests/Application/src/Tests/Validator/TranslatableValidatorTest.php +++ b/tests/Application/src/Tests/Validator/TranslatableValidatorTest.php @@ -13,16 +13,23 @@ namespace App\Tests\Validator; -use ApiTestCase\JsonApiTestCase; use App\Entity\Book; +use App\Foundry\Story\DefaultBooksStory; +use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Validator\Validator\ValidatorInterface; +use Zenstruck\Foundry\Test\Factories; +use Zenstruck\Foundry\Test\ResetDatabase; -final class TranslatableValidatorTest extends JsonApiTestCase +final class TranslatableValidatorTest extends KernelTestCase { + use Factories; + use ResetDatabase; + /** @test */ public function it_fails_validation_with_empty_locale(): void { - $this->loadFixturesFromFile('books.yml'); + DefaultBooksStory::load(); + $book = $this->getBookBy(); $book->getTranslation('pl_PL')->setLocale(''); @@ -34,7 +41,8 @@ public function it_fails_validation_with_empty_locale(): void /** @test */ public function it_fails_validation_with_invalid_locale(): void { - $this->loadFixturesFromFile('books.yml'); + DefaultBooksStory::load(); + $book = $this->getBookBy(); $book->getTranslation('pl_PL')->setLocale('invalid'); @@ -46,7 +54,8 @@ public function it_fails_validation_with_invalid_locale(): void /** @test */ public function it_fails_validation_with_not_unique_locale(): void { - $this->loadFixturesFromFile('books.yml'); + DefaultBooksStory::load(); + $book = $this->getBookBy(); $book->getTranslation('pl_PL')->setLocale('en_US'); @@ -57,7 +66,7 @@ public function it_fails_validation_with_not_unique_locale(): void private function getValidator(): ValidatorInterface { - return self::getContainer()->get('validator'); + return self::getContainer()->get(ValidatorInterface::class); } private function getBookBy(array $criteria = ['author' => 'J.R.R. Tolkien']): ?Book