Skip to content

Commit

Permalink
tests fix
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasHermanek committed Dec 11, 2023
1 parent 27a8571 commit 6bd7c78
Show file tree
Hide file tree
Showing 22 changed files with 72 additions and 71 deletions.
6 changes: 3 additions & 3 deletions tests/Controller/Api/AbstractApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ abstract class AbstractApiController extends AbstractController
/** @psalm-var array<string, ApiClient> */
private array $clients = [];

public function getClient(?int $userId = null): ApiClient
public function getApiClient(?int $newClient = null): ApiClient
{
$key = $userId ?? 'anonymous';
$key = $newClient ?? 'anonymous';
if (false === isset($this->clients[$key])) {
$this->clients[$key] = new ApiClient(
static::$client,
$this->serializer,
$userId
$newClient
);
}
return $this->clients[$key];
Expand Down
2 changes: 1 addition & 1 deletion tests/Controller/Api/AbstractAssetFileApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ protected function testSlotsSuccess(
AssetUrlInterface $url,
): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);

$primarySlotName = $firstAssetFile->getSlots()->first()->getName();
$asset = $firstAssetFile->getAsset();
Expand Down
6 changes: 3 additions & 3 deletions tests/Controller/Api/Adm/V1/AssetApiControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class AssetApiControllerTest extends AbstractAssetFileApiController
*/
public function testUpdate(int $statusCode, ?string $categoryId = null): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);
$video = $this->entityManager->find(VideoFile::class, VideoFixtures::VIDEO_ID_1);

$response = $client->put(
Expand Down Expand Up @@ -80,7 +80,7 @@ protected function setUp(): void
*/
public function testDelete(): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);
$imageUrl = new ImageUrl(AssetLicenceFixtures::DEFAULT_LICENCE_ID);

$image = $this->uploadAsset(
Expand Down Expand Up @@ -122,7 +122,7 @@ public function testDelete(): void
*/
public function testCreate(string $type): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);
$response = $client->post('/api/adm/v1/asset/licence/'.AssetLicenceFixtures::DEFAULT_LICENCE_ID, ['type' => $type]);

$this->assertEquals(Response::HTTP_CREATED, $response->getStatusCode());
Expand Down
4 changes: 2 additions & 2 deletions tests/Controller/Api/Adm/V1/AssetCustomFormControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class AssetCustomFormControllerTest extends AbstractApiController
*/
public function testGetOneSuccess(): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);
$response = $client->get('/api/adm/v1/asset-custom-form/ext-system/1/type/image');
$this->assertSame(Response::HTTP_OK, $response->getStatusCode());

Expand All @@ -46,7 +46,7 @@ public function testGetOneSuccess(): void
*/
public function testGetElementsSuccess(): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);
$response = $client->get('/api/adm/v1/asset-custom-form/ext-system/1/type/image/element');

$this->assertSame(Response::HTTP_OK, $response->getStatusCode());
Expand Down
10 changes: 5 additions & 5 deletions tests/Controller/Api/Adm/V1/AssetLicenceControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class AssetLicenceControllerTest extends AbstractApiController
*/
public function testGetOneSuccess(): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);

$response = $client->get(AssetLicenceUrl::getOne(AssetLicenceFixtures::DEFAULT_LICENCE_ID));
$this->assertSame(Response::HTTP_OK, $response->getStatusCode());
Expand All @@ -49,7 +49,7 @@ public function testGetOneSuccess(): void
*/
public function testGetListSuccess(): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);

$response = $client->get(AssetLicenceUrl::getList());
$this->assertSame(Response::HTTP_OK, $response->getStatusCode());
Expand All @@ -72,7 +72,7 @@ public function testGetListSuccess(): void
*/
public function testCreateSuccess(array $requestJson, int $expectedResponseStatusCode): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);

$response = $client->post(AssetLicenceUrl::createPath(), $requestJson);
$this->assertSame($expectedResponseStatusCode, $response->getStatusCode());
Expand Down Expand Up @@ -109,7 +109,7 @@ public function createSuccessDataProvider(): array
*/
public function testCreateFailure(array $requestJson, array $validationErrors): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);

$response = $client->post(AssetLicenceUrl::createPath(), $requestJson);
$this->assertSame(Response::HTTP_UNPROCESSABLE_ENTITY, $response->getStatusCode());
Expand Down Expand Up @@ -160,7 +160,7 @@ public function createFailureDataProvider(): array
*/
public function testUpdateSuccess(array $requestJson, int $expectedResponseStatusCode): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);

$id = $requestJson['id'];
$response = $client->put(AssetLicenceUrl::update($id), $requestJson);
Expand Down
6 changes: 3 additions & 3 deletions tests/Controller/Api/Adm/V1/AssetSlotControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected function setUp(): void
*/
public function testGetListSuccess(): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);


