Skip to content

Commit

Permalink
[DX][Internal] Remove ApiTestCase package
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 committed Jan 22, 2025
1 parent 818060b commit 12ff104
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 91 deletions.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@
"sylius/resource": "self.version"
},
"require-dev": {
"coduo/php-matcher": "^6.0",
"doctrine/data-fixtures": "^2.0",
"doctrine/doctrine-bundle": "^2.13",
"doctrine/orm": "^2.18 || ^3.3",
"friendsofsymfony/rest-bundle": "^3.7",
"jms/serializer-bundle": "^3.5 || ^4.0 || ^5.0",
"lchrusciel/api-test-case": "^5.0",
"matthiasnoback/symfony-dependency-injection-test": "^4.2.1 || ^5.1",
"openlss/lib-array2xml": "^1.0",
"pagerfanta/pagerfanta": "^4.4",
"pamil/phpspec-skip-example-extension": "^4.2",
"phpspec/phpspec": "^7.5",
Expand All @@ -72,6 +74,7 @@
"rector/rector": "^0.18.2",
"sylius-labs/coding-standard": "^4.4",
"sylius/grid-bundle": "^1.13",
"symfony/browser-kit": "^6.4 || ^7.1",
"symfony/console": "^6.4 || ^7.1",
"symfony/css-selector": "^6.4 || ^7.1",
"symfony/dependency-injection": "^6.4 || ^7.1",
Expand Down
4 changes: 0 additions & 4 deletions tests/Application/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
use BabDev\PagerfantaBundle\BabDevPagerfantaBundle;
use Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle;
use FOS\RestBundle\FOSRestBundle;
use JMS\SerializerBundle\JMSSerializerBundle;
use Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle;
use Sylius\Bundle\GridBundle\SyliusGridBundle;
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
Expand All @@ -35,8 +33,6 @@
FOSRestBundle::class => ['all' => true, 'test_without_fosrest' => false],
JMSSerializerBundle::class => ['all' => true, 'test_without_fosrest' => false],
BazingaHateoasBundle::class => ['all' => true, 'test_without_hateoas' => false, 'test_without_fosrest' => false, 'test_with_attributes' => false],
FidryAliceDataFixturesBundle::class => ['all' => true],
NelmioAliceBundle::class => ['all' => true],
winzouStateMachineBundle::class => ['all' => true, 'test_without_state_machine' => false],
SyliusGridBundle::class => ['all' => true, 'test_without_twig' => false],
Zenstruck\Foundry\ZenstruckFoundryBundle::class => ['dev' => true, 'test' => true],
Expand Down
51 changes: 29 additions & 22 deletions tests/Application/src/Tests/Controller/BoardGameUiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,30 @@

namespace App\Tests\Controller;

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 PHPUnit\Framework\Attributes\Test;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Response;
use Zenstruck\Foundry\Test\Factories;
use Zenstruck\Foundry\Test\ResetDatabase;

final class BoardGameUiTest extends ApiTestCase
final class BoardGameUiTest extends WebTestCase
{
use Factories;
use ResetDatabase;

/** @test */
private KernelBrowser $client;

protected function setUp(): void
{
$this->client = self::createClient();
}

#[Test]
public function it_allows_showing_a_board_game(): void
{
$boardGame = BoardGameFactory::new()
Expand All @@ -38,13 +47,14 @@ public function it_allows_showing_a_board_game(): void
$this->client->request('GET', '/admin/board-games/' . $boardGame->id());
$response = $this->client->getResponse();

$this->assertResponseCode($response, Response::HTTP_OK);
$this->assertResponseIsSuccessful();
$this->assertResponseStatusCodeSame(Response::HTTP_OK);
$content = $response->getContent();
$this->assertStringContainsString(sprintf('ID: %s', $boardGame->id()), $content);
$this->assertStringContainsString('Name: Ticket to Ride', $content);
}

/** @test */
#[Test]
public function it_allows_browsing_board_games(): void
{
$stoneAgeBoardGame = BoardGameFactory::new()
Expand All @@ -60,7 +70,8 @@ public function it_allows_browsing_board_games(): void
$this->client->request('GET', '/admin/board-games');
$response = $this->client->getResponse();

$this->assertResponseCode($response, Response::HTTP_OK);
$this->assertResponseIsSuccessful();
$this->assertResponseStatusCodeSame(Response::HTTP_OK);
$content = $response->getContent();

$this->assertStringContainsString('<td>Stone Age</td>', $content);
Expand All @@ -74,15 +85,16 @@ public function it_allows_browsing_board_games(): void
$this->assertStringContainsString(sprintf('<form action="/admin/board-games/%s/delete" method="post">', $ticketToRideBoardGame->id()), $content);
}

/** @test */
#[Test]
public function it_allows_accessing_board_game_creation_page(): void
{
$this->client->request('GET', '/admin/board-games/new');

$this->assertResponseCode($this->client->getResponse(), Response::HTTP_OK);
$this->assertResponseIsSuccessful();
$this->assertResponseStatusCodeSame(Response::HTTP_OK);
}

/** @test */
#[Test]
public function it_allows_creating_a_board_game(): void
{
$this->client->request('GET', '/admin/board-games/new');
Expand All @@ -99,18 +111,18 @@ public function it_allows_creating_a_board_game(): void
$this->assertSame('Puerto Rico', (string) $boardGame->name());
}

/** @test */
#[Test]
public function it_does_not_allow_to_create_a_board_game_if_there_is_a_validation_error(): void
{
$this->client->request('GET', '/admin/board-games/new');
$this->client->submitForm('Create', [
'board_game[name]' => null,
]);

$this->assertResponseCode($this->client->getResponse(), Response::HTTP_UNPROCESSABLE_ENTITY);
$this->assertResponseStatusCodeSame(Response::HTTP_UNPROCESSABLE_ENTITY);
}

/** @test */
#[Test]
public function it_allows_updating_a_board_game(): void
{
$boardGame = BoardGameFactory::createOne();
Expand All @@ -126,7 +138,7 @@ public function it_allows_updating_a_board_game(): void
$this->assertSame('Puerto Rico', (string) $boardGame->name());
}

/** @test */
#[Test]
public function it_does_not_allow_to_update_a_board_game_if_there_is_a_validation_error(): void
{
$boardGame = BoardGameFactory::createOne();
Expand All @@ -136,10 +148,10 @@ public function it_does_not_allow_to_update_a_board_game_if_there_is_a_validatio
'board_game[name]' => null,
]);

$this->assertResponseCode($this->client->getResponse(), Response::HTTP_UNPROCESSABLE_ENTITY);
$this->assertResponseStatusCodeSame(Response::HTTP_UNPROCESSABLE_ENTITY);
}

