New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix compatibility with PHPUnit error expectations #6461
Closed
calvinalkan
wants to merge
1
commit into
Codeception:4.2
from
snicco:fix/error-handling-expectations
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
class ErrorExpectationsCest | ||
{ | ||
|
||
public function _before(\CliGuy $I) | ||
{ | ||
$I->amInPath('tests/data/error_handling'); | ||
} | ||
|
||
public function expectNoticeWorks(\CliGuy $I) | ||
{ | ||
$this->skipIfNot72($I); | ||
|
||
$I->executeCommand('run tests/unit/ErrorExceptionTest.php:test_notice'); | ||
$I->seeInShellOutput("OK ("); | ||
} | ||
|
||
public function expectWarningWorks(\CliGuy $I) | ||
{ | ||
$this->skipIfNot72($I); | ||
|
||
$I->executeCommand('run tests/unit/ErrorExceptionTest.php:test_warning'); | ||
$I->seeInShellOutput('OK ('); | ||
} | ||
|
||
public function expectErrorWorks(\CliGuy $I) | ||
{ | ||
$this->skipIfNot72($I); | ||
|
||
$I->executeCommand('run tests/unit/ErrorExceptionTest.php:test_error'); | ||
$I->seeInShellOutput('OK ('); | ||
} | ||
|
||
public function expectDeprecationWorks(\CliGuy $I) | ||
{ | ||
$this->skipIfNot72($I); | ||
$I->markTestSkipped('This test is just to reproduce that is doesnt work. It will fail because nothing has been implemented'); | ||
|
||
$I->executeCommand('run tests/unit/ErrorExceptionTest.php:test_deprecation'); | ||
$I->seeInShellOutput('OK ('); | ||
} | ||
|
||
private function skipIfNot72(CliGuy $I) | ||
{ | ||
if(PHP_VERSION_ID < 70200) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And change this condition to if (version_compare(\PHPUnit\Runner\Version::id(), '8.4.0', '<')) { |
||
$I->markTestSkipped('expectXXX is only available on 7.2+'); | ||
} | ||
} | ||
|
||
} | ||
|
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,13 @@ | ||
actor: Tester | ||
paths: | ||
tests: tests | ||
log: tests/_output | ||
data: tests/_data | ||
support: tests/_support | ||
envs: tests/_envs | ||
suites: | ||
unit: | ||
path: . | ||
modules: | ||
enabled: | ||
- Asserts |
Empty file.
35 changes: 35 additions & 0 deletions
35
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,35 @@ | ||
<?php | ||
|
||
class ErrorExceptionTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
|
||
public function test_notice() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
$this->expectNotice(); | ||
$this->expectNoticeMessage('foobar'); | ||
trigger_error('foobar', E_USER_NOTICE); | ||
} | ||
|
||
public function test_warning() | ||
{ | ||
$this->expectWarning(); | ||
$this->expectWarningMessage('foobar'); | ||
trigger_error('foobar', E_USER_WARNING); | ||
} | ||
|
||
public function test_error() | ||
{ | ||
$this->expectError(); | ||
$this->expectErrorMessage('foobar'); | ||
trigger_error('foobar', E_USER_ERROR); | ||
} | ||
|
||
public function test_deprecation() | ||
{ | ||
// 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To get this change into Codeception 4, it must be compatible with PHPUnit 5.7.
Classes you used here were renamed in PHPUnit 6.0, so this code would cause fatal error.
Please add some test that runs on all versions of PHP.
Then add class aliases to https://github.com/Codeception/phpunit-wrapper/blob/6.0/src/shim.php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Naktibalda What about the deprecation stuff?
Codeception should support
expectDeprecation
aswell.But I don't understand what is done there currently. Looks like something symfony-related.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codeception doesn't have to support any of this.
Deprecations are counted and summary is printed below test results:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no equivalent of
Notice
class in PHPUnit 5.7.I think that it would be the best to wrap this section with
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Naktibalda But doesn't this just show the deprecations that occurred while running the test?
What I'm talking about (and what PHPUnit supports in the
TestCase
class) is making assertions about deprecations.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since 8.5.21 PHPUnit doesn't convert deprecations to exceptions by default, it requires setting configuration option.
https://github.com/sebastianbergmann/phpunit/blob/8.5/ChangeLog-8.5.md#8521---2021-09-25
You could implement
convert_deprecations_to_exceptions
option too.error_level
option is handled inhandle
.$defaultSuiteSettings
https://github.com/Codeception/Codeception/blob/4.2/src/Codeception/Configuration.php#L116-L137 (the default value should be false too).