$audioFile = $this->audioFileRepository->find(AudioFixtures::AUDIO_ID_1);
Expand All @@ -56,7 +56,7 @@ public function testGetListSuccess(): void
*/
public function testUpdateSlot(array $reqJson): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);
$audioFile = $this->audioFileRepository->find(AudioFixtures::AUDIO_ID_1);

$response = $client->patch(
Expand All @@ -74,7 +74,7 @@ public function testUpdateSlot(array $reqJson): void
*/
public function testUpdateSlotFailed(array $reqJson): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);
$audioFile = $this->audioFileRepository->find(AudioFixtures::AUDIO_ID_1);

$response = $client->patch(
Expand Down
2 changes: 1 addition & 1 deletion tests/Controller/Api/Adm/V1/AudioApiControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class AudioApiControllerTest extends AbstractAssetFileApiController
*/
public function testUpload(): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);
$audioUrl = new AudioUrl(AssetLicenceFixtures::DEFAULT_LICENCE_ID);

$audio = $this->uploadAsset(
Expand Down
10 changes: 5 additions & 5 deletions tests/Controller/Api/Adm/V1/AuthorControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class AuthorControllerTest extends AbstractApiController
*/
public function testGetOneSuccess(): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);

$response = $client->get(AuthorUrl::getOne(AuthorFixtures::AUTHOR_1));
$this->assertSame(Response::HTTP_OK, $response->getStatusCode());
Expand All @@ -47,7 +47,7 @@ public function testGetOneSuccess(): void
*/
public function testSearchByExtSystemSuccess(): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);

$response = $client->get(AuthorUrl::searchByExtSystem(ExtSystemFixtures::ID_CMS));
$this->assertSame(Response::HTTP_OK, $response->getStatusCode());
Expand All @@ -70,7 +70,7 @@ public function testSearchByExtSystemSuccess(): void
*/
public function testCreateSuccess(array $requestJson, int $expectedResponseStatusCode): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);

$response = $client->post(AuthorUrl::createPath(), $requestJson);
$this->assertSame($expectedResponseStatusCode, $response->getStatusCode());
Expand Down Expand Up @@ -105,7 +105,7 @@ public function createSuccessDataProvider(): array
*/
public function testCreateFailure(array $requestJson, array $validationErrors): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);

$response = $client->post(AuthorUrl::createPath(), $requestJson);
$this->assertSame(Response::HTTP_UNPROCESSABLE_ENTITY, $response->getStatusCode());
Expand Down Expand Up @@ -156,7 +156,7 @@ public function createFailureDataProvider(): array
*/
public function testUpdateSuccess(array $requestJson, int $expectedResponseStatusCode): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);

$id = $requestJson['id'];
$response = $client->put(AuthorUrl::update($id), $requestJson);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class DistributionCategorySelectTest extends AbstractApiController
*/
public function testGetOneSuccess(): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);

$distributionCategorySelectRepository = self::getContainer()->get(DistributionCategorySelectRepository::class);
$fromDb = $distributionCategorySelectRepository->findOneBy([]);
Expand All @@ -46,7 +46,7 @@ public function testGetOneSuccess(): void
*/
public function testGetListSuccess(): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);

$response = $client->get(DistributionCategorySelectUrl::getList(ExtSystemFixtures::ID_CMS));
$this->assertSame(Response::HTTP_OK, $response->getStatusCode());
Expand All @@ -64,7 +64,7 @@ public function testGetListSuccess(): void
*/
public function testUpdateSuccess(): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);

$distributionCategorySelectRepository = self::getContainer()->get(DistributionCategorySelectRepository::class);
$fromDb = $distributionCategorySelectRepository->findOneBy([]);
Expand Down
2 changes: 1 addition & 1 deletion tests/Controller/Api/Adm/V1/DocumentApiControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class DocumentApiControllerTest extends AbstractAssetFileApiController
*/
public function testUpload(): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);
$documentUrl = new DocumentUrl(AssetLicenceFixtures::DEFAULT_LICENCE_ID);

$document = $this->uploadAsset(
Expand Down
8 changes: 4 additions & 4 deletions tests/Controller/Api/Adm/V1/ExtSystemControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class ExtSystemControllerTest extends AbstractApiController
*/
public function testGetOneSuccess(): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);

$response = $client->get(ExtSystemUrl::getOne(ExtSystemFixtures::ID_CMS));
$this->assertSame(Response::HTTP_OK, $response->getStatusCode());
Expand All @@ -46,7 +46,7 @@ public function testGetOneSuccess(): void
*/
public function testGetListSuccess(): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);

