1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00

simplify test class

This commit is contained in:
Emanuil Rusev 2014-04-17 10:46:07 +03:00
parent 159c3cede6
commit 4e670129c8

View File

@ -4,54 +4,64 @@ include 'Parsedown.php';
class Test extends PHPUnit_Framework_TestCase class Test extends PHPUnit_Framework_TestCase
{ {
const provider_dir = 'data/'; public function __construct($name = null, array $data = array(), $dataName = '')
{
$this->dataDir = dirname(__FILE__).'/data/';
/** parent::__construct($name, $data, $dataName);
* @dataProvider provider }
private $dataDir;
/**
* @dataProvider data
*/ */
function test_($filename) function test_($filename)
{ {
$path = $this->get_data_path(); $markdown = file_get_contents($this->dataDir . $filename . '.md');
$markdown = file_get_contents($path . $filename . '.md');
$expected_markup = file_get_contents($path . $filename . '.html');
$expected_markup = str_replace("\r\n", "\n", $expected_markup);
$expected_markup = str_replace("\r", "\n", $expected_markup);
$actual_markup = Parsedown::instance()->parse($markdown); $expectedMarkup = file_get_contents($this->dataDir . $filename . '.html');
$this->assertEquals($expected_markup, $actual_markup); $expectedMarkup = str_replace("\r\n", "\n", $expectedMarkup);
$expectedMarkup = str_replace("\r", "\n", $expectedMarkup);
$actualMarkup = Parsedown::instance()->text($markdown);
$this->assertEquals($expectedMarkup, $actualMarkup);
} }
function provider() function data()
{ {
$provider = array(); $data = array();
$path = $this->get_data_path(); $Folder = new DirectoryIterator($this->dataDir);
$DirectoryIterator = new DirectoryIterator($path);
foreach ($DirectoryIterator as $Item) foreach ($Folder as $File)
{ {
if ($Item->isFile()) /** @var $File DirectoryIterator */
{
$filename = $Item->getFilename();
$extension = pathinfo($filename, PATHINFO_EXTENSION); if ( ! $File->isFile())
{
continue;
}
if ($extension !== 'md') $filename = $File->getFilename();
continue;
$basename = $Item->getBasename('.md'); $extension = pathinfo($filename, PATHINFO_EXTENSION);
if (file_exists($path.$basename.'.html')) {
$provider [] = array($basename); if ($extension !== 'md')
} {
} continue;
}
$basename = $File->getBasename('.md');
if (file_exists($this->dataDir . $basename . '.html'))
{
$data []= array($basename);
}
} }
return $provider; return $data;
} }
}
function get_data_path()
{
return dirname(__FILE__).'/'.self::provider_dir;
}
}