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

StringEnsuranceTest::testIsCallable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 8
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 StringEnsuranceTest 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 testIsEqualTo()
10
    {
11
        ensure('foo')->isString()->isEqualTo('foo');
12
    }
13
14
    public function testIsNotEqualTo()
15
    {
16
        ensure('foo')->isString()->isNotEqualTo('bar');
17
    }
18
19
    public function testMatch()
20
    {
21
        ensure('test@foo')->isString()->match('#^[a-z]+@\w{3}$#i');
22
    }
23
24
    public function testHasLengthOf()
25
    {
26
        ensure('foo')->isString()->hasLengthOf(3);
27
    }
28
29
    public function testIsShorterThan()
30
    {
31
        ensure('foo')->isString()->isShorterThan(4);
32
    }
33
34
    public function testIsShorterOrEqualTo()
35
    {
36
        ensure('foo')->isString()->isShorterOrEqualTo(3);
37
    }
38
39
    public function testIsLongerThan()
40
    {
41
        ensure('foo')->isString()->isLongerThan(2);
42
    }
43
44
    public function testIsLongerorEqualTo()
45
    {
46
        ensure('foo')->isString()->isLongerOrEqualTo(2);
47
        ensure('foo')->isString()->isLongerOrEqualTo(3);
48
    }
49
50
    public function testBeginsWith()
51
    {
52
        ensure('FooBar')->isString()->beginsWith('Fo');
53
54
        $this->expectException(EnsuranceException::class);
55
56
        ensure('Foo')->isString()->beginsWith('fo');
57
    }
58
59
    public function testEndsWith()
60
    {
61
        ensure('FooBar')->isString()->endsWith('ar');
62
63
        $this->expectException(EnsuranceException::class);
64
65
        ensure('Bar')->isString()->endsWith('R');
66
    }
67
68
    public function testIsCallable()
69
    {
70
        ensure('trim')->isString()->isCallable();
71
72
        $this->expectException(EnsuranceException::class);
73
74
        ensure('foo')->isString()->isCallable();
75
    }
76
77
    public function testIsClass()
78
    {
79
        ensure(static::class)->isString()->isClass();
80
81
        $this->expectException(EnsuranceException::class);
82
83
        ensure(uniqid())->isString()->isClass();
84
    }
85
}