/
AggregaterTest.php
115 lines (104 loc) · 3.56 KB
/
AggregaterTest.php
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
namespace AssertChain\Container\Test;
use AssertChain\AssertChain;
use PHPUnit\Framework\TestCase;
class AggregaterTest extends TestCase
{
use AssertChain;
/**
* @test
*/
public function assertReturnAggregater()
{
$this->assertInstanceOf('\AssertChain\Container\Aggregater', $this->centralizedAssert('some value'));
}
public function testWithArray()
{
$this->centralizedAssert(['key' => 'value'])
->notNull()
->notEmpty()
->notCount(0)
->count(1)
->arrayNotHasKey('no existing key')
->arrayHasKey('key')
->notContains('no existing value')
->contains('value')
->equals(['key' => 'value']);
}
public function testWithInt()
{
$this->centralizedAssert(10)
->notTrue()
->notFalse()
->notInternalType('float')
->internalType('integer')
->lessThan(11)
->lessThanOrEqual(10)
->notEquals('11')
->equals('10')
->notSame('10')
->same(10);
}
public function testWithString()
{
$this->centralizedAssert('test string')
->stringStartsNotWith('a')
->stringStartsWith('tes')
->stringEndsNotWith('a')
->stringEndsWith('ing')
->notRegExp('/^not matches/')
->regExp('/^test/')
->regExp('/string$/');
}
public function testWithJsonString()
{
$this->centralizedAssert('{"test":"json"}')
->json()
->jsonStringNotEqualsJsonString('{"wrong":"json"}')
->jsonStringEqualsJsonString('{"test":"json"}');
}
public function testWithClass()
{
$this->centralizedAssert('\AssertChain\Container\Test\SampleClass')
->classNotHasAttribute('no existing attribute')
->classHasAttribute('attrInt1')
->classNotHasStaticAttribute('no existing static attribute')
->classHasStaticAttribute('staticAttr');
}
public function testWithObject()
{
$this->centralizedAssert(new SampleClass(20, new \stdClass))
->objectNotHasAttribute('no existing attribute')
->objectHasAttribute('attrInt2')
->attributeNotEmpty('attrArray')
->attributeNotCount(4, 'attrArray')
->attributeCount(3, 'attrArray')
->attributeNotContains(4, 'attrArray')
->attributeContains(1, 'attrArray')
->attributeNotContainsOnly('string', 'attrArray')
->attributeContainsOnly('integer', 'attrArray')
->attributeGreaterThanOrEqual(10, 'attrInt1')
->attributeGreaterThan(9, 'attrInt1')
->attributeLessThanOrEqual(20, 'attrInt2')
->attributeLessThan(21, 'attrInt2')
->attributeNotEquals(21, 'attrInt2')
->attributeEquals('20', 'attrInt2')
->attributeNotInternalType('string', 'attrInt2')
->attributeInternalType('integer', 'attrInt2')
->attributeNotSame('20', 'attrInt2')
->attributeSame(20, 'attrInt2')
->attributeNotInstanceOf('\AssertChain\Container\Test\SampleClass', 'attrStdClass')
->attributeInstanceOf('\stdClass', 'attrStdClass');
}
}
class SampleClass
{
public $attrInt1 = 10;
public static $staticAttr = 'staticValue1';
public $attrArray = [1, 2, 3];
public function __construct($int, $stdClass)
{
$this->attrInt2 = $int;
$this->attrStdClass = $stdClass;
}
}