Skip to content

Commit af65e9b

Browse files
committed
Introduce a new easy extendable test framwork
1 parent 12e7501 commit af65e9b

File tree

4 files changed

+301
-6
lines changed

4 files changed

+301
-6
lines changed

tests/PHPCtagsTest.php

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
require_once __DIR__ . '/PHPCtagsTestCase.php';
3+
24
/**
35
* Generated by PHPUnit_SkeletonGenerator on 2012-07-10 at 02:00:19.
46
*/
@@ -31,13 +33,56 @@ protected function tearDown()
3133
*/
3234
public function testExport()
3335
{
34-
$options = array(
35-
'excmd' => 'pattern',
36-
'fields' => array('n','k','s','S','a'),
37-
'format' => 2,
38-
);
36+
$testcases = scandir(__DIR__ . '/testcases');
37+
foreach($testcases as $testcase)
38+
{
39+
if($testcase === '.' || $testcase === '..') {
40+
continue;
41+
}
42+
43+
require_once __DIR__ . '/testcases/' . $testcase;
44+
$testcase_id = strstr($testcase, '.', true);
45+
$testcase_class = 't_' . $testcase_id;
46+
$testcase_object = new $testcase_class;
47+
48+
$testcase_expect = '';
49+
$testcase_format = $testcase_object->getFormat();
50+
$testcase_example = $testcase_object->getExample();
51+
$testcase_example = realpath(__DIR__ . '/examples/' . $testcase_example . '.example.php');
52+
$testcase_example_define = $testcase_object->getExampleDefine();
53+
$testcase_example_content = $testcase_object->getExampleContent();
54+
foreach ($testcase_example_define as $define) {
55+
$line = $testcase_format;
56+
57+
$line = preg_replace('/<name>/', $define['name'], $line);
58+
$line = preg_replace('/<file>/', $testcase_example, $line);
59+
$line = preg_replace('/<line content>/', rtrim($testcase_example_content[$define['line'] - 1], "\n"), $line);
60+
$line = preg_replace('/<kind>/', $define['kind'], $line);
61+
$line = preg_replace('/<line number>/', $define['line'], $line);
62+
if(!empty($define['scope'])) {
63+
$line = preg_replace('/<scope>/', $define['scope'], $line);
64+
} else {
65+
$line = preg_replace('/<scope>/', '', $line);
66+
}
67+
if(!empty($define['access'])) {
68+
$line = preg_replace('/<access>/', 'access:' . $define['access'], $line);
69+
} else {
70+
$line = preg_replace('/<access>/', '', $line);
71+
}
72+
$line = rtrim($line, "\t");
73+
$line .= "\n";
74+
75+
$testcase_expect .= $line;
76+
}
77+
78+
ob_start();
79+
$testcase_options = $testcase_object->getOptions();
80+
$this->object->export($testcase_example, $testcase_options);
81+
$testcase_result = ob_get_contents();
82+
ob_end_clean();
3983

40-
$this->object->export(__DIR__ . '/PHPCtagsTest.example.php', $options);
84+
$this->assertEquals(md5($testcase_result), md5($testcase_expect))
85+
}
4186
}
4287

4388
}

tests/PHPCtagsTestCase.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
abstract class PHPCtagsTestCase {
4+
5+
protected $mFormat;
6+
7+
protected $mOptions;
8+
9+
protected $mExample;
10+
11+
protected $mExampleDefine;
12+
13+
public function getFormat()
14+
{
15+
return $this->mFormat;
16+
}
17+
18+
public function getOptions()
19+
{
20+
return $this->mOptions;
21+
}
22+
23+
public function getExample()
24+
{
25+
return $this->mExample;
26+
}
27+
28+
public function getExampleDefine()
29+
{
30+
return $this->mExampleDefine;
31+
}
32+
33+
public function getExampleContent()
34+
{
35+
return file($this->getExample());
36+
}
37+
}
File renamed without changes.

