From 818060b6d56467be3e97a6d25c308f54443b43b1 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 --- composer.json | 3 +- tests/ApiTestCase.php | 51 ++ .../Application/config/packages/doctrine.yaml | 9 + .../config/packages/zenstruck_foundry.yaml | 5 + .../src/Tests/Controller/BlogPostApiTest.php | 84 ++- .../src/Tests/Controller/BookApiTest.php | 527 ++++++++++++++++-- .../src/Tests/Controller/ComicBookApiTest.php | 272 ++++++--- .../src/Tests/Controller/GedmoApiTest.php | 30 +- .../Tests/Controller/PullRequestApiTest.php | 56 +- .../Controller/SubscriptionJsonApiTest.php | 225 ++++++-- .../Controller/SubscriptionXmlApiTest.php | 242 ++++++-- .../src/Tests/Responses/.gitignore | 0 .../Responses/blog-posts/create_response.json | 6 - .../blog-posts/publish_response.json | 6 - .../Responses/blog-posts/reject_response.json | 6 - .../blog-posts/to_review_response.json | 6 - .../Responses/books/create_response.json | 5 - .../Tests/Responses/books/index_response.json | 31 -- .../books/paginated_index_response.json | 77 --- .../Tests/Responses/books/show_response.json | 5 - .../comic-books/create_response.json | 8 - .../Responses/comic-books/index_response.json | 37 -- .../Responses/comic-books/show_response.json | 8 - .../versioned_create_response.json | 6 - .../comic-books/versioned_index_response.json | 33 -- .../comic-books/versioned_show_response.json | 6 - .../Responses/gedmos/create_response.json | 5 - .../pull-requests/create_response.json | 4 - .../pull-requests/submit_response.json | 4 - .../wait_for_review_response.json | 4 - .../subscriptions/create_response.json | 4 - .../subscriptions/create_response.xml | 4 - .../subscriptions/create_validation.json | 16 - .../subscriptions/create_validation.xml | 15 - .../create_validation_legacy.json | 15 - .../create_validation_legacy.xml | 14 - .../subscriptions/index_response.json | 36 -- .../subscriptions/index_response.xml | 35 -- .../subscriptions/show_response.json | 4 - .../Responses/subscriptions/show_response.xml | 5 - .../subscriptions/update_validation.json | 16 - .../subscriptions/update_validation.xml | 15 - .../update_validation_legacy.json | 15 - .../update_validation_legacy.xml | 14 - tests/PurgeDatabaseTrait.php | 36 ++ 45 files changed, 1293 insertions(+), 712 deletions(-) create mode 100644 tests/ApiTestCase.php create mode 100644 tests/Application/config/packages/zenstruck_foundry.yaml create mode 100644 tests/Application/src/Tests/Responses/.gitignore delete mode 100644 tests/Application/src/Tests/Responses/blog-posts/create_response.json delete mode 100644 tests/Application/src/Tests/Responses/blog-posts/publish_response.json delete mode 100644 tests/Application/src/Tests/Responses/blog-posts/reject_response.json delete mode 100644 tests/Application/src/Tests/Responses/blog-posts/to_review_response.json delete mode 100644 tests/Application/src/Tests/Responses/books/create_response.json delete mode 100644 tests/Application/src/Tests/Responses/books/index_response.json delete mode 100644 tests/Application/src/Tests/Responses/books/paginated_index_response.json delete mode 100644 tests/Application/src/Tests/Responses/books/show_response.json delete mode 100644 tests/Application/src/Tests/Responses/comic-books/create_response.json delete mode 100644 tests/Application/src/Tests/Responses/comic-books/index_response.json delete mode 100644 tests/Application/src/Tests/Responses/comic-books/show_response.json delete mode 100644 tests/Application/src/Tests/Responses/comic-books/versioned_create_response.json delete mode 100644 tests/Application/src/Tests/Responses/comic-books/versioned_index_response.json delete mode 100644 tests/Application/src/Tests/Responses/comic-books/versioned_show_response.json delete mode 100644 tests/Application/src/Tests/Responses/gedmos/create_response.json delete mode 100644 tests/Application/src/Tests/Responses/pull-requests/create_response.json delete mode 100644 tests/Application/src/Tests/Responses/pull-requests/submit_response.json delete mode 100644 tests/Application/src/Tests/Responses/pull-requests/wait_for_review_response.json delete mode 100644 tests/Application/src/Tests/Responses/subscriptions/create_response.json delete mode 100644 tests/Application/src/Tests/Responses/subscriptions/create_response.xml delete mode 100644 tests/Application/src/Tests/Responses/subscriptions/create_validation.json delete mode 100644 tests/Application/src/Tests/Responses/subscriptions/create_validation.xml delete mode 100644 tests/Application/src/Tests/Responses/subscriptions/create_validation_legacy.json delete mode 100644 tests/Application/src/Tests/Responses/subscriptions/create_validation_legacy.xml delete mode 100644 tests/Application/src/Tests/Responses/subscriptions/index_response.json delete mode 100644 tests/Application/src/Tests/Responses/subscriptions/index_response.xml delete mode 100644 tests/Application/src/Tests/Responses/subscriptions/show_response.json delete mode 100644 tests/Application/src/Tests/Responses/subscriptions/show_response.xml delete mode 100644 tests/Application/src/Tests/Responses/subscriptions/update_validation.json delete mode 100644 tests/Application/src/Tests/Responses/subscriptions/update_validation.xml delete mode 100644 tests/Application/src/Tests/Responses/subscriptions/update_validation_legacy.json delete mode 100644 tests/Application/src/Tests/Responses/subscriptions/update_validation_legacy.xml create mode 100644 tests/PurgeDatabaseTrait.php diff --git a/composer.json b/composer.json index 7b74a17d6..4ed6a0c4e 100644 --- a/composer.json +++ b/composer.json @@ -130,7 +130,8 @@ "Sylius\\Component\\Resource\\spec\\": "src/Component/legacy/spec/", "Sylius\\Component\\Resource\\Tests\\": "src/Component/legacy/tests/", "Sylius\\Resource\\Tests\\": "src/Component/tests/", - "App\\": "tests/Application/src/" + "App\\": "tests/Application/src/", + "Tests\\": "tests/" } }, "scripts": { diff --git a/tests/ApiTestCase.php b/tests/ApiTestCase.php new file mode 100644 index 000000000..6d5a24cb6 --- /dev/null +++ b/tests/ApiTestCase.php @@ -0,0 +1,51 @@ +client = self::createClient(); + } + + #[Before] + protected static function _createMatcher(): Matcher + { + return (new MatcherFactory())->createMatcher(new VoidBacktrace()); + } + + protected function assertResponseMatchesPattern(string $pattern): void + { + $response = $this->client->getResponse(); + $content = $response->getContent(); + + self::assertMatchesPattern($pattern, $content); + } +} diff --git a/tests/Application/config/packages/doctrine.yaml b/tests/Application/config/packages/doctrine.yaml index 5c208b673..0de09a3aa 100644 --- a/tests/Application/config/packages/doctrine.yaml +++ b/tests/Application/config/packages/doctrine.yaml @@ -3,6 +3,9 @@ doctrine: driver: "%database_driver%" path: "%database_path%" charset: UTF8 + + profiling_collect_backtrace: '%kernel.debug%' + use_savepoints: true orm: auto_generate_proxy_classes: true naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware @@ -24,3 +27,9 @@ doctrine: type: attribute dir: '%kernel.project_dir%/src/Subscription/Entity' prefix: 'App\Subscription\Entity' + +when@test: + doctrine: + dbal: + # "TEST_TOKEN" is typically set by ParaTest + dbname_suffix: '_test%env(default::TEST_TOKEN)%' diff --git a/tests/Application/config/packages/zenstruck_foundry.yaml b/tests/Application/config/packages/zenstruck_foundry.yaml new file mode 100644 index 000000000..e3ed04b46 --- /dev/null +++ b/tests/Application/config/packages/zenstruck_foundry.yaml @@ -0,0 +1,5 @@ +when@dev: &dev + # See full configuration: https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#full-default-bundle-configuration + zenstruck_foundry: + +when@test: *dev diff --git a/tests/Application/src/Tests/Controller/BlogPostApiTest.php b/tests/Application/src/Tests/Controller/BlogPostApiTest.php index 3b2269755..3769a16a1 100644 --- a/tests/Application/src/Tests/Controller/BlogPostApiTest.php +++ b/tests/Application/src/Tests/Controller/BlogPostApiTest.php @@ -13,16 +13,18 @@ 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 Tests\ApiTestCase; +use Tests\PurgeDatabaseTrait; use Zenstruck\Foundry\Test\Factories; -final class BlogPostApiTest extends JsonApiTestCase +final class BlogPostApiTest extends ApiTestCase { use Factories; + use PurgeDatabaseTrait; #[Test] public function it_allows_creating_a_blog_post(): void @@ -30,8 +32,21 @@ public function it_allows_creating_a_blog_post(): void $this->markAsSkippedIfNecessary(); $this->client->request('POST', '/blog-posts/', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); - $response = $this->client->getResponse(); - $this->assertResponse($response, 'blog-posts/create_response', Response::HTTP_CREATED); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_CREATED); + $this->assertResponseHeaderSame('content-type', 'application/json'); + + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "id": @integer@, + "current_place": { + "draft": 1 + } + } + JSON + ); } #[Test] @@ -45,8 +60,21 @@ public function it_allows_reviewing_a_blog_post(): void ; $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); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/json'); + + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "id": @integer@, + "current_place": { + "reviewed": 1 + } + } + JSON + ); } #[Test] @@ -60,8 +88,21 @@ public function it_allows_publishing_a_blog_post(): void ; $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); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/json'); + + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "id": @integer@, + "current_place": { + "published": 1 + } + } + JSON + ); } #[Test] @@ -75,8 +116,21 @@ public function it_allows_rejecting_a_blog_post(): void ; $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); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/json'); + + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "id": @integer@, + "current_place": { + "rejected": 1 + } + } + JSON + ); } #[Test] @@ -90,8 +144,9 @@ public function it_does_not_allow_to_publish_a_blog_post_with_draft_status(): vo ; $this->client->request('PUT', '/blog-posts/' . $blogPost->getId() . '/publish', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); - $response = $this->client->getResponse(); - $this->assertResponseCode($response, Response::HTTP_BAD_REQUEST); + + $this->assertResponseStatusCodeSame(Response::HTTP_BAD_REQUEST); + $this->assertResponseHeaderSame('content-type', 'application/json'); } #[Test] @@ -105,8 +160,9 @@ public function it_does_not_allow_to_reject_a_blog_post_with_draft_status(): voi ; $this->client->request('PUT', '/blog-posts/' . $blogPost->getId() . '/reject', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); - $response = $this->client->getResponse(); - $this->assertResponseCode($response, Response::HTTP_BAD_REQUEST); + + $this->assertResponseStatusCodeSame(Response::HTTP_BAD_REQUEST); + $this->assertResponseHeaderSame('content-type', 'application/json'); } private function markAsSkippedIfNecessary(): void diff --git a/tests/Application/src/Tests/Controller/BookApiTest.php b/tests/Application/src/Tests/Controller/BookApiTest.php index 17c951217..2e5c64467 100644 --- a/tests/Application/src/Tests/Controller/BookApiTest.php +++ b/tests/Application/src/Tests/Controller/BookApiTest.php @@ -13,18 +13,21 @@ namespace App\Tests\Controller; -use ApiTestCase\JsonApiTestCase; +use App\Entity\BookTranslation; use App\Foundry\Factory\BookFactory; use App\Foundry\Factory\BookTranslationFactory; use App\Foundry\Story\DefaultBooksStory; use App\Foundry\Story\MoreBooksStory; use PHPUnit\Framework\Attributes\Test; use Symfony\Component\HttpFoundation\Response; +use Tests\ApiTestCase; +use Tests\PurgeDatabaseTrait; use Zenstruck\Foundry\Test\Factories; -class BookApiTest extends JsonApiTestCase +class BookApiTest extends ApiTestCase { use Factories; + use PurgeDatabaseTrait; #[Test] public function it_allows_creating_a_book(): void @@ -44,8 +47,20 @@ public function it_allows_creating_a_book(): void EOT; $this->client->request('POST', '/books/', [], [], ['CONTENT_TYPE' => 'application/json'], $data); - $response = $this->client->getResponse(); - $this->assertResponse($response, 'books/create_response', Response::HTTP_CREATED); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_CREATED); + $this->assertResponseHeaderSame('content-type', 'application/json'); + + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "id": @integer@, + "title":"Star Wars: Dark Disciple", + "author":"Christie Golden" + } + JSON + ); } #[Test] @@ -54,23 +69,34 @@ public function it_allows_updating_a_book(): void $book = BookFactory::createOne(); $data = -<<client->request('PUT', '/books/' . $book->getId(), [], [], ['CONTENT_TYPE' => 'application/json'], $data); - $response = $this->client->getResponse(); - $this->assertResponseCode($response, Response::HTTP_NO_CONTENT); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_NO_CONTENT); + + $book->_refresh(); + + $enUsTranslation = $book->getTranslation('en_US'); + $plPLTranslation = $book->getTranslation('pl_PL'); + $this->assertInstanceOf(BookTranslation::class, $enUsTranslation); + $this->assertInstanceOf(BookTranslation::class, $plPLTranslation); + $this->assertEquals('Star Wars: Dark Disciple', $enUsTranslation->getTitle()); + $this->assertEquals('Gwiezdne Wojny: Mroczny Uczeń', $plPLTranslation->getTitle()); + $this->assertEquals('Christie Golden', $book->getAuthor()); } #[Test] @@ -79,25 +105,35 @@ public function it_allows_updating_partial_information_about_a_book(): void $book = BookFactory::createOne(); $data = - <<client->request('PATCH', '/books/' . $book->getId(), [], [], ['CONTENT_TYPE' => 'application/json'], $data); - $response = $this->client->getResponse(); - $this->assertResponseCode($response, Response::HTTP_NO_CONTENT); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_NO_CONTENT); + + $book->_refresh(); + + $this->assertEquals('Christie Golden', $book->getAuthor()); } #[Test] public function it_allows_removing_a_book(): void { $book = BookFactory::createOne(); + $bookId = $book->getId(); $this->client->request('DELETE', '/books/' . $book->getId()); - $response = $this->client->getResponse(); - $this->assertResponseCode($response, Response::HTTP_NO_CONTENT); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_NO_CONTENT); + + $deletedBook = $this->getContainer()->get('app.repository.book')->find($bookId); + $this->assertNull($deletedBook); } #[Test] @@ -119,8 +155,20 @@ public function it_allows_showing_a_book(): void ; $this->client->request('GET', '/books/' . $book->getId()); - $response = $this->client->getResponse(); - $this->assertResponse($response, 'books/show_response'); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/json'); + + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "id": @integer@, + "title":"Lord of The Rings", + "author":"J.R.R. Tolkien" + } + JSON + ); } #[Test] @@ -131,8 +179,12 @@ public function it_allows_indexing_books(): void DefaultBooksStory::load(); $this->client->request('GET', '/books/'); - $response = $this->client->getResponse(); - $this->assertResponse($response, 'books/index_response'); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/json'); + + $this->assertResponseMatchesDefaultBooksIndex(); } #[Test] @@ -143,8 +195,12 @@ public function it_allows_paginating_the_index_of_books(): void MoreBooksStory::load(); $this->client->request('GET', '/books/', ['page' => 2]); - $response = $this->client->getResponse(); - $this->assertResponse($response, 'books/paginated_index_response'); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/json'); + + $this->assertResponseMatchesMoreBooksIndexPage2(); } #[Test] @@ -152,37 +208,41 @@ public function it_does_not_allow_showing_resource_if_it_not_exists(): void { $this->markAsSkippedIfNecessary(); - DefaultBooksStory::load(); - $this->client->request('GET', '/books/3'); - $response = $this->client->getResponse(); - $this->assertResponseCode($response, Response::HTTP_NOT_FOUND); + + $this->assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND); } #[Test] - public function it_does_not_apply_sorting_for_un_existing_field(): void + public function it_does_not_apply_sorting_for_non_existing_field(): void { $this->markAsSkippedIfNecessary(); MoreBooksStory::load(); $this->client->request('GET', '/sortable-books/', ['sorting' => ['name' => 'DESC']]); - $response = $this->client->getResponse(); - $this->assertResponseCode($response, Response::HTTP_OK); + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/json'); + + $this->assertResponseMatchesMoreBooksIndex(); } #[Test] - public function it_does_not_apply_filtering_for_un_existing_field(): void + public function it_does_not_apply_filtering_for_non_existing_field(): void { $this->markAsSkippedIfNecessary(); MoreBooksStory::load(); $this->client->request('GET', '/filterable-books/', ['criteria' => ['name' => 'John']]); - $response = $this->client->getResponse(); - $this->assertResponseCode($response, Response::HTTP_OK); + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/json'); + + $this->assertResponseMatchesMoreBooksIndex(); } #[Test] @@ -193,9 +253,88 @@ public function it_applies_sorting_for_existing_field(): void MoreBooksStory::load(); $this->client->request('GET', '/sortable-books/', ['sorting' => ['id' => 'DESC']]); - $response = $this->client->getResponse(); - $this->assertResponseCode($response, Response::HTTP_OK); + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "page": 1, + "limit": 10, + "pages": 3, + "total": 22, + "_links": { + "first": { + "href": "/sortable-books/?sorting%5Bid%5D=DESC&page=1&limit=10" + }, + "last": { + "href": "/sortable-books/?sorting%5Bid%5D=DESC&page=3&limit=10" + }, + "next": { + "href": "/sortable-books/?sorting%5Bid%5D=DESC&page=2&limit=10" + }, + "self": { + "href": "/sortable-books/?sorting%5Bid%5D=DESC&page=1&limit=10" + } + }, + "_embedded": { + "items": [ + { + "author": "@string@", + "id": @integer@, + "title": "Book 22" + }, + { + "author": "@string@", + "id": @integer@, + "title": "Book 21" + }, + { + "author": "@string@", + "id": @integer@, + "title": "Book 20" + }, + { + "author": "@string@", + "id": @integer@, + "title": "Book 19" + }, + { + "author": "@string@", + "id": @integer@, + "title": "Book 18" + }, + { + "author": "@string@", + "id": @integer@, + "title": "Book 17" + }, + { + "author": "@string@", + "id": @integer@, + "title": "Book 16" + }, + { + "author": "@string@", + "id": @integer@, + "title": "Book 15" + }, + { + "author": "@string@", + "id": @integer@, + "title": "Book 14" + }, + { + "author": "@string@", + "id": @integer@, + "title": "Book 13" + } + ] + } + } + JSON + ); } #[Test] @@ -204,11 +343,42 @@ public function it_applies_filtering_for_existing_field(): void $this->markAsSkippedIfNecessary(); MoreBooksStory::load(); + BookFactory::new()->withAuthor('J.R.R. Tolkien')->create(); $this->client->request('GET', '/filterable-books/', ['criteria' => ['author' => 'J.R.R. Tolkien']]); - $response = $this->client->getResponse(); - $this->assertResponseCode($response, Response::HTTP_OK); + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "page": 1, + "limit": 10, + "pages": 1, + "total": 1, + "_links": { + "self": { + "href": "\/filterable-books\/?criteria%5Bauthor%5D=J.R.R.%20Tolkien&page=1&limit=10" + }, + "first": { + "href": "\/filterable-books\/?criteria%5Bauthor%5D=J.R.R.%20Tolkien&page=1&limit=10" + }, + "last": { + "href": "\/filterable-books\/?criteria%5Bauthor%5D=J.R.R.%20Tolkien&page=1&limit=10" + } + }, + "_embedded": { + "items": [ + { + "id": @integer@, + "author": "J.R.R. Tolkien" + } + ] + } + } + JSON + ); } #[Test] @@ -217,20 +387,33 @@ public function it_allows_creating_a_book_via_custom_factory(): void $this->markAsSkippedIfNecessary(); $data = - <<client->request('POST', '/create-custom-book', [], [], ['CONTENT_TYPE' => 'application/json'], $data); - $response = $this->client->getResponse(); - $this->assertResponse($response, 'books/create_response', Response::HTTP_CREATED); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_CREATED); + $this->assertResponseHeaderSame('content-type', 'application/json'); + + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "id": @integer@, + "title":"Star Wars: Dark Disciple", + "author":"Christie Golden" + } + JSON + ); } #[Test] @@ -241,8 +424,12 @@ public function it_allows_indexing_books_via_custom_repository(): void DefaultBooksStory::load(); $this->client->request('GET', '/find-custom-books'); - $response = $this->client->getResponse(); - $this->assertResponse($response, 'books/index_response'); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/json'); + + $this->assertResponseMatchesDefaultBooksIndex(); } #[Test] @@ -253,13 +440,231 @@ public function it_allows_showing_a_book_via_custom_repository(): void DefaultBooksStory::load(); $this->client->request('GET', '/find-custom-book'); - $response = $this->client->getResponse(); - $this->assertResponse($response, 'books/show_response'); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/json'); + + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "id": @integer@, + "title":"Lord of The Rings", + "author":"J.R.R. Tolkien" + } + JSON + ); + } + + private function assertResponseMatchesDefaultBooksIndex(): void + { + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "page": 1, + "limit": 10, + "pages": 1, + "total": 2, + "_links": { + "self": { + "href": "@string@" + }, + "first": { + "href": "@string@" + }, + "last": { + "href": "@string@" + } + }, + "_embedded": { + "items": [ + { + "id": @integer@, + "title": "Lord of The Rings", + "author": "J.R.R. Tolkien" + }, + { + "id": @integer@, + "title": "Game of Thrones", + "author": "George R. R. Martin" + } + ] + } + } + JSON + ); + } + + private function assertResponseMatchesMoreBooksIndex(): void + { + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "page": 1, + "limit": 10, + "pages": 3, + "total": 22, + "_links": { + "self": { + "href": "@string@" + }, + "first": { + "href": "@string@" + }, + "last": { + "href": "@string@" + }, + "next": { + "href": "@string@" + } + }, + "_embedded": { + "items": [ + { + "id": @integer@, + "title": "Book 1", + "author": "@string@" + }, + { + "id": @integer@, + "title": "Book 2", + "author": "@string@" + }, + { + "id": @integer@, + "title": "Book 3", + "author": "@string@" + }, + { + "id": @integer@, + "title": "Book 4", + "author": "@string@" + }, + { + "id": @integer@, + "title": "Book 5", + "author": "@string@" + }, + { + "id": @integer@, + "title": "Book 6", + "author": "@string@" + }, + { + "id": @integer@, + "title": "Book 7", + "author": "@string@" + }, + { + "id": @integer@, + "title": "Book 8", + "author": "@string@" + }, + { + "id": @integer@, + "title": "Book 9", + "author": "@string@" + }, + { + "id": @integer@, + "title": "Book 10", + "author": "@string@" + } + ] + } + } + JSON + ); + } + + private function assertResponseMatchesMoreBooksIndexPage2(): void + { + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "page": 2, + "limit": 10, + "pages": 3, + "total": 22, + "_links": { + "self": { + "href": "@string@" + }, + "first": { + "href": "@string@" + }, + "last": { + "href": "@string@" + }, + "next": { + "href": "@string@" + }, + "previous": { + "href": "@string@" + } + }, + "_embedded": { + "items": [ + { + "id": @integer@, + "title": "Book 11", + "author": "@string@" + }, + { + "id": @integer@, + "title": "Book 12", + "author": "@string@" + }, + { + "id": @integer@, + "title": "Book 13", + "author": "@string@" + }, + { + "id": @integer@, + "title": "Book 14", + "author": "@string@" + }, + { + "id": @integer@, + "title": "Book 15", + "author": "@string@" + }, + { + "id": @integer@, + "title": "Book 16", + "author": "@string@" + }, + { + "id": @integer@, + "title": "Book 17", + "author": "@string@" + }, + { + "id": @integer@, + "title": "Book 18", + "author": "@string@" + }, + { + "id": @integer@, + "title": "Book 19", + "author": "@string@" + }, + { + "id": @integer@, + "title": "Book 20", + "author": "@string@" + } + ] + } + } + JSON + ); } private function markAsSkippedIfNecessary(): void { - if ('test_without_hateoas' === self::$sharedKernel->getEnvironment()) { + if ('test_without_hateoas' === self::getContainer()->get('kernel')->getEnvironment()) { $this->markTestSkipped(); } } diff --git a/tests/Application/src/Tests/Controller/ComicBookApiTest.php b/tests/Application/src/Tests/Controller/ComicBookApiTest.php index 06f80ef84..db3ba3319 100644 --- a/tests/Application/src/Tests/Controller/ComicBookApiTest.php +++ b/tests/Application/src/Tests/Controller/ComicBookApiTest.php @@ -13,64 +13,91 @@ namespace App\Tests\Controller; -use ApiTestCase\JsonApiTestCase; use App\Foundry\Factory\AuthorFactory; use App\Foundry\Factory\ComicBookFactory; use App\Foundry\Story\DefaultComicBooksStory; +use PHPUnit\Framework\Attributes\Test; use Symfony\Component\HttpFoundation\Response; +use Tests\ApiTestCase; +use Tests\PurgeDatabaseTrait; use Zenstruck\Foundry\Test\Factories; -final class ComicBookApiTest extends JsonApiTestCase +final class ComicBookApiTest extends ApiTestCase { use Factories; + use PurgeDatabaseTrait; - /** - * @test - */ + #[Test] public function it_allows_creating_a_comic_book(): void { $data = -<<client->request('POST', '/v1/comic-books/', [], [], ['CONTENT_TYPE' => 'application/json'], $data); - $response = $this->client->getResponse(); - $this->assertResponse($response, 'comic-books/create_response', Response::HTTP_CREATED); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_CREATED); + $this->assertResponseHeaderSame('content-type', 'application/json'); + + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "id": @integer@, + "author": { + "first_name": "Joe", + "last_name": "Kelly" + }, + "title": "Deadpool #1-69" + } + JSON + ); } - /** - * @test - */ + #[Test] public function it_allows_versioned_creating_a_comic_book(): void { $this->markAsSkippedIfNecessary(); $data = -<<client->request('POST', '/v1.2/comic-books/', [], [], ['CONTENT_TYPE' => 'application/json'], $data); - $response = $this->client->getResponse(); - $this->assertResponse($response, 'comic-books/versioned_create_response', Response::HTTP_CREATED); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_CREATED); + $this->assertResponseHeaderSame('content-type', 'application/json'); + + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "id": @integer@, + "author_first_name": "Joe", + "author_last_name": "Kelly", + "title": "Deadpool #1-69" + } + JSON + ); } - /** - * @test - */ + #[Test] public function it_allows_updating_a_comic_book(): void { $comicBook = self::someComicBook()->create(); @@ -87,13 +114,12 @@ public function it_allows_updating_a_comic_book(): void EOT; $this->client->request('PUT', '/v1/comic-books/' . $comicBook->getId(), [], [], ['CONTENT_TYPE' => 'application/json'], $data); - $response = $this->client->getResponse(); - $this->assertResponseCode($response, Response::HTTP_NO_CONTENT); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_NO_CONTENT); } - /** - * @test - */ + #[Test] public function it_allows_updating_partial_information_about_a_comic_book(): void { $comicBook = self::someComicBook()->create(); @@ -109,37 +135,54 @@ public function it_allows_updating_partial_information_about_a_comic_book(): voi EOT; $this->client->request('PATCH', '/v1/comic-books/' . $comicBook->getId(), [], [], ['CONTENT_TYPE' => 'application/json'], $data); - $response = $this->client->getResponse(); - $this->assertResponseCode($response, Response::HTTP_NO_CONTENT); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_NO_CONTENT); + + $book = $this->getContainer()->get('app.repository.comic_book')->find($comicBook->getId()); + $this->getContainer()->get('doctrine.orm.entity_manager')->refresh($book); + + $this->assertEquals('Joe', $book->getAuthor()->getFirstName()); + $this->assertEquals('Kelly', $book->getAuthor()->getLastName()); } - /** - * @test - */ + #[Test] public function it_allows_removing_a_comic_book(): void { $comicBook = self::someComicBook()->create(); $this->client->request('DELETE', '/v1/comic-books/' . $comicBook->getId()); - $response = $this->client->getResponse(); - $this->assertResponseCode($response, Response::HTTP_NO_CONTENT); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_NO_CONTENT); } - /** - * @test - */ + #[Test] public function it_allows_showing_a_comic_book(): void { $comicBook = self::someComicBook()->create(); $this->client->request('GET', '/v1/comic-books/' . $comicBook->getId()); - $response = $this->client->getResponse(); - $this->assertResponse($response, 'comic-books/show_response'); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/json'); + + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "id": @integer@, + "author": { + "first_name": "Andrea", + "last_name": "Sorrentino" + }, + "title": "Old Man Logan" + } + JSON + ); } - /** - * @test - */ + #[Test] public function it_allows_versioning_of_a_showing_comic_book_serialization(): void { $this->markAsSkippedIfNecessary(); @@ -147,13 +190,24 @@ public function it_allows_versioning_of_a_showing_comic_book_serialization(): vo $comicBook = self::someComicBook()->create(); $this->client->request('GET', '/v1.2/comic-books/' . $comicBook->getId()); - $response = $this->client->getResponse(); - $this->assertResponse($response, 'comic-books/versioned_show_response'); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/json'); + + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "id": @integer@, + "author_first_name": "Andrea", + "author_last_name": "Sorrentino", + "title": "Old Man Logan" + } + JSON + ); } - /** - * @test - */ + #[Test] public function it_allows_indexing_of_comic_books(): void { $this->markAsSkippedIfNecessary(); @@ -161,13 +215,55 @@ public function it_allows_indexing_of_comic_books(): void DefaultComicBooksStory::load(); $this->client->request('GET', '/v1/comic-books/'); - $response = $this->client->getResponse(); - $this->assertResponse($response, 'comic-books/index_response'); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/json'); + + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "page": 1, + "limit": 10, + "pages": 1, + "total": 2, + "_links": { + "self": { + "href": "\/v1\/comic-books\/?page=1&limit=10" + }, + "first": { + "href": "\/v1\/comic-books\/?page=1&limit=10" + }, + "last": { + "href": "\/v1\/comic-books\/?page=1&limit=10" + } + }, + "_embedded": { + "items": [ + { + "id": @integer@, + "author": { + "first_name": "Andrea", + "last_name": "Sorrentino" + }, + "title": "Old Man Logan" + }, + { + "id": @integer@, + "author": { + "first_name": "Brian Michael", + "last_name": "Bendis" + }, + "title": "Civil War II" + } + ] + } + } + JSON + ); } - /** - * @test - */ + #[Test] public function it_allows_versioned_indexing_of_comic_books(): void { $this->markAsSkippedIfNecessary(); @@ -175,23 +271,61 @@ public function it_allows_versioned_indexing_of_comic_books(): void DefaultComicBooksStory::load(); $this->client->request('GET', '/v1.2/comic-books/'); - $response = $this->client->getResponse(); - $this->assertResponse($response, 'comic-books/versioned_index_response'); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/json'); + + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "page": 1, + "limit": 10, + "pages": 1, + "total": 2, + "_links": { + "self": { + "href": "\/v1.2\/comic-books\/?page=1&limit=10" + }, + "first": { + "href": "\/v1.2\/comic-books\/?page=1&limit=10" + }, + "last": { + "href": "\/v1.2\/comic-books\/?page=1&limit=10" + } + }, + "_embedded": { + "items": [ + { + "id": @integer@, + "author_first_name": "Andrea", + "author_last_name": "Sorrentino", + "title": "Old Man Logan" + }, + { + "id": @integer@, + "author_first_name": "Brian Michael", + "author_last_name": "Bendis", + "title": "Civil War II" + } + ] + } + } + JSON + ); } - /** - * @test - */ + #[Test] public function it_does_not_allow_showing_resource_if_it_does_not_exist(): void { $this->client->request('GET', '/v1/comic-books/3'); - $response = $this->client->getResponse(); - $this->assertResponseCode($response, Response::HTTP_NOT_FOUND); + + $this->assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND); } private function markAsSkippedIfNecessary(): void { - if ('test_without_hateoas' === self::$sharedKernel->getEnvironment()) { + if ('test_without_hateoas' === self::getContainer()->get('kernel')->getEnvironment()) { $this->markTestSkipped(); } } diff --git a/tests/Application/src/Tests/Controller/GedmoApiTest.php b/tests/Application/src/Tests/Controller/GedmoApiTest.php index e805ec15b..9dda4fe0b 100644 --- a/tests/Application/src/Tests/Controller/GedmoApiTest.php +++ b/tests/Application/src/Tests/Controller/GedmoApiTest.php @@ -13,15 +13,17 @@ namespace App\Tests\Controller; -use ApiTestCase\JsonApiTestCase; +use PHPUnit\Framework\Attributes\Test; use Symfony\Component\HttpFoundation\Response; +use Tests\ApiTestCase; +use Tests\PurgeDatabaseTrait; -final class GedmoApiTest extends JsonApiTestCase +final class GedmoApiTest extends ApiTestCase { - /** - * @test - */ - public function it_allows_creating_a_comic_book() + use PurgeDatabaseTrait; + + #[Test] + public function it_allows_creating_a_comic_book(): void { $data = <<client->request('POST', '/gedmos/', [], [], ['CONTENT_TYPE' => 'application/json'], $data); - $response = $this->client->getResponse(); - $this->assertResponse($response, 'gedmos/create_response', Response::HTTP_CREATED); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_CREATED); + $this->assertResponseHeaderSame('content-type', 'application/json'); + + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "id": @integer@, + "position": 0, + "extra": "Some info" + } + JSON + ); } } diff --git a/tests/Application/src/Tests/Controller/PullRequestApiTest.php b/tests/Application/src/Tests/Controller/PullRequestApiTest.php index 1d1bbd45d..ec549f65d 100644 --- a/tests/Application/src/Tests/Controller/PullRequestApiTest.php +++ b/tests/Application/src/Tests/Controller/PullRequestApiTest.php @@ -13,22 +13,35 @@ namespace App\Tests\Controller; -use ApiTestCase\JsonApiTestCase; use App\Foundry\Factory\PullRequestFactory; use PHPUnit\Framework\Attributes\Test; use Symfony\Component\HttpFoundation\Response; +use Tests\ApiTestCase; +use Tests\PurgeDatabaseTrait; use Zenstruck\Foundry\Test\Factories; -final class PullRequestApiTest extends JsonApiTestCase +final class PullRequestApiTest extends ApiTestCase { use Factories; + use PurgeDatabaseTrait; #[Test] public function it_allows_creating_a_pull_request(): void { $this->client->request('POST', '/pull-requests/', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); - $response = $this->client->getResponse(); - $this->assertResponse($response, 'pull-requests/create_response', Response::HTTP_CREATED); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_CREATED); + $this->assertResponseHeaderSame('content-type', 'application/json'); + + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "id": @integer@, + "current_place": "start" + } + JSON + ); } #[Test] @@ -40,8 +53,19 @@ public function it_allows_submitting_a_pull_request(): void ; $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); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/json'); + + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "id": @integer@, + "current_place": "test" + } + JSON + ); } #[Test] @@ -53,8 +77,19 @@ public function it_allows_waiting_for_review_a_pull_request(): void ; $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); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/json'); + + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "id": @integer@, + "current_place": "review" + } + JSON + ); } #[Test] @@ -66,7 +101,8 @@ public function it_does_not_allow_to_wait_for_review_on_pull_request_with_start_ ; $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); + + $this->assertResponseStatusCodeSame(Response::HTTP_BAD_REQUEST); + $this->assertResponseHeaderSame('content-type', 'application/json'); } } diff --git a/tests/Application/src/Tests/Controller/SubscriptionJsonApiTest.php b/tests/Application/src/Tests/Controller/SubscriptionJsonApiTest.php index 10e6150c6..c956f15d2 100644 --- a/tests/Application/src/Tests/Controller/SubscriptionJsonApiTest.php +++ b/tests/Application/src/Tests/Controller/SubscriptionJsonApiTest.php @@ -13,19 +13,19 @@ namespace App\Tests\Controller; -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 Tests\ApiTestCase; +use Tests\PurgeDatabaseTrait; use Zenstruck\Foundry\Test\Factories; -final class SubscriptionJsonApiTest extends JsonApiTestCase +final class SubscriptionJsonApiTest extends ApiTestCase { use Factories; + use PurgeDatabaseTrait; #[Test] public function it_allows_showing_a_subscription(): void @@ -36,9 +36,19 @@ public function it_allows_showing_a_subscription(): void ; $this->client->request('GET', '/ajax/subscriptions/' . $subscription->getId()); - $response = $this->client->getResponse(); - $this->assertResponse($response, 'subscriptions/show_response', Response::HTTP_OK); + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/json; charset=utf-8'); + + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "state": "new", + "email": "marty.mcfly@bttf.com" + } + JSON + ); } #[Test] @@ -47,41 +57,140 @@ public function it_allows_indexing_subscriptions(): void DefaultSubscriptionsStory::load(); $this->client->request('GET', '/ajax/subscriptions'); - $response = $this->client->getResponse(); - $this->assertResponse($response, 'subscriptions/index_response', Response::HTTP_OK); + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/json; charset=utf-8'); + + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "items": [ + { + "state": "new", + "email": "marty.mcfly@bttf.com" + }, + { + "state": "new", + "email": "doc.brown@bttf.com" + }, + { + "state": "accepted", + "email": "biff.tannen@bttf.com" + }, + { + "state": "new", + "email": "lorraine.baines@bttf.com" + }, + { + "state": "new", + "email": "george.mcfly@bttf.com" + }, + { + "state": "new", + "email": "jennifer.parker@bttf.com" + } + ], + "pagination": { + "current_page": 1, + "has_previous_page": false, + "has_next_page": false, + "per_page": 10, + "total_items": 6, + "total_pages": 1 + } + } + JSON + ); } #[Test] public function it_allows_creating_a_subscription(): void { $data = - <<client->request('POST', '/ajax/subscriptions', [], [], ['CONTENT_TYPE' => 'application/json'], $data); - $response = $this->client->getResponse(); - $this->assertResponse($response, 'subscriptions/create_response', Response::HTTP_CREATED); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_CREATED); + $this->assertResponseHeaderSame('content-type', 'application/json; charset=utf-8'); + + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "state": "new", + "email": "marty.mcfly@bttf.com" + } + JSON + ); } #[Test] public function it_does_not_allow_to_create_a_subscription_if_there_is_a_validation_error(): void { $data = - <<client->request('POST', '/ajax/subscriptions', [], [], ['CONTENT_TYPE' => 'application/json'], $data); - $file = Kernel::VERSION_ID >= 60400 ? 'subscriptions/create_validation' : 'subscriptions/create_validation_legacy'; + $this->assertResponseStatusCodeSame(Response::HTTP_UNPROCESSABLE_ENTITY); + $this->assertResponseHeaderSame('content-type', 'application/json; charset=utf-8'); - $this->assertResponse($this->client->getResponse(), $file, Response::HTTP_UNPROCESSABLE_ENTITY); + if (Kernel::VERSION_ID < 60400) { + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "type": "https://symfony.com/errors/validation", + "title": "Validation Failed", + "detail": "email: This value should not be blank.", + "violations": [ + { + "propertyPath": "email", + "title": "This value should not be blank.", + "parameters": { + "{{ value }}": "\"\"" + }, + "type": "urn:uuid:c1051bb4-d103-4f74-8988-acbcafc7fdc3" + } + ] + } + JSON + ); + + return; + } + + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "type": "https://symfony.com/errors/validation", + "title": "Validation Failed", + "detail": "email: This value should not be blank.", + "violations": [ + { + "propertyPath": "email", + "title": "This value should not be blank.", + "template": "This value should not be blank.", + "parameters": { + "{{ value }}": "\"\"" + }, + "type": "urn:uuid:c1051bb4-d103-4f74-8988-acbcafc7fdc3" + } + ] + } + JSON + ); } #[Test] @@ -90,15 +199,17 @@ public function it_allows_updating_a_subscription(): void $subscription = SubscriptionFactory::createOne(); $data = - <<client->request('PUT', '/ajax/subscriptions/' . $subscription->getId(), [], [], ['CONTENT_TYPE' => 'application/json'], $data); - $response = $this->client->getResponse(); - $this->assertResponseCode($response, Response::HTTP_NO_CONTENT); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_NO_CONTENT); } #[Test] @@ -115,9 +226,53 @@ public function it_does_not_allow_to_update_a_subscription_if_there_is_a_validat $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->assertResponseStatusCodeSame(Response::HTTP_UNPROCESSABLE_ENTITY); + $this->assertResponseHeaderSame('content-type', 'application/json; charset=utf-8'); - $this->assertResponse($this->client->getResponse(), $file, Response::HTTP_UNPROCESSABLE_ENTITY); + if (Kernel::VERSION_ID < 60400) { + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "type": "https://symfony.com/errors/validation", + "title": "Validation Failed", + "detail": "email: This value should not be blank.", + "violations": [ + { + "propertyPath": "email", + "title": "This value should not be blank.", + "parameters": { + "{{ value }}": "\"\"" + }, + "type": "urn:uuid:c1051bb4-d103-4f74-8988-acbcafc7fdc3" + } + ] + } + JSON + ); + + return; + } + + $this->assertResponseMatchesPattern( + <<<'JSON' + { + "type": "https://symfony.com/errors/validation", + "title": "Validation Failed", + "detail": "email: This value should not be blank.", + "violations": [ + { + "propertyPath": "email", + "title": "This value should not be blank.", + "template": "This value should not be blank.", + "parameters": { + "{{ value }}": "\"\"" + }, + "type": "urn:uuid:c1051bb4-d103-4f74-8988-acbcafc7fdc3" + } + ] + } + JSON + ); } #[Test] @@ -126,12 +281,8 @@ public function it_allows_removing_a_subscription(): void $subscription = SubscriptionFactory::createOne(); $this->client->request('DELETE', '/ajax/subscriptions/' . $subscription->getId()); - $response = $this->client->getResponse(); - $this->assertResponseCode($response, Response::HTTP_NO_CONTENT); - } - protected function buildMatcher(): Matcher - { - return $this->matcherFactory->createMatcher(new VoidBacktrace()); + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_NO_CONTENT); } } diff --git a/tests/Application/src/Tests/Controller/SubscriptionXmlApiTest.php b/tests/Application/src/Tests/Controller/SubscriptionXmlApiTest.php index 456c27cd3..9653b79c1 100644 --- a/tests/Application/src/Tests/Controller/SubscriptionXmlApiTest.php +++ b/tests/Application/src/Tests/Controller/SubscriptionXmlApiTest.php @@ -16,15 +16,21 @@ 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 Tests\ApiTestCase; +use Tests\PurgeDatabaseTrait; use Zenstruck\Foundry\Test\Factories; -final class SubscriptionXmlApiTest extends XmlApiTestCase +final class SubscriptionXmlApiTest extends ApiTestCase { use Factories; + use PurgeDatabaseTrait; + + private static array $headersWithContentType = [ + 'CONTENT_TYPE' => 'application/xml', + 'HTTP_ACCEPT' => 'application/xml', + ]; #[Test] public function it_allows_showing_a_subscription(): void @@ -34,10 +40,20 @@ public function it_allows_showing_a_subscription(): void ->create() ; - $this->client->request('GET', '/ajax/subscriptions/' . $subscription->getId()); - $response = $this->client->getResponse(); + $this->client->request('GET', '/ajax/subscriptions/' . $subscription->getId(), server: self::$headersWithContentType); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'text/xml; charset=utf-8'); - $this->assertResponse($response, 'subscriptions/show_response', Response::HTTP_OK); + $this->assertResponseMatchesPattern( + <<<'XML' + + new + marty.mcfly@bttf.com + + XML + ); } #[Test] @@ -45,42 +61,135 @@ public function it_allows_indexing_subscriptions(): void { DefaultSubscriptionsStory::load(); - $this->client->request('GET', '/ajax/subscriptions'); - $response = $this->client->getResponse(); + $this->client->request('GET', '/ajax/subscriptions', server: self::$headersWithContentType); - $this->assertResponse($response, 'subscriptions/index_response', Response::HTTP_OK); + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'text/xml; charset=utf-8'); + + $this->assertResponseMatchesPattern( + <<<'XML' + + + new + marty.mcfly@bttf.com + + + new + doc.brown@bttf.com + + + accepted + biff.tannen@bttf.com + + + new + lorraine.baines@bttf.com + + + new + george.mcfly@bttf.com + + + new + jennifer.parker@bttf.com + + + 1 + 0 + 0 + 10 + 6 + 1 + + + XML + ); } #[Test] public function it_allows_creating_a_subscription(): void { - $data = << - - marty.mcfly@bttf.com - -EOT; + $data = + <<<'XML' + + marty.mcfly@bttf.com + + XML + ; $this->client->request(method: 'POST', uri: '/ajax/subscriptions', server: self::$headersWithContentType, content: $data); - $response = $this->client->getResponse(); - $this->assertResponse($response, 'subscriptions/create_response', Response::HTTP_CREATED); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_CREATED); + $this->assertResponseHeaderSame('content-type', 'text/xml; charset=utf-8'); + + $this->assertResponseMatchesPattern( + <<<'XML' + + new + marty.mcfly@bttf.com + + XML + ); } #[Test] public function it_does_not_allow_to_create_a_subscription_if_there_is_a_validation_error(): void { - $data = << - - - -EOT; + $data = + <<<'XML' + + + + XML + ; $this->client->request(method: 'POST', uri: '/ajax/subscriptions', server: self::$headersWithContentType, content: $data); - $file = Kernel::VERSION_ID >= 60400 ? 'subscriptions/create_validation' : 'subscriptions/create_validation_legacy'; + $this->assertResponseStatusCodeSame(Response::HTTP_UNPROCESSABLE_ENTITY); + $this->assertResponseHeaderSame('content-type', 'text/xml; charset=utf-8'); + + if (Kernel::VERSION_ID < 60400) { + $this->assertResponseMatchesPattern( + <<<'XML' + + https://symfony.com/errors/validation + Validation Failed + email: This value should not be blank. + + email + This value should not be blank. + + "" + + urn:uuid:c1051bb4-d103-4f74-8988-acbcafc7fdc3 + + + XML + ); - $this->assertResponse($this->client->getResponse(), $file, Response::HTTP_UNPROCESSABLE_ENTITY); + return; + } + + $this->assertResponseMatchesPattern( + <<<'XML' + + https://symfony.com/errors/validation + Validation Failed + email: This value should not be blank. + + email + This value should not be blank. + + + "" + + urn:uuid:c1051bb4-d103-4f74-8988-acbcafc7fdc3 + + + XML + ); } #[Test] @@ -88,16 +197,18 @@ public function it_allows_updating_a_subscription(): void { $subscription = SubscriptionFactory::createOne(); - $data = << - - calvin.klein@bttf.com - -EOT; + $data = + <<<'XML' + + calvin.klein@bttf.com + + XML + ; $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); + + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_NO_CONTENT); } #[Test] @@ -105,18 +216,59 @@ public function it_does_not_allow_to_update_a_subscription_if_there_is_a_validat { $subscription = SubscriptionFactory::createOne(); - $data = << - - - -EOT; + $data = + <<<'XML' + + + + XML + ; $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->assertResponseStatusCodeSame(Response::HTTP_UNPROCESSABLE_ENTITY); + $this->assertResponseHeaderSame('content-type', 'text/xml; charset=utf-8'); - $this->assertResponse($this->client->getResponse(), $file, Response::HTTP_UNPROCESSABLE_ENTITY); + if (Kernel::VERSION_ID < 60400) { + $this->assertResponseMatchesPattern( + <<<'XML' + + https://symfony.com/errors/validation + Validation Failed + email: This value should not be blank. + + email + This value should not be blank. + + "" + + urn:uuid:c1051bb4-d103-4f74-8988-acbcafc7fdc3 + + + XML + ); + + return; + } + + $this->assertResponseMatchesPattern( + <<<'XML' + + https://symfony.com/errors/validation + Validation Failed + email: This value should not be blank. + + email + This value should not be blank. + + + "" + + urn:uuid:c1051bb4-d103-4f74-8988-acbcafc7fdc3 + + + XML + ); } #[Test] @@ -125,12 +277,8 @@ public function it_allows_removing_a_subscription(): void $subscription = SubscriptionFactory::createOne(); $this->client->request('DELETE', '/ajax/subscriptions/' . $subscription->getId()); - $response = $this->client->getResponse(); - $this->assertResponseCode($response, Response::HTTP_NO_CONTENT); - } - protected function buildMatcher(): Matcher - { - return $this->matcherFactory->createMatcher(new VoidBacktrace()); + $this->assertResponseIsSuccessful(); + $this->assertResponseStatusCodeSame(Response::HTTP_NO_CONTENT); } } diff --git a/tests/Application/src/Tests/Responses/.gitignore b/tests/Application/src/Tests/Responses/.gitignore new file mode 100644 index 000000000..e69de29bb diff --git a/tests/Application/src/Tests/Responses/blog-posts/create_response.json b/tests/Application/src/Tests/Responses/blog-posts/create_response.json deleted file mode 100644 index b33ba8cfc..000000000 --- a/tests/Application/src/Tests/Responses/blog-posts/create_response.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "id": @integer@, - "current_place": { - "draft": 1 - } -} diff --git a/tests/Application/src/Tests/Responses/blog-posts/publish_response.json b/tests/Application/src/Tests/Responses/blog-posts/publish_response.json deleted file mode 100644 index 8f2451d49..000000000 --- a/tests/Application/src/Tests/Responses/blog-posts/publish_response.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "id": @integer@, - "current_place": { - "published": 1 - } -} diff --git a/tests/Application/src/Tests/Responses/blog-posts/reject_response.json b/tests/Application/src/Tests/Responses/blog-posts/reject_response.json deleted file mode 100644 index f8894ee63..000000000 --- a/tests/Application/src/Tests/Responses/blog-posts/reject_response.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "id": @integer@, - "current_place": { - "rejected": 1 - } -} diff --git a/tests/Application/src/Tests/Responses/blog-posts/to_review_response.json b/tests/Application/src/Tests/Responses/blog-posts/to_review_response.json deleted file mode 100644 index b921e7669..000000000 --- a/tests/Application/src/Tests/Responses/blog-posts/to_review_response.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "id": @integer@, - "current_place": { - "reviewed": 1 - } -} diff --git a/tests/Application/src/Tests/Responses/books/create_response.json b/tests/Application/src/Tests/Responses/books/create_response.json deleted file mode 100644 index 96781082e..000000000 --- a/tests/Application/src/Tests/Responses/books/create_response.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "id": @integer@, - "title": "Star Wars: Dark Disciple", - "author": "Christie Golden" -} diff --git a/tests/Application/src/Tests/Responses/books/index_response.json b/tests/Application/src/Tests/Responses/books/index_response.json deleted file mode 100644 index 9bb2fddbb..000000000 --- a/tests/Application/src/Tests/Responses/books/index_response.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "page": 1, - "limit": 10, - "pages": 1, - "total": 2, - "_links": { - "self": { - "href": "@string@" - }, - "first": { - "href": "@string@" - }, - "last": { - "href": "@string@" - } - }, - "_embedded": { - "items": [ - { - "id": @integer@, - "title": "Lord of The Rings", - "author": "J.R.R. Tolkien" - }, - { - "id": @integer@, - "title": "Game of Thrones", - "author": "George R. R. Martin" - } - ] - } -} diff --git a/tests/Application/src/Tests/Responses/books/paginated_index_response.json b/tests/Application/src/Tests/Responses/books/paginated_index_response.json deleted file mode 100644 index e805da814..000000000 --- a/tests/Application/src/Tests/Responses/books/paginated_index_response.json +++ /dev/null @@ -1,77 +0,0 @@ -{ - "page": 2, - "limit": 10, - "pages": 3, - "total": 22, - "_links": { - "self": { - "href": "@string@" - }, - "first": { - "href": "@string@" - }, - "last": { - "href": "@string@" - }, - "next": { - "href": "@string@" - }, - "previous": { - "href": "@string@" - } - }, - "_embedded": { - "items": [ - { - "id": @integer@, - "title": "Book 11", - "author": "@string@" - }, - { - "id": @integer@, - "title": "Book 12", - "author": "@string@" - }, - { - "id": @integer@, - "title": "Book 13", - "author": "@string@" - }, - { - "id": @integer@, - "title": "Book 14", - "author": "@string@" - }, - { - "id": @integer@, - "title": "Book 15", - "author": "@string@" - }, - { - "id": @integer@, - "title": "Book 16", - "author": "@string@" - }, - { - "id": @integer@, - "title": "Book 17", - "author": "@string@" - }, - { - "id": @integer@, - "title": "Book 18", - "author": "@string@" - }, - { - "id": @integer@, - "title": "Book 19", - "author": "@string@" - }, - { - "id": @integer@, - "title": "Book 20", - "author": "@string@" - } - ] - } -} diff --git a/tests/Application/src/Tests/Responses/books/show_response.json b/tests/Application/src/Tests/Responses/books/show_response.json deleted file mode 100644 index 5df47fc3b..000000000 --- a/tests/Application/src/Tests/Responses/books/show_response.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "id": @integer@, - "title": "Lord of The Rings", - "author": "J.R.R. Tolkien" -} diff --git a/tests/Application/src/Tests/Responses/comic-books/create_response.json b/tests/Application/src/Tests/Responses/comic-books/create_response.json deleted file mode 100644 index 50f86c343..000000000 --- a/tests/Application/src/Tests/Responses/comic-books/create_response.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "id": @integer@, - "author": { - "first_name": "Joe", - "last_name": "Kelly" - }, - "title": "Deadpool #1-69" -} diff --git a/tests/Application/src/Tests/Responses/comic-books/index_response.json b/tests/Application/src/Tests/Responses/comic-books/index_response.json deleted file mode 100644 index 9d32fc854..000000000 --- a/tests/Application/src/Tests/Responses/comic-books/index_response.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "page": 1, - "limit": 10, - "pages": 1, - "total": 2, - "_links": { - "self": { - "href": "\/v1\/comic-books\/?page=1&limit=10" - }, - "first": { - "href": "\/v1\/comic-books\/?page=1&limit=10" - }, - "last": { - "href": "\/v1\/comic-books\/?page=1&limit=10" - } - }, - "_embedded": { - "items": [ - { - "id": @integer@, - "author": { - "first_name": "Andrea", - "last_name": "Sorrentino" - }, - "title": "Old Man Logan" - }, - { - "id": @integer@, - "author": { - "first_name": "Brian Michael", - "last_name": "Bendis" - }, - "title": "Civil War II" - } - ] - } -} diff --git a/tests/Application/src/Tests/Responses/comic-books/show_response.json b/tests/Application/src/Tests/Responses/comic-books/show_response.json deleted file mode 100644 index c62876a67..000000000 --- a/tests/Application/src/Tests/Responses/comic-books/show_response.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "id": @integer@, - "author": { - "first_name": "Andrea", - "last_name": "Sorrentino" - }, - "title": "Old Man Logan" -} diff --git a/tests/Application/src/Tests/Responses/comic-books/versioned_create_response.json b/tests/Application/src/Tests/Responses/comic-books/versioned_create_response.json deleted file mode 100644 index 4818f7197..000000000 --- a/tests/Application/src/Tests/Responses/comic-books/versioned_create_response.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "id": @integer@, - "author_first_name": "Joe", - "author_last_name": "Kelly", - "title": "Deadpool #1-69" -} diff --git a/tests/Application/src/Tests/Responses/comic-books/versioned_index_response.json b/tests/Application/src/Tests/Responses/comic-books/versioned_index_response.json deleted file mode 100644 index c7c1bca92..000000000 --- a/tests/Application/src/Tests/Responses/comic-books/versioned_index_response.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "page": 1, - "limit": 10, - "pages": 1, - "total": 2, - "_links": { - "self": { - "href": "\/v1.2\/comic-books\/?page=1&limit=10" - }, - "first": { - "href": "\/v1.2\/comic-books\/?page=1&limit=10" - }, - "last": { - "href": "\/v1.2\/comic-books\/?page=1&limit=10" - } - }, - "_embedded": { - "items": [ - { - "id": @integer@, - "author_first_name": "Andrea", - "author_last_name": "Sorrentino", - "title": "Old Man Logan" - }, - { - "id": @integer@, - "author_first_name": "Brian Michael", - "author_last_name": "Bendis", - "title": "Civil War II" - } - ] - } -} diff --git a/tests/Application/src/Tests/Responses/comic-books/versioned_show_response.json b/tests/Application/src/Tests/Responses/comic-books/versioned_show_response.json deleted file mode 100644 index b88976736..000000000 --- a/tests/Application/src/Tests/Responses/comic-books/versioned_show_response.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "id": @integer@, - "author_first_name": "Andrea", - "author_last_name": "Sorrentino", - "title": "Old Man Logan" -} diff --git a/tests/Application/src/Tests/Responses/gedmos/create_response.json b/tests/Application/src/Tests/Responses/gedmos/create_response.json deleted file mode 100644 index e5a797c8d..000000000 --- a/tests/Application/src/Tests/Responses/gedmos/create_response.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "id": @integer@, - "position": 0, - "extra": "Some info" -} diff --git a/tests/Application/src/Tests/Responses/pull-requests/create_response.json b/tests/Application/src/Tests/Responses/pull-requests/create_response.json deleted file mode 100644 index 3b24b7002..000000000 --- a/tests/Application/src/Tests/Responses/pull-requests/create_response.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "id": @integer@, - "current_place": "start" -} diff --git a/tests/Application/src/Tests/Responses/pull-requests/submit_response.json b/tests/Application/src/Tests/Responses/pull-requests/submit_response.json deleted file mode 100644 index 448109b2d..000000000 --- a/tests/Application/src/Tests/Responses/pull-requests/submit_response.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "id": @integer@, - "current_place": "test" -} diff --git a/tests/Application/src/Tests/Responses/pull-requests/wait_for_review_response.json b/tests/Application/src/Tests/Responses/pull-requests/wait_for_review_response.json deleted file mode 100644 index 8587e7388..000000000 --- a/tests/Application/src/Tests/Responses/pull-requests/wait_for_review_response.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "id": @integer@, - "current_place": "review" -} diff --git a/tests/Application/src/Tests/Responses/subscriptions/create_response.json b/tests/Application/src/Tests/Responses/subscriptions/create_response.json deleted file mode 100644 index ddc3c7554..000000000 --- a/tests/Application/src/Tests/Responses/subscriptions/create_response.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "state": "new", - "email": "marty.mcfly@bttf.com" -} diff --git a/tests/Application/src/Tests/Responses/subscriptions/create_response.xml b/tests/Application/src/Tests/Responses/subscriptions/create_response.xml deleted file mode 100644 index 42ea85b92..000000000 --- a/tests/Application/src/Tests/Responses/subscriptions/create_response.xml +++ /dev/null @@ -1,4 +0,0 @@ - - new - marty.mcfly@bttf.com - diff --git a/tests/Application/src/Tests/Responses/subscriptions/create_validation.json b/tests/Application/src/Tests/Responses/subscriptions/create_validation.json deleted file mode 100644 index 4059d1666..000000000 --- a/tests/Application/src/Tests/Responses/subscriptions/create_validation.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "type": "https://symfony.com/errors/validation", - "title": "Validation Failed", - "detail": "email: This value should not be blank.", - "violations": [ - { - "propertyPath": "email", - "title": "This value should not be blank.", - "template": "This value should not be blank.", - "parameters": { - "{{ value }}": "\"\"" - }, - "type": "urn:uuid:c1051bb4-d103-4f74-8988-acbcafc7fdc3" - } - ] -} diff --git a/tests/Application/src/Tests/Responses/subscriptions/create_validation.xml b/tests/Application/src/Tests/Responses/subscriptions/create_validation.xml deleted file mode 100644 index 1304ceb2e..000000000 --- a/tests/Application/src/Tests/Responses/subscriptions/create_validation.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - https://symfony.com/errors/validation - Validation Failed - email: This value should not be blank. - - email - This value should not be blank. - - - "" - - urn:uuid:c1051bb4-d103-4f74-8988-acbcafc7fdc3 - - diff --git a/tests/Application/src/Tests/Responses/subscriptions/create_validation_legacy.json b/tests/Application/src/Tests/Responses/subscriptions/create_validation_legacy.json deleted file mode 100644 index 0fd888370..000000000 --- a/tests/Application/src/Tests/Responses/subscriptions/create_validation_legacy.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "type": "https://symfony.com/errors/validation", - "title": "Validation Failed", - "detail": "email: This value should not be blank.", - "violations": [ - { - "propertyPath": "email", - "title": "This value should not be blank.", - "parameters": { - "{{ value }}": "\"\"" - }, - "type": "urn:uuid:c1051bb4-d103-4f74-8988-acbcafc7fdc3" - } - ] -} diff --git a/tests/Application/src/Tests/Responses/subscriptions/create_validation_legacy.xml b/tests/Application/src/Tests/Responses/subscriptions/create_validation_legacy.xml deleted file mode 100644 index 04a18b61c..000000000 --- a/tests/Application/src/Tests/Responses/subscriptions/create_validation_legacy.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - https://symfony.com/errors/validation - Validation Failed - email: This value should not be blank. - - email - This value should not be blank. - - "" - - urn:uuid:c1051bb4-d103-4f74-8988-acbcafc7fdc3 - - diff --git a/tests/Application/src/Tests/Responses/subscriptions/index_response.json b/tests/Application/src/Tests/Responses/subscriptions/index_response.json deleted file mode 100644 index a438662f3..000000000 --- a/tests/Application/src/Tests/Responses/subscriptions/index_response.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "items": [ - { - "state": "new", - "email": "marty.mcfly@bttf.com" - }, - { - "state": "new", - "email": "doc.brown@bttf.com" - }, - { - "state": "accepted", - "email": "biff.tannen@bttf.com" - }, - { - "state": "new", - "email": "lorraine.baines@bttf.com" - }, - { - "state": "new", - "email": "george.mcfly@bttf.com" - }, - { - "state": "new", - "email": "jennifer.parker@bttf.com" - } - ], - "pagination": { - "current_page": 1, - "has_previous_page": false, - "has_next_page": false, - "per_page": 10, - "total_items": 6, - "total_pages": 1 - } -} diff --git a/tests/Application/src/Tests/Responses/subscriptions/index_response.xml b/tests/Application/src/Tests/Responses/subscriptions/index_response.xml deleted file mode 100644 index 2d2a7c770..000000000 --- a/tests/Application/src/Tests/Responses/subscriptions/index_response.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - new - marty.mcfly@bttf.com - - - new - doc.brown@bttf.com - - - accepted - biff.tannen@bttf.com - - - new - lorraine.baines@bttf.com - - - new - george.mcfly@bttf.com - - - new - jennifer.parker@bttf.com - - - 1 - 0 - 0 - 10 - 6 - 1 - - diff --git a/tests/Application/src/Tests/Responses/subscriptions/show_response.json b/tests/Application/src/Tests/Responses/subscriptions/show_response.json deleted file mode 100644 index ddc3c7554..000000000 --- a/tests/Application/src/Tests/Responses/subscriptions/show_response.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "state": "new", - "email": "marty.mcfly@bttf.com" -} diff --git a/tests/Application/src/Tests/Responses/subscriptions/show_response.xml b/tests/Application/src/Tests/Responses/subscriptions/show_response.xml deleted file mode 100644 index cb119e406..000000000 --- a/tests/Application/src/Tests/Responses/subscriptions/show_response.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - new - marty.mcfly@bttf.com - diff --git a/tests/Application/src/Tests/Responses/subscriptions/update_validation.json b/tests/Application/src/Tests/Responses/subscriptions/update_validation.json deleted file mode 100644 index 4059d1666..000000000 --- a/tests/Application/src/Tests/Responses/subscriptions/update_validation.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "type": "https://symfony.com/errors/validation", - "title": "Validation Failed", - "detail": "email: This value should not be blank.", - "violations": [ - { - "propertyPath": "email", - "title": "This value should not be blank.", - "template": "This value should not be blank.", - "parameters": { - "{{ value }}": "\"\"" - }, - "type": "urn:uuid:c1051bb4-d103-4f74-8988-acbcafc7fdc3" - } - ] -} diff --git a/tests/Application/src/Tests/Responses/subscriptions/update_validation.xml b/tests/Application/src/Tests/Responses/subscriptions/update_validation.xml deleted file mode 100644 index 1304ceb2e..000000000 --- a/tests/Application/src/Tests/Responses/subscriptions/update_validation.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - https://symfony.com/errors/validation - Validation Failed - email: This value should not be blank. - - email - This value should not be blank. - - - "" - - urn:uuid:c1051bb4-d103-4f74-8988-acbcafc7fdc3 - - diff --git a/tests/Application/src/Tests/Responses/subscriptions/update_validation_legacy.json b/tests/Application/src/Tests/Responses/subscriptions/update_validation_legacy.json deleted file mode 100644 index 0fd888370..000000000 --- a/tests/Application/src/Tests/Responses/subscriptions/update_validation_legacy.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "type": "https://symfony.com/errors/validation", - "title": "Validation Failed", - "detail": "email: This value should not be blank.", - "violations": [ - { - "propertyPath": "email", - "title": "This value should not be blank.", - "parameters": { - "{{ value }}": "\"\"" - }, - "type": "urn:uuid:c1051bb4-d103-4f74-8988-acbcafc7fdc3" - } - ] -} diff --git a/tests/Application/src/Tests/Responses/subscriptions/update_validation_legacy.xml b/tests/Application/src/Tests/Responses/subscriptions/update_validation_legacy.xml deleted file mode 100644 index 04a18b61c..000000000 --- a/tests/Application/src/Tests/Responses/subscriptions/update_validation_legacy.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - https://symfony.com/errors/validation - Validation Failed - email: This value should not be blank. - - email - This value should not be blank. - - "" - - urn:uuid:c1051bb4-d103-4f74-8988-acbcafc7fdc3 - - diff --git a/tests/PurgeDatabaseTrait.php b/tests/PurgeDatabaseTrait.php new file mode 100644 index 000000000..13137f8c2 --- /dev/null +++ b/tests/PurgeDatabaseTrait.php @@ -0,0 +1,36 @@ +getContainer()->get(EntityManagerInterface::class); + $purger = new ORMPurger($entityManager); + $purger->purge(); + + $entityManager->clear(); + } +}