|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Dgame\Ensurance\Exception\EnsuranceException; |
|
4
|
|
|
use PHPUnit\Framework\TestCase; |
|
5
|
|
|
use function Dgame\Ensurance\ensure; |
|
6
|
|
|
|
|
7
|
|
|
class ArrayEnsuranceTest extends TestCase |
|
|
|
|
|
|
8
|
|
|
{ |
|
9
|
|
|
public function testHasKey() |
|
10
|
|
|
{ |
|
11
|
|
|
ensure(['a' => 'b'])->isArray()->hasKey('a'); |
|
12
|
|
|
|
|
13
|
|
|
$this->expectException(EnsuranceException::class); |
|
14
|
|
|
|
|
15
|
|
|
ensure(['a' => 'b'])->isArray()->hasKey('b'); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function testHasValue() |
|
19
|
|
|
{ |
|
20
|
|
|
ensure(['a', 'b'])->isArray()->hasValue('a'); |
|
21
|
|
|
ensure(['a', 'b'])->isArray()->hasValue('b'); |
|
22
|
|
|
|
|
23
|
|
|
$this->expectException(EnsuranceException::class); |
|
24
|
|
|
|
|
25
|
|
|
ensure(['a', 'b'])->isArray()->hasValue('c'); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testHasLengthOf() |
|
29
|
|
|
{ |
|
30
|
|
|
ensure([])->isArray()->hasLengthOf(0); |
|
31
|
|
|
ensure(range(0, 99))->isArray()->hasLengthOf(100); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testIsShorterThan() |
|
35
|
|
|
{ |
|
36
|
|
|
ensure([1, 2, 3])->isArray()->isShorterThan(4); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testIsShorterOrEqualsTo() |
|
40
|
|
|
{ |
|
41
|
|
|
ensure([1, 2, 3])->isArray()->isShorterOrEqualsTo(4); |
|
42
|
|
|
ensure([1, 2, 3])->isArray()->isShorterOrEqualsTo(3); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testIsLongerThan() |
|
46
|
|
|
{ |
|
47
|
|
|
ensure([1, 2, 3])->isArray()->isLongerThan(2); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testIsLongerOrEqualTo() |
|
51
|
|
|
{ |
|
52
|
|
|
ensure([1, 2, 3])->isArray()->isLongerOrEqualTo(3); |
|
53
|
|
|
ensure([1, 2, 3])->isArray()->isLongerOrEqualTo(2); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testIsAssociative() |
|
57
|
|
|
{ |
|
58
|
|
|
ensure(['a' => 'b'])->isArray()->isAssociative(); |
|
59
|
|
|
|
|
60
|
|
|
$this->expectException(EnsuranceException::class); |
|
61
|
|
|
|
|
62
|
|
|
ensure(['a', 'b'])->isArray()->isAssociative(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testIsNotAssociative() |
|
66
|
|
|
{ |
|
67
|
|
|
ensure(['a', 'b'])->isArray()->isNotAssociative(); |
|
68
|
|
|
|
|
69
|
|
|
$this->expectException(EnsuranceException::class); |
|
70
|
|
|
|
|
71
|
|
|
ensure(['a' => 'b'])->isArray()->isNotAssociative(); |
|
72
|
|
|
} |
|
73
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.