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