VerifyTest.php
6.76 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?php
include __DIR__.'/../src/Codeception/function.php';
include __DIR__.'/../vendor/autoload.php';
class VerifyTest extends PHPUnit_Framework_TestCase {
protected $xml;
protected function setUp()
{
$this->xml = new DomDocument;
$this->xml->loadXML('<foo><bar>Baz</bar><bar>Baz</bar></foo>');
}
public function testEquals()
{
verify(5)->equals(5);
verify("hello")->equals("hello");
verify("user have 5 posts", 5)->equals(5);
verify(3.251)->equals(3.25, 0.01);
verify("respects delta", 3.251)->equals(3.25, 0.01);
verify_file(__FILE__)->equals(__FILE__);
}
public function testNotEquals()
{
verify(3)->notEquals(5);
verify(3.252)->notEquals(3.25, 0.001);
verify("respects delta", 3.252, 0.001);
verify_file(__FILE__)->notEquals(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'composer.json');
}
public function testContains()
{
verify(array(3, 2))->contains(3);
verify("user have 5 posts", array(3, 2))->notContains(5);
}
public function testGreaterLowerThan()
{
verify(7)->greaterThan(5);
verify(7)->lessThan(10);
verify(7)->lessOrEquals(7);
verify(7)->lessOrEquals(8);
verify(7)->greaterOrEquals(7);
verify(7)->greaterOrEquals(5);
}
public function testTrueFalseNull()
{
verify(true)->true();
verify(false)->false();
verify(null)->null();
verify(true)->notNull();
verify('something should be false', false)->false();
verify('something should be true', true)->true();
}
public function testEmptyNotEmpty()
{
verify(array('3', '5'))->notEmpty();
verify(array())->isEmpty();
}
public function testVerifyThat()
{
verify_that(12);
verify_that('hello world');
verify_that(array('hello'));
}
public function testVerifyNot()
{
verify_not(false);
verify_not(null);
verify_not(array());
}
public function testExpectFunctions()
{
expect(12)->equals(12);
expect_that(true);
expect_not(false);
}
public function testArrayHasKey()
{
$errors = array('title' => 'You should add title');
expect($errors)->hasKey('title');
expect($errors)->hasntKey('body');
}
public function testIsInstanceOf()
{
$testClass = new DateTime();
expect($testClass)->isInstanceOf('DateTime');
expect($testClass)->isNotInstanceOf('DateTimeZone');
}
public function testInternalType()
{
$testVar = array();
expect($testVar)->internalType('array');
expect($testVar)->notInternalType('boolean');
}
public function testHasAttribute()
{
expect('Exception')->hasAttribute('message');
expect('Exception')->notHasAttribute('fakeproperty');
$testObject = (object) array('existingAttribute' => true);
expect($testObject)->hasAttribute('existingAttribute');
expect($testObject)->notHasAttribute('fakeproperty');
}
public function testHasStaticAttribute()
{
expect('FakeClassForTesting')->hasStaticAttribute('staticProperty');
expect('FakeClassForTesting')->notHasStaticAttribute('fakeProperty');
}
public function testContainsOnly()
{
expect(array('1', '2', '3'))->containsOnly('string');
expect(array('1', '2', 3))->notContainsOnly('string');
}
public function testContainsOnlyInstancesOf()
{
expect(array(new FakeClassForTesting(), new FakeClassForTesting(), new FakeClassForTesting()))
->containsOnlyInstancesOf('FakeClassForTesting');
}
public function testCount()
{
expect(array(1,2,3))->count(3);
expect(array(1,2,3))->notCount(2);
}
public function testEqualXMLStructure()
{
$expected = new DOMElement('foo');
$actual = new DOMElement('foo');
expect($expected)->equalXMLStructure($actual);
}
public function testFileExists()
{
expect_file(__FILE__)->exists();
expect_file('completelyrandomfilename.txt')->notExists();
}
public function testEqualsJsonFile()
{
expect_file(__DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'json-test-file.json')
->equalsJsonFile(__DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'equal-json-test-file.json');
expect('{"some" : "data"}')->equalsJsonFile(__DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'equal-json-test-file.json');
}
public function testEqualsJsonString()
{
expect('{"some" : "data"}')->equalsJsonString('{"some" : "data"}');
}
public function testRegExp()
{
expect('somestring')->regExp('/string/');
}
public function testMatchesFormat()
{
expect('somestring')->matchesFormat('%s');
expect('somestring')->notMatchesFormat('%i');
}
public function testMatchesFormatFile()
{
expect('23')->matchesFormatFile(__DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'format-file.txt');
expect('asdfas')->notMatchesFormatFile(__DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'format-file.txt');
}
public function testSame()
{
expect(1)->same(0+1);
expect(1)->notSame(true);
}
public function testEndsWith()
{
expect('A completely not funny string')->endsWith('ny string');
expect('A completely not funny string')->notEndsWith('A completely');
}
public function testEqualsFile()
{
expect('%i')->equalsFile(__DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'format-file.txt');
expect('Another string')->notEqualsFile(__DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'format-file.txt');
}
public function testStartsWith()
{
expect('A completely not funny string')->startsWith('A completely');
expect('A completely not funny string')->notStartsWith('string');
}
public function testEqualsXmlFile()
{
expect_file(__DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'xml-test-file.xml')
->equalsXmlFile(__DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'xml-test-file.xml');
expect('<foo><bar>Baz</bar><bar>Baz</bar></foo>')
->equalsXmlFile(__DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'xml-test-file.xml');
}
public function testEqualsXmlString()
{
expect('<foo><bar>Baz</bar><bar>Baz</bar></foo>')
->equalsXmlString('<foo><bar>Baz</bar><bar>Baz</bar></foo>');
}
}
class FakeClassForTesting
{
static $staticProperty;
}