Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 25 additions & 21 deletions tests/JsonControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,29 @@
use App\Entity\Guest;
use App\Enum\CheckinStatusEnum;
use Doctrine\Common\DataFixtures\Executor\AbstractExecutor;
use Doctrine\ORM\EntityManagerInterface;
use Liip\TestFixturesBundle\Services\DatabaseToolCollection;
use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class JsonControllerTest extends WebTestCase
{
private KernelBrowser $client;
private EntityManagerInterface $entityManager;
private AbstractExecutor $fixtures;

protected function setUp(): void
{
parent::setUp();

$this->client = self::createClient();
$this->entityManager = static::getContainer()->get('doctrine')->getManager();
$this->fixtures = $this->loadFixtures([
EventFixtures::class,
GuestFixture::class
]);
}

protected function loadFixtures(array $fixtures): AbstractExecutor
{
Expand All @@ -24,14 +41,8 @@ protected function loadFixtures(array $fixtures): AbstractExecutor

public function testBaseStats(): void
{
$client = static::createClient();
$fixtures = $this->loadFixtures([
EventFixtures::class,
GuestFixture::class
])->getReferenceRepository();
$event = $fixtures->getReference('event1');

$client->xmlHttpRequest('POST', '/json/stats/' . $event->getId());
$event = $this->fixtures->getReferenceRepository()->getReference('event1');
$this->client->xmlHttpRequest('POST', '/json/stats/' . $event->getId());

self::assertResponseIsSuccessful();
$expectedArray = [
Expand All @@ -45,26 +56,19 @@ public function testBaseStats(): void
'totalNoShows' => 15
]
];
$expected = json_encode($expectedArray);
$this->assertSame($expected, $client->getResponse()->getContent());
$expected = json_encode($expectedArray, JSON_THROW_ON_ERROR);
$this->assertSame($expected, $this->client->getResponse()->getContent());
}

public function testCancellation()
{
$client = static::createClient();
$entityManager = static::getContainer()
->get('doctrine')
->getManager();
$repo = $entityManager->getRepository(Guest::class);
$fixtures = $this->loadFixtures([
EventFixtures::class,
GuestFixture::class
])->getReferenceRepository();
$repo = $this->entityManager->getRepository(Guest::class);

// Get record
/** @var Guest $guestToWorkOn */
$guestToWorkOn = $fixtures->getReference('event1guest_1');
$guestToWorkOn = $this->fixtures->getReferenceRepository()->getReference('event1guest_1');
$expected = CheckinStatusEnum::CANCELLED;
$client->xmlHttpRequest('POST', '/json/cancel/' . $guestToWorkOn->getId());
$this->client->xmlHttpRequest('POST', '/json/cancel/' . $guestToWorkOn->getId());
$actual = $repo->find($guestToWorkOn->getId());
$this->assertSame($expected, $actual->getCheckInStatus());
}
Expand Down