Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
23 / 23
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 Phexium\Domain\Specification\UnaryIdentitySpecification;
13use Tests\Phexium\Fake\Domain\Specification\NameSpecification as FakeNameSpecification;
14
15describe('Evaluation', function (): void {
16    it('returns SQL unchanged from wrapped specification', function (): void {
17        $nameSpec = new FakeNameSpecification('Foo');
18        $identitySpec = new UnaryIdentitySpecification($nameSpec);
19
20        $result = $identitySpec->toSql();
21
22        expect($result)->toBeArray();
23        expect($result)->toHaveKey('sql');
24        expect($result)->toHaveKey('params');
25        expect($result['sql'])->toBe('name = :name');
26        expect($result['params'])->toBe(['name' => 'Foo']);
27    });
28
29    it('returns callable that applies wrapped specification logic', function (): void {
30        $nameSpec = new FakeNameSpecification('Foo');
31        $identitySpec = new UnaryIdentitySpecification($nameSpec);
32
33        $filter = $identitySpec->toInMemoryFilter();
34
35        expect($filter)->toBeCallable();
36
37        $matchingRow = ['id' => 1, 'name' => 'Foo'];
38        expect($filter($matchingRow))->toBeTrue();
39
40        $nonMatchingRow = ['id' => 2, 'name' => 'Bar'];
41        expect($filter($nonMatchingRow))->toBeFalse();
42    });
43});