Opened 8 years ago
Closed 8 years ago
#39822 closed defect (bug) (fixed)
PHPUnit 6 compatibility
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.8 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Build/Test Tools | Keywords: | |
Focuses: | Cc: |
Description
PHPUnit no longer supports PHPUnit_Framework_TestCase
as the base class.
https://github.com/sebastianbergmann/phpunit/blob/6.0/ChangeLog-6.0.md#600---2017-02-03
$ phpunit Installing... Running as single site... To run multisite, use -c tests/phpunit/multisite.xml PHP Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /Users/miyauchi/wp-core/trunk/tests/phpunit/includes/testcase.php on line 15
I wrote aliases for it.
It looks woking fine with phpunit 5.6 and phpunit 6.
Attachments (4)
Change History (41)
#2
follow-up:
↓ 3
@
8 years ago
Oh, that is exactly right!
Do you know any solution to include it for PHP 5.2.
if ( class_exists( 'PHPUnit\Runner\Version' ) {}
doesn't work on PHP 5.2 right?
Thanks for your response.
#3
in reply to:
↑ 2
@
8 years ago
Replying to miyauchi:
I think that this should work fine on PHP 5.2:
<?php if ( class_exists( 'PHPUnit\Runner\Version' ) { require_once dirname( __FILE__ ) . '/phpunit-6-compat.php'; }
In the phpunit-6-compat.php
file would be the rest of the code, of course.
#4
@
8 years ago
The current patch fails on php5.2 - https://travis-ci.org/aaronjorbin/WordPress/jobs/200040930
#5
follow-up:
↓ 7
@
8 years ago
Thanks @jdgrimes , @jorbin
I updated the bootstrap.php
and phpunit-6-compat.php
.
But there are some errors on /usr/local/bin/phpunit --group ajax
with PHPUnit 6 for now.
(Sorry I tried only /usr/local/bin/phpunit
(without option) on my local machine.)
https://travis-ci.org/miya0001/WordPress/builds/200084016
I'll try to fix it tomorrow.
#6
@
8 years ago
There is also a deprecation error for the HHVM job: https://travis-ci.org/miya0001/WordPress/jobs/200084031
Fatal error: Class already declared: PHPUnit_Framework_Error_Deprecated in phar://phpunit-5.7.7.phar/phpunit/Framework/Error/Deprecated.php on line 21
#7
in reply to:
↑ 5
@
8 years ago
Replying to miyauchi:
But there are some errors on
/usr/local/bin/phpunit --group ajax
with PHPUnit 6 for now.
setExpectedException()
has been removed in PHPUnit 6: https://github.com/sebastianbergmann/phpunit/issues/2074
This ticket was mentioned in Slack in #core by boone. View the logs.
8 years ago
This ticket was mentioned in Slack in #core by johnbillion. View the logs.
8 years ago
#15
@
8 years ago
@gitlost In 39822.3.patch rather than replacing every instance of setExpectedException()
with _setExpectedException()
, you should be able to do something like this:
protected function setExpectedException( ... ) { if ( is_callable( 'parent::setExpectedException' ) ) { parent::setExpectedException( ... ); } else { // shim code } }
#17
follow-up:
↓ 20
@
8 years ago
- Keywords needs-refresh removed
- Milestone changed from Awaiting Review to 4.8
- Version trunk deleted
39822.4.patch Looks good.
#18
@
8 years ago
Any ETA on when this will show up in https://develop.svn.wordpress.org/trunk/ ?
This ticket was mentioned in Slack in #core by robertpeake. View the logs.
8 years ago
#20
in reply to:
↑ 17
@
8 years ago
#23
@
8 years ago
- Keywords needs-patch added; has-patch removed
- Resolution fixed deleted
- Status changed from closed to reopened
This broke the PHP 5.2 build: https://travis-ci.org/aaronjorbin/develop.wordpress/jobs/224813063
I'll look into it tomorrow.
#26
in reply to:
↑ 24
@
8 years ago
Replying to johnbillion:
In 40539:
I'm now having issues with this in a plugin, due to the fact that is_callable( 'parent::method' )
is apparently not supported on PHP 5.2 when the method is actually on the grandparent.
When using setExpectedException()
in a testcase extending WP_Ajax_UnitTestCase
, I now get this error:
Fatal error: Call to undefined method WordPoints_Breaking_Module_Check_Ajax_Test::expectException() in /tmp/wordpress/tests/phpunit/includes/testcase-ajax.php on line 215
However, method_exists( 'PHPUnit_Framework_TestCase', 'setExpectedException' )
would appear to work. See https://3v4l.org/it5tc#v512
Won't the use of the namespace separator in that code cause a parse an error on PHP 5.2? I know that it won't actually be executed, because an older version of PHPUnit will be running on that old of a version of PHP. But WordPress still runs its tests against PHP 5.2, so this solution needs to be PHP 5.2 compatible. And because the code is a part of the file, even if it isn't executed, it will still have to get parsed.
I would say the best way to fix this would be to move the migration code to a separate file, that would only be included (and thus parsed),
if ( class_exists( 'PHPUnit\Runner\Version' ) {}
. That way the main file should still parse on PHP 5.2, and the migration file that requires a newer PHP version to parse won't be loaded then.