Skip to content

Commit

Permalink
Merge pull request #3231 from Codeception/fix-failed-chars
Browse files Browse the repository at this point in the history
Fixed creating snapshot files on failure. Closes #3207
  • Loading branch information
Naktibalda committed Jun 18, 2016
2 parents a7b90f3 + 120b1e4 commit 1f4d67b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Codeception/Lib/InnerBrowser.php
Expand Up @@ -58,7 +58,8 @@ public function _failed(TestInterface $test, $fail)
if (!$this->client || !$this->client->getInternalResponse()) {
return;
}
$this->_savePageSource(codecept_output_dir().str_replace(['::', '\\', '/'], ['.', '.', '.'], Descriptor::getTestSignature($test)) . '.fail.html');
$filename = preg_replace('~\W~', '.', Descriptor::getTestSignature($test)) . '.fail.html';
$this->_savePageSource(codecept_output_dir() . $filename);
}

public function _after(TestInterface $test)
Expand Down
2 changes: 1 addition & 1 deletion src/Codeception/Module/WebDriver.php
Expand Up @@ -365,7 +365,7 @@ public function _after(TestInterface $test)
public function _failed(TestInterface $test, $fail)
{
$this->debugWebDriverLogs();
$filename = str_replace([':', '\\', '/'], ['.', '', ''], Descriptor::getTestSignature($test)) . '.fail';
$filename = preg_replace('~\W~', '.', Descriptor::getTestSignature($test)) . '.fail';
$outputDir = codecept_output_dir();
$this->_saveScreenshot($outputDir . $filename . '.png');
$this->_savePageSource($outputDir . $filename . '.html');
Expand Down
2 changes: 1 addition & 1 deletion tests/data/app/db
@@ -1 +1 @@
a:0:{}
a:4:{s:6:"params";a:0:{}s:5:"query";a:0:{}s:4:"form";a:0:{}s:5:"files";a:1:{s:6:"avatar";a:5:{s:4:"name";s:10:"avatar.jpg";s:4:"type";s:0:"";s:8:"tmp_name";s:49:"/tmp/63775c69b7d7e48350acc1411b833fac0a3e5725.jpg";s:5:"error";s:1:"0";s:4:"size";s:4:"5621";}}}
14 changes: 14 additions & 0 deletions tests/unit/Codeception/Module/FrameworksTest.php
@@ -1,4 +1,6 @@
<?php
use Codeception\Util\Stub;

require_once __DIR__ . '/TestsForWeb.php';

/**
Expand Down Expand Up @@ -78,4 +80,16 @@ public function testMoveBackThrowsExceptionIfNumberOfStepsIsInvalid()
}
}
}

public function testCreateSnapshotOnFail()
{
$module = Stub::construct(get_class($this->module), [make_container()],[
'_savePageSource' => Stub::once(function ($filename) {
$this->assertEquals(codecept_log_dir('Codeception.Module.UniversalFramework.looks.like..test.fail.html'), $filename);
}),
]);
$module->amOnPage('/');
$cest = new \Codeception\Test\Cest($this->module, 'looks:like::test', 'demo1Cest.php');
$module->_failed($cest, new PHPUnit_Framework_AssertionFailedError());
}
}

0 comments on commit 1f4d67b

Please sign in to comment.