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