Skip to content

Commit

Permalink
misc: Change namespace imports in ContractsControllerTest
Browse files Browse the repository at this point in the history
  • Loading branch information
marien-probesys committed Dec 11, 2024
1 parent 931218c commit e73f9b6
Showing 1 changed file with 28 additions and 34 deletions.
62 changes: 28 additions & 34 deletions tests/Controller/ContractsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@

namespace App\Tests\Controller;

use App\Tests\AuthorizationHelper;
use App\Tests\FactoriesHelper;
use App\Tests\Factory\ContractFactory;
use App\Tests\Factory\OrganizationFactory;
use App\Tests\Factory\TicketFactory;
use App\Tests\Factory\TimeSpentFactory;
use App\Tests\Factory\UserFactory;
use App\Tests\SessionHelper;
use App\Tests;
use App\Tests\Factory;
use App\Utils;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -23,24 +17,24 @@

class ContractsControllerTest extends WebTestCase
{
use AuthorizationHelper;
use Factories;
use FactoriesHelper;
use ResetDatabase;
use SessionHelper;
use Tests\AuthorizationHelper;
use Tests\FactoriesHelper;
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:contracts']);
$contract1 = ContractFactory::createOne([
$contract1 = Factory\ContractFactory::createOne([
'name' => 'My contract 1',
'startAt' => Utils\Time::ago(1, 'months'),
'endAt' => Utils\Time::fromNow(1, 'months'),
]);
$contract2 = ContractFactory::createOne([
$contract2 = Factory\ContractFactory::createOne([
'name' => 'My contract 2',
'startAt' => Utils\Time::ago(1, 'months'),
'endAt' => Utils\Time::fromNow(2, 'months'),
Expand All @@ -56,31 +50,31 @@ public function testGetIndexRendersCorrectly(): void
public function testGetIndexRendersCorrectlyListsOnlyAccessibleContracts(): void
{
$client = static::createClient();
$user = UserFactory::createOne();
$user = Factory\UserFactory::createOne();
$client->loginUser($user->_real());
$organization1 = OrganizationFactory::createOne();
$organization2 = OrganizationFactory::createOne();
$organization3 = OrganizationFactory::createOne();
$organization1 = Factory\OrganizationFactory::createOne();
$organization2 = Factory\OrganizationFactory::createOne();
$organization3 = Factory\OrganizationFactory::createOne();
$this->grantOrga($user->_real(), [
'orga:see',
'orga:see:contracts'
], $organization1->_real());
$this->grantOrga($user->_real(), [
'orga:see',
], $organization2->_real());
$contract1 = ContractFactory::createOne([
$contract1 = Factory\ContractFactory::createOne([
'name' => 'My contract 1',
'organization' => $organization1,
'startAt' => Utils\Time::ago(1, 'months'),
'endAt' => Utils\Time::fromNow(1, 'months'),
]);
$contract2 = ContractFactory::createOne([
$contract2 = Factory\ContractFactory::createOne([
'name' => 'My contract 2',
'organization' => $organization2,
'startAt' => Utils\Time::ago(1, 'months'),
'endAt' => Utils\Time::fromNow(1, 'months'),
]);
$contract3 = ContractFactory::createOne([
$contract3 = Factory\ContractFactory::createOne([
'name' => 'My contract 3',
'organization' => $organization3,
'startAt' => Utils\Time::ago(1, 'months'),
Expand All @@ -99,10 +93,10 @@ public function testGetIndexFailsIfAccessIsForbidden(): 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']);
$contract = ContractFactory::createOne([
$contract = Factory\ContractFactory::createOne([
'startAt' => Utils\Time::ago(1, 'months'),
'endAt' => Utils\Time::fromNow(1, 'months'),
]);
Expand All @@ -114,10 +108,10 @@ public function testGetIndexFailsIfAccessIsForbidden(): void
public function testGetEditRendersCorrectly(): void
{
$client = static::createClient();
$user = UserFactory::createOne();
$user = Factory\UserFactory::createOne();
$client->loginUser($user->_real());
$this->grantOrga($user->_real(), ['orga:manage:contracts']);
$contract = ContractFactory::createOne();
$contract = Factory\ContractFactory::createOne();

$client->request(Request::METHOD_GET, "/contracts/{$contract->getUid()}/edit");

Expand All @@ -130,9 +124,9 @@ public function testGetEditFailsIfAccessIsForbidden(): void
$this->expectException(AccessDeniedException::class);

$client = static::createClient();
$user = UserFactory::createOne();
$user = Factory\UserFactory::createOne();
$client->loginUser($user->_real());
$contract = ContractFactory::createOne();
$contract = Factory\ContractFactory::createOne();

$client->catchExceptions(false);
$client->request(Request::METHOD_GET, "/contracts/{$contract->getUid()}/edit");
Expand All @@ -141,14 +135,14 @@ public function testGetEditFailsIfAccessIsForbidden(): void
public function testPostEditSavesTheContract(): void
{
$client = static::createClient();
$user = UserFactory::createOne();
$user = Factory\UserFactory::createOne();
$client->loginUser($user->_real());
$this->grantOrga($user->_real(), ['orga:manage:contracts']);
$oldName = 'Contract 2023';
$newName = 'Contract 2024';
$oldMaxHours = 5;
$newMaxHours = 10;
$contract = ContractFactory::createOne([
$contract = Factory\ContractFactory::createOne([
'name' => $oldName,
'maxHours' => $oldMaxHours,
]);
Expand All @@ -170,18 +164,18 @@ public function testPostEditSavesTheContract(): void
public function testPostEditDoesNotAcceptMaxHoursBelowSpentTime(): void
{
$client = static::createClient();
$user = UserFactory::createOne();
$user = Factory\UserFactory::createOne();
$client->loginUser($user->_real());
$this->grantOrga($user->_real(), ['orga:manage:contracts']);
$oldName = 'Contract 2023';
$newName = 'Contract 2024';
$oldMaxHours = 10;
$newMaxHours = 1;
$contract = ContractFactory::createOne([
$contract = Factory\ContractFactory::createOne([
'name' => $oldName,
'maxHours' => $oldMaxHours,
]);
$timeSpent = TimeSpentFactory::createOne([
$timeSpent = Factory\TimeSpentFactory::createOne([
'time' => ($newMaxHours + 1) * 60,
'contract' => $contract,
]);
Expand All @@ -207,14 +201,14 @@ public function testPostEditDoesNotAcceptMaxHoursBelowSpentTime(): void
public function testPostEditFailsIfCsrfTokenIsInvalid(): void
{
$client = static::createClient();
$user = UserFactory::createOne();
$user = Factory\UserFactory::createOne();
$client->loginUser($user->_real());
$this->grantOrga($user->_real(), ['orga:manage:contracts']);
$oldName = 'Contract 2023';
$newName = 'Contract 2024';
$oldMaxHours = 5;
$newMaxHours = 10;
$contract = ContractFactory::createOne([
$contract = Factory\ContractFactory::createOne([
'name' => $oldName,
'maxHours' => $oldMaxHours,
]);
Expand Down

0 comments on commit e73f9b6

Please sign in to comment.