/
Assertion.php
156 lines (145 loc) · 4.69 KB
/
Assertion.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
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
<?php
/**
* phpRack: Integration Testing Framework
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt. It is also available
* through the world-wide-web at this URL: http://www.phprack.com/LICENSE.txt
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@phprack.com so we can send you a copy immediately.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @copyright Copyright (c) 2009-2012 phpRack.com
* @version $Id$
* @category phpRack
* @package Tests
* @subpackage core
*/
/**
* @see phpRack_Package
*/
require_once PHPRACK_PATH . '/Package.php';
/**
* @see phpRack_Result
*/
require_once PHPRACK_PATH . '/Result.php';
/**
* @see phpRack_Test
*/
require_once PHPRACK_PATH . '/Test.php';
/**
* One single test assertion
*
* @see phpRack_Test::__get()
* @property-read phpRack_Package_Cpu $cpu CPU related assertions
* @property-read phpRack_Package_Db $db DB related assertions
* @property-read phpRack_Package_Disc $disc Local HDD related assertions
* @property-read phpRack_Package_Network $network Network-related assertions
* @property-read phpRack_Package_Php $php PHP related assertions
* @property-read phpRack_Package_Qos $qos QOS related assertions
* @property-read phpRack_Package_Shell $shell Assertions related to SHELL
* @property-read phpRack_Package_Simple $simple Simple package, for simple assertions
* @package Tests
* @subpackage core
*/
class phpRack_Assertion
{
/**
* Result collector
*
* @var phpRack_Result
* @see __construct()
*/
protected $_result;
/**
* Construct the class
*
* @param phpRack_Test Test, which pushes results here
* @return void
* @see phpRack_Test::__get()
*/
private function __construct(phpRack_Test $test)
{
$this->_result = new phpRack_Result($test);
}
/**
* Create new assertion
*
* There is a combination of static factory() method and a private
* constructor. However we don't have any static factory here, just an
* incapsulation of constructor. Some time ago we had a static factory,
* but then removed it. Maybe in the future we might get back to this
* design approach.
*
* @param phpRack_Test Test that is using this assertion
* @return phpRack_Assertion
* @see phpRack_Test::__get()
*/
public static function factory(phpRack_Test $test)
{
return new self($test);
}
/**
* Dispatcher of calls to packages
*
* @param string Name of the package to get
* @return phpRack_Package
* @see phpRack_Test::_log() and many other methods inside Integration Tests
*/
public function __get($name)
{
return phpRack_Package::factory($name, $this->_result);
}
/**
* Call method, any one
*
* This magic method will be called when you're using any assertion and
* some method inside it, for example:
*
* <code>
* // inside your instance of phpRack_Test:
* $this->assert->php->extensions->isLoaded('simplexml');
* </code>
*
* The call in the example will lead you to this method, and will call
* __call('simplexml', array()).
*
* @param string Name of the method to call
* @param array Arguments to pass
* @return mixed
* @see PhpConfigurationTest::testPhpExtensionsExist isLoaded() reaches this point
*/
public function __call($name, array $args)
{
return call_user_func_array(
array(
phpRack_Package::factory('simple', $this->_result),
$name
),
$args
);
}
/**
* Get instance of result collector
*
* @return phpRack_Result
* @see phpRack_Test::_log() and many other methods inside Integration Tests
*/
public function getResult()
{
return $this->_result;
}
}