Skip to content

Commit cf6ba18

Browse files
committed
Use parameterized testing pattern to generate the test
1 parent 5dd003f commit cf6ba18

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

tests/PHPCtagsTest.php

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,33 +29,43 @@ protected function tearDown()
2929
}
3030

3131
/**
32-
* @covers PHPCtags::export
33-
*/
34-
public function testExport()
32+
* Data provider
33+
**/
34+
public function provider()
3535
{
36+
$testcases_files = array();
3637
$testcases = scandir(__DIR__ . '/testcases');
3738
foreach($testcases as $testcase)
3839
{
3940
if($testcase === '.' || $testcase === '..') {
4041
continue;
4142
}
43+
$testcases_files[] = array($testcase);
44+
}
45+
return $testcases_files;
46+
}
4247

43-
require_once __DIR__ . '/testcases/' . $testcase;
44-
$testcase_id = strstr($testcase, '.', true);
45-
$testcase_class = 't_' . $testcase_id;
46-
$testcase_object = new $testcase_class;
48+
/**
49+
* @covers PHPCtags::export
50+
* @dataProvider provider
51+
*/
52+
public function testExport($testcase)
53+
{
54+
require_once __DIR__ . '/testcases/' . $testcase;
55+
$testcase_id = strstr($testcase, '.', true);
56+
$testcase_class = 't_' . $testcase_id;
57+
$testcase_object = new $testcase_class;
4758

48-
$testcase_expect = $testcase_object->getExpectResult();
59+
$testcase_expect = $testcase_object->getExpectResult();
4960

50-
ob_start();
51-
$testcase_example = $testcase_object->getExample();
52-
$testcase_options = $testcase_object->getOptions();
53-
$this->object->export($testcase_example, $testcase_options);
54-
$testcase_result = ob_get_contents();
55-
ob_end_clean();
61+
ob_start();
62+
$testcase_example = $testcase_object->getExample();
63+
$testcase_options = $testcase_object->getOptions();
64+
$this->object->export($testcase_example, $testcase_options);
65+
$testcase_result = ob_get_contents();
66+
ob_end_clean();
5667

57-
$this->assertEquals(md5($testcase_result), md5($testcase_expect))
58-
}
68+
$this->assertEquals(md5($testcase_result), md5($testcase_expect))
5969
}
6070

6171
}

0 commit comments

Comments
 (0)