/** @test */
#[Test]
public function it_allows_deleting_a_board_game(): void
{
BoardGameFactory::createOne();
Expand All @@ -154,9 +166,4 @@ public function it_allows_deleting_a_board_game(): void

$this->assertEmpty($boardGames);
}

protected function buildMatcher(): Matcher
{
return $this->matcherFactory->createMatcher(new VoidBacktrace());
}
}
44 changes: 27 additions & 17 deletions tests/Application/src/Tests/Controller/ScienceBookUiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,28 @@

namespace App\Tests\Controller;

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\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Response;
use Zenstruck\Foundry\Test\Factories;
use Zenstruck\Foundry\Test\ResetDatabase;

final class ScienceBookUiTest extends ApiTestCase
final class ScienceBookUiTest extends WebTestCase
{
use Factories;
use ResetDatabase;

private KernelBrowser $client;

protected function setUp(): void
{
$this->client = self::createClient();
}

#[Test]
public function it_allows_showing_a_book(): void
{
Expand All @@ -45,7 +51,9 @@ public function it_allows_showing_a_book(): void
$this->client->request('GET', '/science-books/' . $scienceBook->getId());
$response = $this->client->getResponse();

$this->assertResponseCode($response, Response::HTTP_OK);
$this->assertResponseIsSuccessful();
$this->assertResponseStatusCodeSame(Response::HTTP_OK);

$content = $response->getContent();
$this->assertStringContainsString(sprintf('ID: %d', $scienceBook->getId()), $content);
$this->assertStringContainsString('Title: A Brief History of Time', $content);
Expand Down Expand Up @@ -78,7 +86,9 @@ public function it_allows_indexing_books(): void
$this->client->request('GET', '/science-books/');
$response = $this->client->getResponse();

$this->assertResponseCode($response, Response::HTTP_OK);
$this->assertResponseIsSuccessful();
$this->assertResponseStatusCodeSame(Response::HTTP_OK);

$content = $response->getContent();
$this->assertStringContainsString('<h1>Books</h1>', $content);
$this->assertStringContainsString(
Expand Down Expand Up @@ -128,7 +138,7 @@ public function it_does_not_allow_to_create_a_book_if_there_is_a_validation_erro
'science_book[author][lastName]' => $newBookAuthorLastName,
]);

$this->assertResponseCode($this->client->getResponse(), Response::HTTP_UNPROCESSABLE_ENTITY);
$this->assertResponseStatusCodeSame(Response::HTTP_UNPROCESSABLE_ENTITY);

/** @var ScienceBook $book */
$book = static::getContainer()->get('app.repository.science_book')->findOneBy(['title' => $newBookTitle]);
Expand Down Expand Up @@ -163,7 +173,9 @@ public function it_allows_updating_a_book(): void
#[Test]
public function it_does_not_allow_to_update_a_book_if_there_is_a_validation_error(): void
{
$scienceBook = ScienceBookFactory::createOne();
$scienceBook = ScienceBookFactory::new()
->withTitle('The Shinning')
->create();

$newBookTitle = 'The Book of Why';
$newBookAuthorLastName = 'Pearl';
Expand All @@ -175,10 +187,13 @@ public function it_does_not_allow_to_update_a_book_if_there_is_a_validation_erro
'science_book[author][lastName]' => $newBookAuthorLastName,
]);

$this->assertResponseCode($this->client->getResponse(), Response::HTTP_UNPROCESSABLE_ENTITY);
$this->assertResponseStatusCodeSame(expectedCode: Response::HTTP_UNPROCESSABLE_ENTITY);

