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
fix compatibility with PHPUnit error expectations #6461
Conversation
d3743b5
to
36426ab
Compare
Tests are failing because of But maybe that's desired..? |
36426ab
to
1a9f31f
Compare
There methods are quite recent, they there introduced in PHPUnit 8.4, |
}elseif ($errno === E_USER_ERROR) { | ||
throw new Error($errstr, $errno, $errfile, $errline); | ||
} | ||
|
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.
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
if (version_compare(\PHPUnit\Runner\Version::id(), '8.4.0', '>=')) {
...
}
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:
@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.
class Foo {
public function foo(): {
trigger_error('foo is deprecated', E_USER_DEPRECATED);
}
}
class FooTest extends Codeception\Unit {
public function test_that_foo_triggers_deprecation() {
$this->expectDeprecation('foo is deprecated');
(new Foo())->foo();
}
}
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.
- See how
error_level
option is handled inhandle
. - Add new option to
$defaultSuiteSettings
https://github.com/Codeception/Codeception/blob/4.2/src/Codeception/Configuration.php#L116-L137 (the default value should be false too). - Document at https://github.com/Codeception/codeception.github.com/blob/master/docs/reference/Configuration.md#settings
class ErrorExceptionTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
|
||
public function test_notice() |
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.
testNotice
}elseif ($errno === E_USER_ERROR) { | ||
throw new Error($errstr, $errno, $errfile, $errline); | ||
} | ||
|
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
if (version_compare(\PHPUnit\Runner\Version::id(), '8.4.0', '>=')) {
...
}
|
||
private function skipIfNot72(CliGuy $I) | ||
{ | ||
if(PHP_VERSION_ID < 70200) { |
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.
And change this condition to
if (version_compare(\PHPUnit\Runner\Version::id(), '8.4.0', '<')) {
I implemented all proposed changes myself in #6469 |
@Naktibalda Great. Thanks a lot. |
I'm surprised that nobody noticed this before, but PHPUnits
expectNotice()
expectWarning()
,expectError()
methods dont seem to work at all.This is because the
ErrorHandler
transforms all errors into exceptions instead of conditionally looking at the error code (like the PHPUnit error handler).I created tests that prove this.
For deprecations, it's the same issue and I created a failing test. I don't now how to fix that tho because I don't understand how deprecations are currently handled here.