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