toBeInstanceOf(IncoShortMapper::class); }); it('can map kiota model to an inco short dto', function () { // GIVEN $kiotaModel = new KiotaIncoShort(); $kiotaModel->setIncoId('123'); $kiotaModel->setName('Poulet rôti'); $kiotaModel->setLabel('Poulet rôti 1kg'); $kiotaModel->setDescription('Délicieux poulet rôti aux herbes'); $kiotaModel->setCreatedAt(new DateTime('2024-01-01 10:00:00')); $kiotaModel->setUpdatedAt(new DateTime('2024-06-01 12:00:00')); // WHEN $incoShortDto = (new IncoShortMapper())->toDto($kiotaModel); // THEN expect($incoShortDto)->toBeInstanceOf(IncoShort::class); expect($incoShortDto->id)->toBeInstanceOf(IncoId::class); expect($incoShortDto->id->value)->toBe('123'); expect($incoShortDto->name)->toBe('Poulet rôti'); expect($incoShortDto->libelle)->toBe('Poulet rôti 1kg'); expect($incoShortDto->description)->toBe('Délicieux poulet rôti aux herbes'); expect($incoShortDto->created_at)->toBeInstanceOf(DateTimeInterface::class); expect($incoShortDto->created_at?->format('Y-m-d H:i:s'))->toBe('2024-01-01 10:00:00'); expect($incoShortDto->updated_at)->toBeInstanceOf(DateTimeInterface::class); expect($incoShortDto->updated_at?->format('Y-m-d H:i:s'))->toBe('2024-06-01 12:00:00'); }); it('can map kiota model with null optional properties to an inco short dto', function () { // GIVEN $kiotaModel = new KiotaIncoShort(); // WHEN $incoShortDto = (new IncoShortMapper())->toDto($kiotaModel); // THEN expect($incoShortDto)->toBeInstanceOf(IncoShort::class); expect($incoShortDto->id)->toBeInstanceOf(IncoId::class); expect($incoShortDto->id->value)->toBe('0'); expect($incoShortDto->name)->toBe(''); expect($incoShortDto->libelle)->toBe(''); expect($incoShortDto->description)->toBe(''); expect($incoShortDto->created_at)->toBeNull(); expect($incoShortDto->updated_at)->toBeNull(); }); it('can map all properties from kiota model to inco short dto', function () { // GIVEN [ $pagination, $paginationMeta, ] = generaterFirstPagePaginationMeta(); $response = new IncoListResponse(); $response->setIncoSheets([]); $response->setPagination($paginationMeta); // WHEN $incoShortPageDto = (new IncoShortMapper())->toPage($response, $pagination); // THEN expect($incoShortPageDto)->toBeInstanceOf(PageOf::class); expect($incoShortPageDto->items())->toBeArray(); expect($incoShortPageDto->pagination())->toBeInstanceOf(PaginationDto::class); }); it('can map list response with items to page of inco short dto', function () { // GIVEN [ $pagination, $paginationMeta, ] = generaterFirstPagePaginationMeta(); $kiotaIncoShort = new KiotaIncoShort(); $kiotaIncoShort->setIncoId('456'); $kiotaIncoShort->setName('Nuggets'); $kiotaIncoShort->setLabel('Nuggets de poulet'); $kiotaIncoShort->setDescription('Nuggets croustillants'); $response = new IncoListResponse(); $response->setIncoSheets([$kiotaIncoShort]); $response->setPagination($paginationMeta); // WHEN $incoShortPageDto = (new IncoShortMapper())->toPage($response, $pagination); // THEN expect($incoShortPageDto)->toBeInstanceOf(PageOf::class); expect($incoShortPageDto->items())->toHaveCount(1); expect($incoShortPageDto->items()[0])->toBeInstanceOf(IncoShort::class); expect($incoShortPageDto->items()[0]->id->value)->toBe('456'); expect($incoShortPageDto->items()[0]->name)->toBe('Nuggets'); expect($incoShortPageDto->items()[0]->libelle)->toBe('Nuggets de poulet'); expect($incoShortPageDto->items()[0]->description)->toBe('Nuggets croustillants'); }); });