forked from the-crucible/phpunit-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14Contains.php
86 lines (70 loc) · 2.07 KB
/
14Contains.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
<?php
/**
* assertContains(
* mixed $needle,
* Iterator|array $haystack[,
* string $message = '']
* )
*
* Reports an error identified by $message if
* $needle is not an element of $haystack.
*
* assertNotContains() is the inverse of this
* assertion and takes the same arguments.
*
* assertAttributeContains() and assertAttributeNotContains()
* are convenience wrappers that use a public, protected, or
* private attribute of a class or object as the haystack.
*
*/
class ContainsTest extends PHPUnit_Framework_TestCase
{
/**
* This test will use assertContains() function on
* a array and see how it works
*/
public function testArraySearch()
{
$arr = array(1, 2, 3);
#$arr[] = 4;
#Uncommenting line above will pass the test
$this->assertContains(4, $arr);
}
/**
* This test will use assertContains() function on a
* string and see how it works
*/
public function testStringSearch()
{
$str = 'bar';
#$str = 'foobar';
#Uncommenting line above will pass the test
$this->assertContains('foo',$str);
}
/**
* This function will test assertAttributeContains for
* objects and public, private and protected variables
*/
public function testContainAttribute(){
$obj = new ContainClass();
$needle = 4;
#$needle = 3;
#Uncommenting line above will pass the test
$this->assertAttributeContains($needle, 'arr2' , $obj);
}
/**
* This function will test assertAttributeContains for
* objects and public, private and protected variables
*/
public function testContainStaticVar(){
$needle = 4;
#$needle = 3;
#Uncommenting line above will pass the test
$this->assertAttributeContains($needle, 'arr1' , 'ContainClass' );
}
}
class ContainClass{
public static $arr1 = array(1, 2, 3);
public $arr2 = array(1, 2, 3);
}
?>