generated from spawnia/php-package-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpecificationTest.php
More file actions
43 lines (34 loc) · 1.22 KB
/
SpecificationTest.php
File metadata and controls
43 lines (34 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php declare(strict_types=1);
namespace MLL\Utils\Tests;
use MLL\Utils\Specification;
use PHPUnit\Framework\TestCase;
final class SpecificationTest extends TestCase
{
public function testNot(): void
{
$truthy = fn (string $value): bool => (bool) $value;
self::assertTrue($truthy('truthy'));
$negatedIdentity = Specification::not($truthy);
self::assertFalse($negatedIdentity('truthy'));
}
public function testOr(): void
{
$is1 = fn (int $value): bool => $value === 1;
$is2 = fn (int $value): bool => $value === 2;
$is1Or2 = Specification::or($is1, $is2);
self::assertTrue($is1Or2(1));
self::assertTrue($is1Or2(2));
self::assertFalse($is1Or2(3));
}
public function testAnd(): void
{
$isPositive = fn (int $value): bool => $value > 0;
$isOdd = fn (int $value): bool => $value % 2 === 1;
$isPositiveAndOdd = Specification::and($isPositive, $isOdd);
self::assertTrue($isPositiveAndOdd(1));
self::assertFalse($isPositiveAndOdd(2));
self::assertFalse($isPositiveAndOdd(-1));
self::assertFalse($isPositiveAndOdd(0));
self::assertFalse($isPositiveAndOdd(-2));
}
}