Skip to content

Commit

Permalink
improved tests to tests basic markdown also against subflavor class
Browse files Browse the repository at this point in the history
  • Loading branch information
cebe committed Feb 17, 2014
1 parent 6b35979 commit 1229ed3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
40 changes: 19 additions & 21 deletions tests/BaseMarkdownTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,50 @@
*/
abstract class BaseMarkdownTest extends \PHPUnit_Framework_TestCase
{
abstract public function getDataPath();
abstract public function getDataPaths();

abstract public function createMarkdown();

/**
* @dataProvider dataFiles
*/
public function testParse($file)
public function testParse($path, $file)
{
list($markdown, $html) = $this->getTestData($file);
list($markdown, $html) = $this->getTestData($path, $file);
// Different OS line endings should not affect test
$html = preg_replace('~\r\n?~', "\n", $html);

$m = $this->createMarkdown();
$this->assertEquals($html, $m->parse($markdown));
}

public function getTestData($file)
public function getTestData($path, $file)
{
return [
file_get_contents(__DIR__ . '/' . $this->getDataPath() . '/' . $file . '.md'),
file_get_contents(__DIR__ . '/' . $this->getDataPath() . '/' . $file . '.html'),
file_get_contents($this->getDataPaths()[$path] . '/' . $file . '.md'),
file_get_contents($this->getDataPaths()[$path] . '/' . $file . '.html'),
];
}

public function dataFiles()
{
$src = __DIR__ . '/' . $this->getDataPath();

$files = [];

$handle = opendir($src);
if ($handle === false) {
throw new \Exception('Unable to open directory: ' . $src);
}
while (($file = readdir($handle)) !== false) {
if ($file === '.' || $file === '..') {
continue;
foreach($this->getDataPaths() as $name => $src) {
$handle = opendir($src);
if ($handle === false) {
throw new \Exception('Unable to open directory: ' . $src);
}

if (substr($file, -3, 3) === '.md' && file_exists($src . '/' . substr($file, 0, -3) . '.html')) {
$files[] = [substr($file, 0, -3)];
while (($file = readdir($handle)) !== false) {
if ($file === '.' || $file === '..') {
continue;
}

if (substr($file, -3, 3) === '.md' && file_exists($src . '/' . substr($file, 0, -3) . '.html')) {
$files[] = [$name, substr($file, 0, -3)];
}
}
closedir($handle);
}
closedir($handle);

return $files;
}
}
7 changes: 5 additions & 2 deletions tests/GithubMarkdownTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ public function createMarkdown()
return new GithubMarkdown();
}

public function getDataPath()
public function getDataPaths()
{
return 'github-data';
return [
'markdown-data' => __DIR__ . '/markdown-data',
'github-data' => __DIR__ . '/github-data',
];
}
}
6 changes: 4 additions & 2 deletions tests/MarkdownTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ public function createMarkdown()
return new Markdown();
}

public function getDataPath()
public function getDataPaths()
{
return 'markdown-data';
return [
'markdown-data' => __DIR__ . '/markdown-data',
];
}
}

0 comments on commit 1229ed3

Please sign in to comment.