$response = $client->get(ExtSystemUrl::getList());
$this->assertSame(Response::HTTP_OK, $response->getStatusCode());
Expand All @@ -66,7 +66,7 @@ public function testGetListSuccess(): void
*/
public function testUpdateSuccess(array $requestJson, int $expectedResponseStatusCode): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);

$id = $requestJson['id'];
$response = $client->put(ExtSystemUrl::update($id), $requestJson);
Expand Down Expand Up @@ -106,7 +106,7 @@ public function updateSuccessDataProvider(): array
*/
public function testUpdateFailure(array $requestJson, array $validationErrors): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);

$id = $requestJson['id'];
$response = $client->put(ExtSystemUrl::update($id), $requestJson);
Expand Down
12 changes: 6 additions & 6 deletions tests/Controller/Api/Adm/V1/ImageApiControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function setUp(): void
public function testUpload(): void
{
$rotation = 90;
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);
$imageUrl = new ImageUrl(AssetLicenceFixtures::DEFAULT_LICENCE_ID);

$image = $this->uploadAsset(
Expand Down Expand Up @@ -103,7 +103,7 @@ public function testUpload(): void

public function testCreateToAsset(): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);
$response = $client->post(AssetUrl::createPath(), ['type' => 'image']);
$this->assertEquals(Response::HTTP_CREATED, $response->getStatusCode());
$asset = $this->serializer->deserialize($response->getContent(), AssetAdmDetailDto::class);
Expand Down Expand Up @@ -135,7 +135,7 @@ public function testSetSlotSuccess(): void
*/
public function testCreateToAssetFailed(string $imageId, string $slot, string $error): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);
$response = $client->post(AssetUrl::createPath(), ['type' => 'image']);
$this->assertEquals(Response::HTTP_CREATED, $response->getStatusCode());
$asset = $this->serializer->deserialize($response->getContent(), AssetAdmDetailDto::class);
Expand All @@ -162,7 +162,7 @@ public function createToAssetFailedDataProvider(): array

public function testCreateImageFailed(): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);

$responseData = $this->createAsset(
$client,
Expand Down Expand Up @@ -193,7 +193,7 @@ public function testCreateImageFailed(): void
*/
public function testAddChunkFailed(array $reqBody, array $validationFieldsBody): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);

$responseData = $this->uploadChunk(
$client,
Expand Down Expand Up @@ -245,7 +245,7 @@ public function addChunkFailedDataProvider(): array

public function testFinishUploadFailed(): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);

$responseData = $this->finishUpload(
$client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class JwDistributionControllerTest extends AbstractApiController
*/
public function testGetOneSuccess(): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);

$payload = [
'distributionService' => 'jw_cms_main',
Expand Down
10 changes: 5 additions & 5 deletions tests/Controller/Api/Adm/V1/KeywordControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class KeywordControllerTest extends AbstractApiController
*/
public function testGetOneSuccess(): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);

$response = $client->get(KeywordUrl::getOne(KeywordFixtures::KEYWORD_1));
$this->assertSame(Response::HTTP_OK, $response->getStatusCode());
Expand All @@ -47,7 +47,7 @@ public function testGetOneSuccess(): void
*/
public function testSearchByExtSystemSuccess(): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);

$response = $client->get(KeywordUrl::searchByExtSystem(ExtSystemFixtures::ID_CMS));
$this->assertSame(Response::HTTP_OK, $response->getStatusCode());
Expand All @@ -70,7 +70,7 @@ public function testSearchByExtSystemSuccess(): void
*/
public function testCreateSuccess(array $requestJson, int $expectedResponseStatusCode): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);

$response = $client->post(KeywordUrl::createPath(), $requestJson);
$this->assertSame($expectedResponseStatusCode, $response->getStatusCode());
Expand Down Expand Up @@ -105,7 +105,7 @@ public function createSuccessDataProvider(): array
*/
public function testCreateFailure(array $requestJson, array $validationErrors): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);

$response = $client->post(KeywordUrl::createPath(), $requestJson);
$this->assertSame(Response::HTTP_UNPROCESSABLE_ENTITY, $response->getStatusCode());
Expand Down Expand Up @@ -156,7 +156,7 @@ public function createFailureDataProvider(): array
*/
public function testUpdateSuccess(array $requestJson, int $expectedResponseStatusCode): void
{
$client = $this->getClient(User::ID_ADMIN);
$client = $this->getApiClient(User::ID_ADMIN);

$id = $requestJson['id'];
$response = $client->put(KeywordUrl::update($id), $requestJson);
Expand Down
Loading

0 comments on commit 6bd7c78

Please sign in to comment.