Skip to content

Commit

Permalink
misc: Improve namespace imports of the TicketsControllerTest file
Browse files Browse the repository at this point in the history
  • Loading branch information
marien-probesys committed Jan 15, 2025
1 parent a5a053a commit fc44fda
Showing 1 changed file with 34 additions and 38 deletions.
72 changes: 34 additions & 38 deletions tests/Controller/TicketsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,34 @@

namespace App\Tests\Controller;

use App\Entity\Organization;
use App\Entity\Ticket;
use App\Tests\AuthorizationHelper;
use App\Tests\Factory\MessageFactory;
use App\Tests\Factory\OrganizationFactory;
use App\Tests\Factory\TicketFactory;
use App\Tests\Factory\UserFactory;
use App\Entity;
use App\Tests;
use App\Tests\Factory;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Zenstruck\Foundry;
use Zenstruck\Foundry\Factory;
use Zenstruck\Foundry\Test\Factories;
use Zenstruck\Foundry\Test\ResetDatabase;

class TicketsControllerTest extends WebTestCase
{
use AuthorizationHelper;
use Factories;
use ResetDatabase;
use Tests\AuthorizationHelper;
use Tests\SessionHelper;

public function testGetIndexRendersCorrectly(): void
{
$client = static::createClient();
$user = UserFactory::createOne();
$user = Factory\UserFactory::createOne();
$client->loginUser($user->_real());
$this->grantOrga($user->_real(), ['orga:see']);
$ticket = TicketFactory::createOne([
$ticket = Factory\TicketFactory::createOne([
'title' => 'My ticket',
'assignee' => $user,
'status' => Foundry\faker()->randomElement(Ticket::OPEN_STATUSES),
'status' => Foundry\faker()->randomElement(Entity\Ticket::OPEN_STATUSES),
]);

$client->request(Request::METHOD_GET, '/tickets');
Expand All @@ -49,10 +45,10 @@ public function testGetIndexRendersCorrectly(): void
public function testGetShowRendersCorrectlyIfTicketIsCreatedByUser(): void
{
$client = static::createClient();
$user = UserFactory::createOne();
$user = Factory\UserFactory::createOne();
$client->loginUser($user->_real());
$this->grantOrga($user->_real(), ['orga:see']);
$ticket = TicketFactory::createOne([
$ticket = Factory\TicketFactory::createOne([
'title' => 'My ticket',
'createdBy' => $user,
]);
Expand All @@ -66,10 +62,10 @@ public function testGetShowRendersCorrectlyIfTicketIsCreatedByUser(): void
public function testGetShowRendersCorrectlyIfTicketIsRequestedByUser(): void
{
$client = static::createClient();
$user = UserFactory::createOne();
$user = Factory\UserFactory::createOne();
$client->loginUser($user->_real());
$this->grantOrga($user->_real(), ['orga:see']);
$ticket = TicketFactory::createOne([
$ticket = Factory\TicketFactory::createOne([
'title' => 'My ticket',
'requester' => $user,
]);
Expand All @@ -83,10 +79,10 @@ public function testGetShowRendersCorrectlyIfTicketIsRequestedByUser(): void
public function testGetShowRendersCorrectlyIfTicketIsAssignedToUser(): void
{
$client = static::createClient();
$user = UserFactory::createOne();
$user = Factory\UserFactory::createOne();
$client->loginUser($user->_real());
$this->grantOrga($user->_real(), ['orga:see']);
$ticket = TicketFactory::createOne([
$ticket = Factory\TicketFactory::createOne([
'title' => 'My ticket',
'assignee' => $user,
]);
Expand All @@ -100,10 +96,10 @@ public function testGetShowRendersCorrectlyIfTicketIsAssignedToUser(): void
public function testGetShowRendersCorrectlyIfUserIsObserverOfTheTicket(): void
{
$client = static::createClient();
$user = UserFactory::createOne();
$user = Factory\UserFactory::createOne();
$client->loginUser($user->_real());
$this->grantOrga($user->_real(), ['orga:see']);
$ticket = TicketFactory::createOne([
$ticket = Factory\TicketFactory::createOne([
'title' => 'My ticket',
'observers' => [$user],
]);
Expand All @@ -117,10 +113,10 @@ public function testGetShowRendersCorrectlyIfUserIsObserverOfTheTicket(): void
public function testGetShowRendersCorrectlyIfAccessIsGranted(): void
{
$client = static::createClient();
$user = UserFactory::createOne();
$user = Factory\UserFactory::createOne();
$client->loginUser($user->_real());
$this->grantOrga($user->_real(), ['orga:see', 'orga:see:tickets:all']);
$ticket = TicketFactory::createOne([
$ticket = Factory\TicketFactory::createOne([
'title' => 'My ticket',
]);

Expand All @@ -133,15 +129,15 @@ public function testGetShowRendersCorrectlyIfAccessIsGranted(): void
public function testGetShowRendersMessages(): void
{
$client = static::createClient();
$user = UserFactory::createOne();
$user = Factory\UserFactory::createOne();
$client->loginUser($user->_real());
$ticket = TicketFactory::createOne([
$ticket = Factory\TicketFactory::createOne([
'title' => 'My ticket',
'createdBy' => $user,
]);
$this->grantOrga($user->_real(), ['orga:see']);
$content = 'The content of the answer';
$message = MessageFactory::createOne([
$message = Factory\MessageFactory::createOne([
'isConfidential' => false,
'ticket' => $ticket,
'content' => $content
Expand All @@ -156,16 +152,16 @@ public function testGetShowRendersMessages(): void
public function testGetShowRendersConfidentialMessagesIfAccessIsGranted(): void
{
$client = static::createClient();
$user = UserFactory::createOne();
$user = Factory\UserFactory::createOne();
$client->loginUser($user->_real());
$this->grantOrga($user->_real(), [
'orga:see',
'orga:see:tickets:all',
'orga:see:tickets:messages:confidential',
]);
$content = 'The content of the answer';
$ticket = TicketFactory::createOne();
$message = MessageFactory::createOne([
$ticket = Factory\TicketFactory::createOne();
$message = Factory\MessageFactory::createOne([
'isConfidential' => true,
'ticket' => $ticket,
'content' => $content
Expand All @@ -180,12 +176,12 @@ public function testGetShowRendersConfidentialMessagesIfAccessIsGranted(): void
public function testGetShowHidesConfidentialMessagesIfAccessIsNotGranted(): void
{
$client = static::createClient();
$user = UserFactory::createOne();
$user = Factory\UserFactory::createOne();
$client->loginUser($user->_real());
$this->grantOrga($user->_real(), ['orga:see', 'orga:see:tickets:all']);
$content = 'The content of the answer';
$ticket = TicketFactory::createOne();
$message = MessageFactory::createOne([
$ticket = Factory\TicketFactory::createOne();
$message = Factory\MessageFactory::createOne([
'isConfidential' => true,
'ticket' => $ticket,
'content' => $content
Expand All @@ -200,9 +196,9 @@ public function testGetShowHidesConfidentialMessagesIfAccessIsNotGranted(): void
public function testGetShowRendersEvents(): void
{
$client = static::createClient();
$user = UserFactory::createOne();
$user = Factory\UserFactory::createOne();
$client->loginUser($user->_real());
$ticket = TicketFactory::createOne([
$ticket = Factory\TicketFactory::createOne([
'title' => 'The old title',
'createdBy' => $user,
]);
Expand All @@ -215,7 +211,7 @@ public function testGetShowRendersEvents(): void
$registry = $container->get('doctrine');
$entityManager = $registry->getManager();
/** @var \App\Repository\TicketRepository $ticketRepository */
$ticketRepository = $entityManager->getRepository(Ticket::class);
$ticketRepository = $entityManager->getRepository(Entity\Ticket::class);
$ticketRepository->save($ticket->_real(), true);

$client->request(Request::METHOD_GET, "/tickets/{$ticket->getUid()}");
Expand All @@ -229,10 +225,10 @@ public function testGetShowFailsIfAccessIsForbidden(): void
$this->expectException(AccessDeniedException::class);

$client = static::createClient();
$user = UserFactory::createOne();
$user = Factory\UserFactory::createOne();
$client->loginUser($user->_real());
$this->grantOrga($user->_real(), ['orga:see']);
$ticket = TicketFactory::createOne([
$ticket = Factory\TicketFactory::createOne([
'title' => 'My ticket',
]);

Expand All @@ -243,8 +239,8 @@ public function testGetShowFailsIfAccessIsForbidden(): void
public function testGetShowRedirectsToLoginIfNotConnected(): void
{
$client = static::createClient();
$user = UserFactory::createOne();
$ticket = TicketFactory::createOne([
$user = Factory\UserFactory::createOne();
$ticket = Factory\TicketFactory::createOne([
'title' => 'My ticket',
'createdBy' => $user,
]);
Expand Down

0 comments on commit fc44fda

Please sign in to comment.