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\UnaryNotSpecification;
13use Tests\Phexium\Fake\Domain\Specification\NameSpecification as FakeNameSpecification;
14
15describe('Evaluation', function (): void {
16    it('wraps specification with NOT operator in SQL', function (): void {
17        $nameSpec = new FakeNameSpecification('Foo');
18        $notSpec = new UnaryNotSpecification($nameSpec);
19
20        $result = $notSpec->toSql();
21
22        expect($result)->toBeArray();
23        expect($result)->toHaveKey('sql');
24        expect($result)->toHaveKey('params');
25        expect($result['sql'])->toBe('NOT (name = :name)');
26        expect($result['params'])->toBe(['name' => 'Foo']);
27    });
28
29    it('returns callable that inverts the logic', function (): void {
30        $nameSpec = new FakeNameSpecification('Foo');
31        $notSpec = new UnaryNotSpecification($nameSpec);
32
33        $filter = $notSpec->toInMemoryFilter();
34
35        expect($filter)->toBeCallable();
36
37        $matchingRow = ['id' => 1, 'name' => 'Foo'];
38        expect($filter($matchingRow))->toBeFalse();
39
40        $nonMatchingRow = ['id' => 2, 'name' => 'Bar'];
41        expect($filter($nonMatchingRow))->toBeTrue();
42    });
43});