Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6469 from Codeception/error-handling-expectations
Fix compatibility with PHPUnit error expectations
- Loading branch information
Showing
7 changed files
with
140 additions
and
5 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,49 @@ | ||
<?php | ||
|
||
class ErrorExpectationsCest | ||
{ | ||
|
||
public function _before(\CliGuy $I) | ||
{ | ||
$I->amInPath('tests/data/error_handling'); | ||
} | ||
|
||
public function expectNoticeWorks(\CliGuy $I) | ||
{ | ||
$this->skipIfOldPhpUnit($I); | ||
|
||
$I->executeCommand('run tests/unit/ErrorExceptionTest.php:testNotice'); | ||
$I->seeInShellOutput("OK ("); | ||
} | ||
|
||
public function expectWarningWorks(\CliGuy $I) | ||
{ | ||
$this->skipIfOldPhpUnit($I); | ||
|
||
$I->executeCommand('run tests/unit/ErrorExceptionTest.php:testWarning'); | ||
$I->seeInShellOutput('OK ('); | ||
} | ||
|
||
public function expectErrorWorks(\CliGuy $I) | ||
{ | ||
$this->skipIfOldPhpUnit($I); | ||
|
||
$I->executeCommand('run tests/unit/ErrorExceptionTest.php:testError'); | ||
$I->seeInShellOutput('OK ('); | ||
} | ||
|
||
public function expectDeprecationWorks(\CliGuy $I) | ||
{ | ||
$this->skipIfOldPhpUnit($I); | ||
|
||
$I->executeCommand('run tests/unit/ErrorExceptionTest.php:testDeprecation'); | ||
$I->seeInShellOutput('OK ('); | ||
} | ||
|
||
private function skipIfOldPhpUnit(CliGuy $I) | ||
{ | ||
if (version_compare(\PHPUnit\Runner\Version::id(), '8.4.0', '<')) { | ||
$I->markTestSkipped('expectXXX is only available on PHPUnit 8.4+'); | ||
} | ||
} | ||
} |
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,15 @@ | ||
actor: Tester | ||
paths: | ||
tests: tests | ||
log: tests/_output | ||
data: tests/_data | ||
support: tests/_support | ||
envs: tests/_envs | ||
suites: | ||
unit: | ||
path: . | ||
modules: | ||
enabled: | ||
- Asserts | ||
settings: | ||
convert_deprecations_to_exceptions: true |
Empty file.
34 changes: 34 additions & 0 deletions
34
tests/data/error_handling/tests/unit/ErrorExceptionTest.php
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,34 @@ | ||
<?php | ||
|
||
class ErrorExceptionTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
|
||
public function testNotice() | ||
{ | ||
$this->expectNotice(); | ||
$this->expectNoticeMessage('foobar'); | ||
trigger_error('foobar', E_USER_NOTICE); | ||
} | ||
|
||
public function testWarning() | ||
{ | ||
$this->expectWarning(); | ||
$this->expectWarningMessage('foobar'); | ||
trigger_error('foobar', E_USER_WARNING); | ||
} | ||
|
||
public function testError() | ||
{ | ||
$this->expectError(); | ||
$this->expectErrorMessage('foobar'); | ||
trigger_error('foobar', E_USER_ERROR); | ||
} | ||
|
||
public function testDeprecation() | ||
{ | ||
// This test fails. | ||
$this->expectDeprecation(); | ||
$this->expectDeprecationMessage('foobar'); | ||
trigger_error('foobar', E_USER_DEPRECATED); | ||
} | ||
} |
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