63 lines
2 KiB
PHP
63 lines
2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Tests\Unit\Mapper;
|
||
|
|
|
||
|
|
require_once __DIR__ . '/PaginationMetaForTests.php';
|
||
|
|
|
||
|
|
use Uwil\ArcadiaApiPhpClient\Lib\ApiDto\Dto\Brand;
|
||
|
|
use Uwil\ArcadiaApiPhpClient\Lib\ApiDto\Dto\PageOf;
|
||
|
|
use Uwil\ArcadiaApiPhpClient\Lib\ApiDto\Dto\PaginationDto;
|
||
|
|
use Uwil\ArcadiaApiPhpClient\Mapper\BrandMapper;
|
||
|
|
use Uwil\ArcadiaKiotaOpenApiClient\Models\Brand as KiotaBrand;
|
||
|
|
use Uwil\ArcadiaKiotaOpenApiClient\Models\BrandListResponse;
|
||
|
|
|
||
|
|
describe('BrandMapper test', function () {
|
||
|
|
it('can instanciate BrandMapper', function () {
|
||
|
|
// GIVEN / WHEN
|
||
|
|
$brandMapper = new BrandMapper();
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($brandMapper)->toBeInstanceOf(BrandMapper::class);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('can map kiota model to a brand dto', function () {
|
||
|
|
// GIVEN
|
||
|
|
$kiotaModel = new KiotaBrand();
|
||
|
|
$kiotaModel->setName('Test Brand');
|
||
|
|
$kiotaModel->setCode('LGL39');
|
||
|
|
$kiotaModel->setArcadiaId('arcadia-id');
|
||
|
|
$kiotaModel->setCreatedAt(new \DateTime());
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$brandDto = (new BrandMapper())->toDto($kiotaModel);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($brandDto)->toBeInstanceOf(Brand::class);
|
||
|
|
expect($brandDto->label)->toBe('Test Brand');
|
||
|
|
expect($brandDto->code->value)->toBe('LGL39');
|
||
|
|
expect($brandDto->arcadiaId)->toBe('arcadia-id');
|
||
|
|
expect($brandDto->createdAt)->toBeInstanceOf(\DateTime::class);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('can map all properties from kiota model to brand dto', function () {
|
||
|
|
// GIVEN
|
||
|
|
[
|
||
|
|
$pagination,
|
||
|
|
$paginationMeta,
|
||
|
|
] = generaterFirstPagePaginationMeta();
|
||
|
|
$response = new BrandListResponse();
|
||
|
|
$response->setBrands([]);
|
||
|
|
$response->setPagination($paginationMeta);
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$brandPageDto = (new BrandMapper())->toPage($response, $pagination);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($brandPageDto)->toBeInstanceOf(PageOf::class);
|
||
|
|
expect($brandPageDto->items())->toBeArray();
|
||
|
|
expect($brandPageDto->pagination())->toBeInstanceOf(PaginationDto::class);
|
||
|
|
});
|
||
|
|
});
|