$scienceBook->_refresh();
$this->assertNotEquals($newBookTitle, $scienceBook->getTitle());
/** @var ScienceBook $book */
$book = static::getContainer()->get('app.repository.science_book')->find($scienceBook->getId());
$this->getContainer()->get('doctrine.orm.entity_manager')->refresh($book);

$this->assertNotEquals($newBookTitle, $book->getTitle());
}

#[Test]
Expand Down Expand Up @@ -223,7 +238,7 @@ public function it_allows_filtering_books(): void
$this->client->request('GET', '/science-books/?criteria[search][value]=history of time');
$response = $this->client->getResponse();

$this->assertResponseCode($response, Response::HTTP_OK);
$this->assertResponseStatusCodeSame(expectedCode: Response::HTTP_OK);
$content = $response->getContent();
$this->assertStringContainsString('<h1>Books</h1>', $content);
$this->assertStringContainsString(
Expand All @@ -235,9 +250,4 @@ public function it_allows_filtering_books(): void
$content,
);
}

protected function buildMatcher(): Matcher
{
return $this->matcherFactory->createMatcher(new VoidBacktrace());
}
}
41 changes: 24 additions & 17 deletions tests/Application/src/Tests/Controller/SubscriptionUiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,27 @@

namespace App\Tests\Controller;

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\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Response;
use Zenstruck\Foundry\Test\Factories;
use Zenstruck\Foundry\Test\ResetDatabase;

final class SubscriptionUiTest extends ApiTestCase
final class SubscriptionUiTest extends WebTestCase
{
use Factories;
use ResetDatabase;

private KernelBrowser $client;

protected function setUp(): void
{
$this->client = self::createClient();
}

#[Test]
public function it_allows_showing_a_subscription(): void
Expand All @@ -38,7 +46,9 @@ public function it_allows_showing_a_subscription(): void
$this->client->request('GET', '/admin/subscriptions/' . $subscription->getId());
$response = $this->client->getResponse();

$this->assertResponseCode($response, Response::HTTP_OK);
$this->assertResponseIsSuccessful();
$this->assertResponseStatusCodeSame(Response::HTTP_OK);

$content = $response->getContent();
$this->assertStringContainsString(sprintf('ID: %s', $subscription->getId()), $content);
$this->assertStringContainsString('Email: marty.mcfly@bttf.com', $content);
Expand All @@ -56,7 +66,9 @@ public function it_allows_browsing_subscriptions(): void
$this->client->request('GET', '/admin/subscriptions');
$response = $this->client->getResponse();

$this->assertResponseCode($response, Response::HTTP_OK);
$this->assertResponseIsSuccessful();
$this->assertResponseStatusCodeSame(Response::HTTP_OK);

$content = $response->getContent();

// only 5 subscriptions
Expand All @@ -81,9 +93,9 @@ public function it_allows_browsing_subscriptions_with_page_limit(): void
DefaultSubscriptionsStory::load();

$this->client->request('GET', '/admin/subscriptions?limit=3');
$response = $this->client->getResponse();

$this->assertResponseCode($response, Response::HTTP_OK);
$this->assertResponseIsSuccessful();
$this->assertResponseStatusCodeSame(Response::HTTP_OK);

// only 2 subscriptions
if (method_exists($this, 'assertSelectorCount')) {
Expand All @@ -97,9 +109,9 @@ public function it_allows_browsing_subscriptions_with_grid_limits(): void
DefaultSubscriptionsStory::load();

$this->client->request('GET', '/admin/subscriptions');
$response = $this->client->getResponse();

$this->assertResponseCode($response, Response::HTTP_OK);
$this->assertResponseIsSuccessful();
$this->assertResponseStatusCodeSame(Response::HTTP_OK);

// only 5 subscriptions
if (method_exists($this, 'assertSelectorCount')) {
Expand Down Expand Up @@ -138,7 +150,7 @@ public function it_does_not_allow_to_create_a_subscription_if_there_is_a_validat
'subscription[email]' => null,
]);

$this->assertResponseCode($this->client->getResponse(), Response::HTTP_UNPROCESSABLE_ENTITY);
$this->assertResponseStatusCodeSame(Response::HTTP_UNPROCESSABLE_ENTITY);
}

#[Test]
Expand Down Expand Up @@ -167,7 +179,7 @@ public function it_does_not_allow_to_update_a_subscription_if_there_is_a_validat
'subscription[email]' => null,
]);

$this->assertResponseCode($this->client->getResponse(), Response::HTTP_UNPROCESSABLE_ENTITY);
$this->assertResponseStatusCodeSame(Response::HTTP_UNPROCESSABLE_ENTITY);
}

#[Test]
Expand Down Expand Up @@ -235,9 +247,4 @@ public function it_allows_accepting_multiple_subscription(): void
$docBrown->_refresh();
$this->assertSame('accepted', $docBrown->getState());
}

protected function buildMatcher(): Matcher
{
return $this->matcherFactory->createMatcher(new VoidBacktrace());
}
}
Loading

0 comments on commit 12ff104

Please sign in to comment.