Skip to content

Commit

Permalink
Misc improvements for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
javiereguiluz committed May 24, 2015
1 parent 9249cc7 commit e4097ea
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 40 deletions.
55 changes: 29 additions & 26 deletions src/Easybook/Tests/DependencyInjection/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,27 +69,31 @@ public function testSlugifyUniquely()
}
}

public function testHighlight()
/**
* @dataProvider provideHighlightFixtures
*/
public function testHighlight($originalFilePath, $highlightedFilePath)
{
// mock the $app object to disable the highlight cache
$app = $this->getMock('Easybook\DependencyInjection\Application', array('edition'));
$app->expects($this->any())
->method('edition')
->will($this->returnValue(null));

$fixturesDir = __DIR__.'/fixtures/highlight';
$languageToHighlight = substr(basename($originalFilePath), 0, -4);

$this->assertEquals(
file_get_contents($fixturesDir.'/highlighted_html_snippet.txt'),
$app->highlight(file_get_contents($fixturesDir.'/raw_html_snippet.txt'), 'html'),
'HTML code snippet is highlighted correctly.'
file_get_contents($highlightedFilePath),
$app->highlight(file_get_contents($originalFilePath), $languageToHighlight),
'Code snippet is highlighted correctly.'
);
}

$this->assertEquals(
file_get_contents($fixturesDir.'/highlighted_php_snippet.txt'),
$app->highlight(file_get_contents($fixturesDir.'/raw_php_snippet.txt'), 'php'),
'PHP code snippet is highlighted correctly.'
);
public function provideHighlightFixtures()
{
$fixturesDir = __DIR__.'/fixtures/highlight';

return array_map(null, glob($fixturesDir.'/input/*.txt'), glob($fixturesDir.'/output/*.txt'));
}

public function testBookMethodShortcut()
Expand Down Expand Up @@ -134,17 +138,16 @@ public function testEditionMethodShortcut()
$this->assertEquals('epub', $app->edition('format'));
}

/**
* @expectedException PHPUnit_Framework_Error_Deprecated
* @expectedExceptionMessage The "publishing.id" option is deprecated
*/
public function testDeprecatedPublishingIdProperty()
{
$app = new Application();
$app['publishing.edition.id'] = 'custom_edition_id';

try {
$id = $app['publishing.id'];
} catch (\Exception $e) {
$this->assertInstanceOf('PHPUnit_Framework_Error_Deprecated', $e);
$this->assertContains('The "publishing.id" option is deprecated', $e->getMessage());
}
$id = $app['publishing.id'];
}

/**
Expand Down Expand Up @@ -185,6 +188,10 @@ public function getPublishers()
);
}

/**
* @expectedException RuntimeException
* @expectedExceptionMessage Unknown "this_format_does_not_exist" format
*/
public function testUnsupportedPublisher()
{
$app = new Application();
Expand All @@ -200,13 +207,13 @@ public function testUnsupportedPublisher()
),
);

try {
$publisher = $app['publisher'];
} catch (\RuntimeException $e) {
$this->assertContains('Unknown "this_format_does_not_exist" format', $e->getMessage());
}
$publisher = $app['publisher'];
}

/**
* @expectedException RuntimeException
* @expectedExceptionMessage (easybook only supports Markdown)
*/
public function testUnsupportedContentFormat()
{
$app = new Application();
Expand All @@ -217,11 +224,7 @@ public function testUnsupportedContentFormat()
),
);

try {
$parser = $app['parser'];
} catch (\RuntimeException $e) {
$this->assertContains('(easybook only supports Markdown)', $e->getMessage());
}
$parser = $app['parser'];
}

public function testGetTitleMethodForDefaultTitles()
Expand Down
24 changes: 11 additions & 13 deletions src/Easybook/Tests/DependencyInjection/RenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,25 @@ public function setUp()

public function tearDown()
{
//$this->filesystem->remove($this->templateDir);
$this->filesystem->remove($this->templateDir);
}

/**
* @expectedException RuntimeException
* @expectedExceptionMessage (easybook only supports Twig)
*/
public function testNonTwigTemplate()
{
try {
$this->app->render('template.tpl');
} catch (\RuntimeException $e) {
$this->assertInstanceOf('RuntimeException', $e);
$this->assertContains('(easybook only supports Twig)', $e->getMessage());
}
$this->app->render('template.tpl');
}

/**
* @expectedException Twig_Error_Loader
* @expectedExceptionRegExp /Unable to find template (.*)/
*/
public function testUndefinedTwigTemplate()
{
try {
$this->app->render('template.twig');
} catch (\Twig_Error_Loader $e) {
$this->assertInstanceOf('Twig_Error_Loader', $e);
$this->assertContains('Unable to find template', $e->getMessage());
}
$this->app->render('template.twig');
}

public function testSimpleTemplate()
Expand Down
2 changes: 1 addition & 1 deletion src/Easybook/Tests/Publishers/PublisherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function setUp()

public function tearDown()
{
//$this->filesystem->remove($this->tmpDir);
$this->filesystem->remove($this->tmpDir);

parent::tearDown();
}
Expand Down

0 comments on commit e4097ea

Please sign in to comment.