Test Failed
Branch master (5e8424)
by Randy
02:43
created

ArrayEnsuranceTest::testHasLengthOf()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
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
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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
}