Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
26 / 26
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2
3// ╔════════════════════════════════════════════════════════════╗
4// ║ MIT Licence (#Expat) - https://opensource.org/licenses/MIT ║
5// ║ Copyright 2026 Frederic Poeydomenge <dyno@phexium.com>     ║
6// ╚════════════════════════════════════════════════════════════╝
7
8declare(strict_types=1);
9
10pest()->group('unit');
11
12use AppDemo\Library\Infrastructure\Mapper\BookMapper;
13use Phexium\Plugin\IdGenerator\Adapter\TimestampIdGenerator;
14use Tests\AppDemo\Fixture\BookMother;
15
16beforeEach(function (): void {
17    $this->mapper = new BookMapper(new TimestampIdGenerator());
18});
19
20describe('Round-trip', function (): void {
21    it('preserves data from row to entity and back', function (): void {
22        $row = [
23            'id' => 7,
24            'title' => 'Refactoring',
25            'author' => 'Martin Fowler',
26            'isbn' => '9780134757599',
27            'status' => 'available',
28        ];
29
30        expect($this->mapper->toRow($this->mapper->fromRow($row)))->toBe($row);
31    });
32
33    it('preserves entity from entity to row and back', function (): void {
34        $book = BookMother::borrowed(99);
35
36        $reconstituted = $this->mapper->fromRow($this->mapper->toRow($book));
37
38        expect($reconstituted->getId()->getValue())->toBe($book->getId()->getValue())
39            ->and($reconstituted->getTitle()->getValue())->toBe($book->getTitle()->getValue())
40            ->and($reconstituted->getAuthor()->getValue())->toBe($book->getAuthor()->getValue())
41            ->and($reconstituted->getIsbn()->getValue())->toBe($book->getIsbn()->getValue())
42            ->and($reconstituted->getStatus())->toBe($book->getStatus())
43        ;
44    });
45});