tests/testcases/0001.testcase.php

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
<?php
2+
class t_0001 extends PHPCtagsTestCase {
3+
4+
public function __construct()
5+
{
6+
$this->mFormat = "<name>\t<file>\t/^<line content>$/;\"\t<kind>\tline:<line number>\t<scope>\t<access>";
7+
$this->mOptions = array(
8+
'excmd' => 'pattern',
9+
'fields' => array('n','k','s','a'),
10+
'format' => 2,
11+
);
12+
$this->mExample = '0001';
13+
$this->mExampleDefine = array(
14+
array(
15+
'name'=>'GLOBAL_CONST_1',
16+
'kind'=>'d',
17+
'line'=>'3',
18+
'scope'=>'',
19+
'access'=>'',
20+
),
21+
array(
22+
'name'=>'GLOBAL_CONST_2',
23+
'kind'=>'d',
24+
'line'=>'6',
25+
'scope'=>'',
26+
'access'=>'',
27+
),
28+
array(
29+
'name'=>'$var1',
30+
'kind'=>'v',
31+
'line'=>'8',
32+
'scope'=>'',
33+
'access'=>'',
34+
),
35+
array(
36+
'name'=>'$var2',
37+
'kind'=>'v',
38+
'line'=>'10',
39+
'scope'=>'',
40+
'access'=>'',
41+
),
42+
array(
43+
'name'=>'function_1',
44+
'kind'=>'f',
45+
'line'=>'13',
46+
'scope'=>'',
47+
'access'=>'',
48+
),
49+
array(
50+
'name'=>'$var',
51+
'kind'=>'v',
52+
'line'=>'15',
53+
'scope'=>'function:function_1',
54+
'access'=>'',
55+
),
56+
array(
57+
'name'=>'function_2',
58+
'kind'=>'f',
59+
'line'=>'20',
60+
'scope'=>'',
61+
'access'=>'',
62+
),
63+
array(
64+
'name'=>'Interface_1',
65+
'kind'=>'i',
66+
'line'=>'30',
67+
'scope'=>'',
68+
'access'=>'',
69+
),
70+
array(
71+
'name'=>'CLASS_CONST',
72+
'kind'=>'d',
73+
'line'=>'32',
74+
'scope'=>'interface:Interface_1',
75+
'access'=>'',
76+
),
77+
array(
78+
'name'=>'method_0',
79+
'kind'=>'m',
80+
'line'=>'34',
81+
'scope'=>'interface:Interface_1',
82+
'access'=>'public',
83+
),
84+
array(
85+
'name'=>'method_1',
86+
'kind'=>'m',
87+
'line'=>'36',
88+
'scope'=>'interface:Interface_1',
89+
'access'=>'public',
90+
),
91+
array(
92+
'name'=>'method_2',
93+
'kind'=>'m',
94+
'line'=>'38',
95+
'scope'=>'interface:Interface_1',
96+
'access'=>'public',
97+
),
98+
array(
99+
'name'=>'method_3',
100+
'kind'=>'m',
101+
'line'=>'40',
102+
'scope'=>'interface:Interface_1',
103+
'access'=>'public',
104+
),
105+
array(
106+
'name'=>'Class_1',
107+
'kind'=>'c',
108+
'line'=>'43',
109+
'scope'=>'',
110+
'access'=>'',
111+
),
112+
array(
113+
'name'=>'CLASS_CONST',
114+
'kind'=>'d',
115+
'line'=>'45',
116+
'scope'=>'class:Class_1',
117+
'access'=>'',
118+
),
119+
array(
120+
'name'=>'var1',
121+
'kind'=>'p',
122+
'line'=>'47',
123+
'scope'=>'class:Class_1',
124+
'access'=>'public',
125+
),
126+
array(
127+
'name'=>'var2',
128+
'kind'=>'p',
129+
'line'=>'49',
130+
'scope'=>'class:Class_1',
131+
'access'=>'private',
132+
),
133+
array(
134+
'name'=>'var3',
135+
'kind'=>'p',
136+
'line'=>'51',
137+
'scope'=>'class:Class_1',
138+
'access'=>'protected',
139+
),
140+
array(
141+
'name'=>'__construct',
142+
'kind'=>'m',
143+
'line'=>'53',
144+
'scope'=>'class:Class_1',
145+
'access'=>'public',
146+
),
147+
array(
148+
'name'=>'$var1',
149+
'kind'=>'v',
150+
'line'=>'55',
151+
'scope'=>'method:Class_1::__construct',
152+
'access'=>'',
153+
),
154+
array(
155+
'name'=>'$var2',
156+
'kind'=>'v',
157+
'line'=>'56',
158+
'scope'=>'method:Class_1::__construct',
159+
'access'=>'',
160+
),
161+
array(
162+
'name'=>'$var3',
163+
'kind'=>'v',
164+
'line'=>'57',
165+
'scope'=>'method:Class_1::__construct',
166+
'access'=>'',
167+
),
168+
array(
169+
'name'=>'method_0',
170+
'kind'=>'m',
171+
'line'=>'60',
172+
'scope'=>'class:Class_1',
173+
'access'=>'public',
174+
),
175+
array(
176+
'name'=>'$var',
177+
'kind'=>'v',
178+
'line'=>'62',
179+
'scope'=>'method:Class_1::method_0',
180+
'access'=>'',
181+
),
182+
array(
183+
'name'=>'method_1',
184+
'kind'=>'m',
185+
'line'=>'66',
186+
'scope'=>'class:Class_1',
187+
'access'=>'public',
188+
),
189+
array(
190+
'name'=>'method_2',
191+
'kind'=>'m',
192+
'line'=>'71',
193+
'scope'=>'class:Class_1',
194+
'access'=>'private',
195+
),
196+
array(
197+
'name'=>'method_3',
198+
'kind'=>'m',
199+
'line'=>'76',
200+
'scope'=>'class:Class_1',
201+
'access'=>'protected',
202+
),
203+
array(
204+
'name'=>'Class_2',
205+
'kind'=>'c',
206+
'line'=>'82',
207+
'scope'=>'',
208+
'access'=>'',
209+
),
210+
);
211+
}
212+
213+
}

0 commit comments

Comments
 (0)