forked from phalcon/cphalcon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanual-unit.php
187 lines (160 loc) · 4.95 KB
/
manual-unit.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
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
<?php
/*
+------------------------------------------------------------------------+
| Phalcon Framework |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2012 Phalcon Team (http://www.phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file docs/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@phalconphp.com so we can send you a copy immediately. |
+------------------------------------------------------------------------+
| Authors: Andres Gutierrez <andres@phalconphp.com> |
| Eduar Carvajal <eduar@phalconphp.com> |
+------------------------------------------------------------------------+
*/
error_reporting(E_ALL | E_NOTICE | E_STRICT);
if (function_exists('xhprof_enable')) {
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
}
class PHPUnit_Framework_TestCase
{
public function assertInstanceOf($className, $object)
{
if (get_class($object) != $className) {
throw new Exception('Not instance of '.$className.', actually: '.get_class($object));
}
}
public function assertEquals($a, $b)
{
if ($a != $b) {
if(is_array($a) && is_array($b)){
foreach($a as $k => $v){
if(isset($b[$k])){
if ($v != $b[$k]) {
print_r($v);
echo PHP_EOL;
print_r($b[$k]);
}
} else {
print_r($v);
echo PHP_EOL;
echo 'Not exists';
}
}
throw new Exception('Not equals');
} else {
throw new Exception('Not equals '.print_r($a, true).' != '.print_r($b, true));
}
}
}
public function assertNotEquals($a, $b)
{
if ($a == $b) {
throw new Exception('Equals '.$a.'=='.$b);
}
}
public function assertFalse($a)
{
if ($a) {
throw new Exception('Not false');
}
}
public function assertTrue($a)
{
if (!$a) {
throw new Exception('Not true');
}
}
public function assertGreaterThan($a, $b)
{
if ($b <= $a){
throw new Exception('Not greater than');
}
}
public function markTestSkipped($message)
{
echo 'Skipped: ' . $message . PHP_EOL;
}
public static function main($className)
{
echo 'Testing ', $className, ' ';
if (class_exists($className, false)) {
$class = new $className();
if (method_exists($class, 'setUp')) {
$class->setUp();
}
$reflectionClass = new ReflectionClass($class);
$hasSetup = $reflectionClass->hasMethod('setUp');
$m = microtime(true);
$mm = memory_get_usage(true);
$mf = memory_get_usage(false);
foreach ($reflectionClass->getMethods() as $method) {
$methodName = $method->getName();
if (substr($methodName, 0, 4) == 'test') {
if ($hasSetup) {
$class->setUp();
}
$class->$methodName();
}
}
echo '[OK]', ' (', memory_get_usage(true) - $mm, ') (', memory_get_usage(false) - $mf, ') (', sprintf("%.4f", (microtime(true) - $m) * 1000), ')', PHP_EOL;
} else {
echo '[FAILED]', PHP_EOL;
}
}
}
if (PHP_OS == 'Linux') {
if(isset($_SERVER['LOGNAME']) && $_SERVER['LOGNAME']=='gutierrezandresfelipe'){
chdir('/home/gutierrezandresfelipe/cphalcon');
}
}
if (!extension_loaded('phalcon')) {
throw new Exception("Sorry, but phalcon extension is not loaded");
}
try {
if (isset($_SERVER['argv'][1])) {
$file = $_SERVER['argv'][1];
require $_SERVER['argv'][1];
if (isset($_SERVER['argv'][2])) {
$className = $_SERVER['argv'][2];
} else {
if (preg_match('#/([a-zA-Z0-9]+)\.php$#', $_SERVER['argv'][1], $matches)) {
$className = $matches[1];
} else {
throw new Exception("class-name plz");
}
}
PHPUnit_Framework_TestCase::main($className);
} else {
$xml = simplexml_load_file('unit-tests/phpunit.xml');
foreach ($xml->testsuites as $suite) {
foreach ($suite->testsuite->file as $file) {
$fileName = (string) $file;
if (preg_match('#/([a-zA-Z0-9]+)\.php$#', $fileName, $matches)) {
require $fileName;
PHPUnit_Framework_TestCase::main($matches[1]);
} else {
throw new Exception("$file plz");
}
}
}
}
}
catch(Exception $e){
echo $e->getMessage(), PHP_EOL;
echo $e->getTraceAsString(), PHP_EOL;
//print_r($e->getTrace());
}
if (function_exists('xhprof_enable')) {
$xhprof_data = xhprof_disable('/tmp');
$XHPROF_ROOT = "/var/www/xhprof/";
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";
$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_testing");
echo "http://192.168.0.27/xhprof/xhprof_html/index.php?run={$run_id}&source=xhprof_testing\n";
}