forked from nette/tester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Assert.contains.phpt
45 lines (32 loc) · 1.11 KB
/
Assert.contains.phpt
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
<?php
use Tester\Assert;
require __DIR__ . '/bootstrap.php';
$contains = array(
array('1', '1', "'1' should not contain '1'"),
array('1', 'a1', "'a1' should not contain '1'"),
array('1', array('1'), "array(1) should not contain '1'"),
);
$notContains = array(
array('2', 'a1', "'a1' should contain '2'"),
array('1', array(TRUE), "array(1) should contain '1'"),
);
foreach ($contains as $case) {
list($expected, $actual, $message) = $case;
Assert::contains($expected, $actual);
Assert::exception(function() use ($expected, $actual) {
Assert::notContains($expected, $actual);
}, 'Tester\AssertException', $message);
}
foreach ($notContains as $case) {
list($expected, $actual, $message) = $case;
Assert::notContains($case[0], $case[1]);
Assert::exception(function() use ($expected, $actual) {
Assert::contains($expected, $actual);
}, 'Tester\AssertException', $message);
}
Assert::exception(function(){
Assert::contains(1, 1);
}, 'Tester\AssertException', '1 should be string or array');
Assert::exception(function(){
Assert::notContains(1, 1);
}, 'Tester\AssertException', '1 should be string or array');