Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
24 / 24
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\User\Infrastructure\Mapper\UserMapper;
13use Phexium\Plugin\IdGenerator\Adapter\TimestampIdGenerator;
14use Tests\AppDemo\Fixture\UserMother;
15
16beforeEach(function (): void {
17    $this->mapper = new UserMapper(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            'email' => 'bob@example.com',
25            'password' => '$argon2id$v=19$hash',
26            'group_name' => 'user',
27        ];
28
29        expect($this->mapper->toRow($this->mapper->fromRow($row)))->toBe($row);
30    });
31
32    it('preserves entity from entity to row and back', function (): void {
33        $user = UserMother::admin(99);
34
35        $reconstituted = $this->mapper->fromRow($this->mapper->toRow($user));
36
37        expect($reconstituted->getId()->getValue())->toBe($user->getId()->getValue())
38            ->and($reconstituted->getEmail()->getValue())->toBe($user->getEmail()->getValue())
39            ->and($reconstituted->getHashedPassword()->getValue())->toBe($user->getHashedPassword()->getValue())
40            ->and($reconstituted->getGroup())->toBe($user->getGroup())
41        ;
42    });
43});