Skip to content

Commit 5dd003f

Browse files
committed
Extract the expected result generating code into test case class
1 parent 58a4bfe commit 5dd003f

File tree

2 files changed

+35
-33
lines changed

2 files changed

+35
-33
lines changed

tests/PHPCtagsTest.php

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -45,36 +45,10 @@ public function testExport()
4545
$testcase_class = 't_' . $testcase_id;
4646
$testcase_object = new $testcase_class;
4747

48-
$testcase_expect = '';
49-
$testcase_format = $testcase_object->getFormat();
50-
$testcase_example = $testcase_object->getExample();
51-
$testcase_example_define = $testcase_object->getExampleDefine();
52-
$testcase_example_content = $testcase_object->getExampleContent();
53-
foreach ($testcase_example_define as $define) {
54-
$line = $testcase_format;
55-
56-
$line = preg_replace('/<name>/', $define['name'], $line);
57-
$line = preg_replace('/<file>/', $testcase_example, $line);
58-
$line = preg_replace('/<line content>/', rtrim($testcase_example_content[$define['line'] - 1], "\n"), $line);
59-
$line = preg_replace('/<kind>/', $define['kind'], $line);
60-
$line = preg_replace('/<line number>/', $define['line'], $line);
61-
if(!empty($define['scope'])) {
62-
$line = preg_replace('/<scope>/', $define['scope'], $line);
63-
} else {
64-
$line = preg_replace('/<scope>/', '', $line);
65-
}
66-
if(!empty($define['access'])) {
67-
$line = preg_replace('/<access>/', 'access:' . $define['access'], $line);
68-
} else {
69-
$line = preg_replace('/<access>/', '', $line);
70-
}
71-
$line = rtrim($line, "\t");
72-
$line .= "\n";
73-
74-
$testcase_expect .= $line;
75-
}
48+
$testcase_expect = $testcase_object->getExpectResult();
7649

7750
ob_start();
51+
$testcase_example = $testcase_object->getExample();
7852
$testcase_options = $testcase_object->getOptions();
7953
$this->object->export($testcase_example, $testcase_options);
8054
$testcase_result = ob_get_contents();

tests/PHPCtagsTestCase.php

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ public function __construct()
1818
);
1919
}
2020

21-
public function getFormat()
22-
{
23-
return $this->mFormat;
24-
}
25-
2621
public function getOptions()
2722
{
2823
return $this->mOptions;
@@ -48,4 +43,37 @@ public function getExampleContent()
4843
{
4944
return file($this->getExample());
5045
}
46+
47+
public function getExpectResult()
48+
{
49+
$testcase_expect = '';
50+
$testcase_example_define = $this->getExampleDefine();
51+
$testcase_example_content = $this->getExampleContent();
52+
foreach ($testcase_example_define as $define) {
53+
$line = $this->mFormat;
54+
55+
$line = preg_replace('/<name>/', $define['name'], $line);
56+
$line = preg_replace('/<file>/', $this->getExample(), $line);
57+
$line = preg_replace('/<line content>/', rtrim($testcase_example_content[$define['line'] - 1], "\n"), $line);
58+
$line = preg_replace('/<kind>/', $define['kind'], $line);
59+
$line = preg_replace('/<line number>/', $define['line'], $line);
60+
if(!empty($define['scope'])) {
61+
$line = preg_replace('/<scope>/', $define['scope'], $line);
62+
} else {
63+
$line = preg_replace('/<scope>/', '', $line);
64+
}
65+
if(!empty($define['access'])) {
66+
$line = preg_replace('/<access>/', 'access:' . $define['access'], $line);
67+
} else {
68+
$line = preg_replace('/<access>/', '', $line);
69+
}
70+
$line = rtrim($line, "\t");
71+
$line .= "\n";
72+
73+
$testcase_expect .= $line;
74+
}
75+
76+
return $testcase_expect;
77+
78+
}
5179
}

0 commit comments

Comments
 (0)