Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
21 / 21
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 Tests\Phexium\Fake\Domain\Specification\NameSpecification as FakeNameSpecification;
13
14describe('Evaluation', function (): void {
15    it('generates correct SQL and params', function (): void {
16        $specification = new FakeNameSpecification('Foo');
17
18        $result = $specification->toSql();
19
20        expect($result)->toBeArray();
21        expect($result)->toHaveKey('sql');
22        expect($result)->toHaveKey('params');
23        expect($result['sql'])->toBe('name = :name');
24        expect($result['params'])->toBe(['name' => 'Foo']);
25    });
26
27    it('returns callable that filters by name', function (): void {
28        $specification = new FakeNameSpecification('Foo');
29
30        $filter = $specification->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    });
40});