-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AssertionFailedWrappedError with test (#14)
* Update and rename ExpectationFailedWrappedError.php to AssertionFailedWrappedError.php * Update README.md * Remove unneeded use statements in BehatProvidingTraitTest * Create TestWrappingException.php * Create AssertionFailedWrapperErrrorTest * Remove stray brace in readme * Provide code to parent in AssertionFailedError
- Loading branch information
1 parent
479d7b4
commit 8cc5345
Showing
5 changed files
with
96 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
namespace PHPUnitBehat\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use PHPUnitBehat\PHPUnit\Framework\AssertionFailedWrappedError; | ||
|
||
/** | ||
* | ||
*/ | ||
class AssertionFailedWrappedErrorTest extends TestCase { | ||
|
||
use TestDefinitionsTrait; | ||
|
||
// This code using AssertionFailedWrappedError is taken from the project's readme. | ||
|
||
use TestHelpersTrait { | ||
assertBehatScenarioPassed as assertBehatScenarioPassedTrait; | ||
} | ||
|
||
public static function assertBehatScenarioPassed($scenarioResults, $scenario = NULL, $stepResults = [], $snippetGenerator = NULL, $environment = NULL, $message = '', $callHandler = '') | ||
{ | ||
try { | ||
self::assertBehatScenarioPassedTrait($scenarioResults, $scenario, $stepResults, $snippetGenerator, $environment, $message, $callHandler); | ||
} | ||
catch (TestWrappingException $e) { | ||
throw new \PHPUnitBehat\PHPUnit\Framework\AssertionFailedWrappedError($e); | ||
} | ||
} | ||
|
||
protected $testBehatFeature = <<<'FEATURE' | ||
Feature: BehatScenarioTestingTrait | ||
In order to test a feature | ||
We need to able to test scenarios | ||
Scenario: #0 Normal error | ||
Given an error | ||
Scenario: #1 Error to wrap | ||
Given an error to wrap | ||
|
||
FEATURE; | ||
|
||
|
||
/** | ||
* Test scenario "#0 Error" | ||
*/ | ||
public function testError() { | ||
$scenario = $this->getTestBehatScenario(0); | ||
$result = $this->executeTestBehatScenario($scenario); | ||
$this->assertTestFailed($result); | ||
$exceptionMessages = [ | ||
"Scenario '#0 Error' had steps:", | ||
"Failed: Given an error", | ||
"A test error message", | ||
]; | ||
$this->assertBehatScenarioAssertion($scenario, TestException::class, $exceptionMessages); | ||
} | ||
|
||
/** | ||
* Test scenario "#1 Error" | ||
*/ | ||
public function testErrorToWrap() { | ||
$scenario = $this->getTestBehatScenario(1); | ||
$result = $this->executeTestBehatScenario($scenario); | ||
$this->assertTestFailed($result); | ||
$exceptionMessages = [ | ||
"Scenario '#1 Error to wrap' had steps:", | ||
"Failed: Given an error to wrap", | ||
"A wrapped test error message", | ||
]; | ||
$this->assertBehatScenarioAssertion($scenario, AssertionFailedWrappedError::class, $exceptionMessages); | ||
} | ||
|
||
/** | ||
* @Given an error to wrap | ||
*/ | ||
public function anErrorToWrapStep() { | ||
throw new TestWrappingException("A wrapped test error message"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace PHPUnitBehat\Tests; | ||
|
||
use Exception; | ||
|
||
class TestWrappingException extends Exception {} |