As a follow up for #2110153: Upgrade phpunit/php-file-iterator from 1.3.3 to 1.3.4, here's a patch that updates all the other phpunit components we're using. Let's update these things and test how decoupled our use of these components are. We shouldn't break anything by upgrading minor versions.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cosmicdreams’s picture

Status: Active » Needs review
FileSize
149.92 KB

Here's a patch that updates the following:

phpunit/php-timer => (1.0.5)
phpunit/php-token-stream => (1.2.1)
phpunit/php-code-coverage => (1.2.13)
phpunit/phpunit =>(3.7.28)

cweagans’s picture

cosmicdreams’s picture

Oh I hadn't realized I had already opened this issue. Cool.

Now that we have composer, updating PHPUnit is one composer -update operation away. PHPUnit does state that the 3.7 version of their suite is LTS. It's not exactly clear what they mean by LTS and how much longer we should expect it to be supported.

Either way, 4.0 is the new shiny and there are a few things in the Changlog that sound like it may interest us here. Specifically:

Implemented #773: Recursive and repeated arrays are more gracefully when comparison differences are exported.
Implemented #813: Added @before, @after, @beforeClass and @afterClass annotations.
Implemented #838: Added a base test listener.
Implemented #869: Added support for the adjacent sibling selector (+) to PHPUnit_Util_XML::findNodes().
Implemented #871: Add Comparator for DateTime objects.
Implemented #877: Added new HTML5 tags to PHPUnit_Util_XML::findNodes().
Fixed #240: XML strings are escaped by removing invalid characters.

Full changelog: https://github.com/sebastianbergmann/phpunit/wiki/ChangeLog-for-PHPUnit-4.0
Release notes: https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-f...

cosmicdreams’s picture

Status: Needs review » Closed (duplicate)

Marking this one as a duplicate of #2159845: Upgrade to PHPUnit 4

webchick’s picture

Status: Closed (duplicate) » Needs review

This one's older, let's use this issue.

webchick’s picture

Status: Needs review » Needs work

Oops. We need a new patch.

tim.plunkett’s picture

Removing the staticExpects in AccessManagerTest and ReverseProxySubscriberUnitTest does not make the tests fail, but it might affect what lines of code they cover.

However, the staticExpects in EntityManagerTest is a problem.
In EntityManager::buildBaseFieldDefinitions() it calls $base_field_definitions = $class::baseFieldDefinitions($entity_type); and then foreaches over it. Removing the staticExpects makes this null, so you get a nice Invalid argument supplied for foreach().

Not sure what to do there.

cosmicdreams’s picture

I'll try to put together the patch to update phpunit tonight (unless someone beats me to it). Hopefully after that, we'll have specific test failures to address.

Xano’s picture

@cosmicdreams: do you have something already, or can I safely make a patch without being in your way?

cosmicdreams’s picture

You can, but beware of Dragons. I haven't contributed back a patch for this because TONS of things break by moving to PHPUnit 4. I've been trying to diagnose what's wrong and what needs to be fixed but it's a bit beyond me.

dawehner’s picture

@cosmicdreams
Do you have a list of tests which fail after the update?

cosmicdreams’s picture

It's the test runner that fails. so no I do not.

dawehner’s picture

Whath happens if you use the native phpunit test runner?

neclimdul’s picture

nothing currently, it somehow hands off to Drupal's runner. If you update composer.json and run composer update it will use the 4.0 runner and it fails because we use the goofy staticExpects method that is gone because it was apparently sort of broken. I was going to take a swing then saw this was sprinkled in our base entity tests and I don't have the chops to testing EntityAPI.

http://phpunit.de/manual/current/en/appendixes.upgrading.html#appendixes...

Xano’s picture

Title: Update phpunit to latest stable version. » Update PHPUnit to 4.x
cosmicdreams’s picture

FileSize
2.86 MB

Here's a patch that updates to PhpUnit 4.1.0. When I run the tests here's the error I get:

"C:\Program Files (x86)\Dev Desktop\php5_4\php.exe" C:\Users\karen_000\AppData\Local\Temp\ide-phpunit.php --configuration C:\Users\karen_000\Sites\d8\core\phpunit.xml.dist
Testing started at 9:28 AM ...
PHPUnit 4.1.0 by Sebastian Bergmann.

Configuration read from C:\Users\karen_000\Sites\d8\core\phpunit.xml.dist


Fatal error: Call to undefined method Mock_Request_5a8ef19b::staticExpects() in C:\Users\karen_000\Sites\d8\core\tests\Drupal\Tests\Core\Access\AccessManagerTest.php on line 442

Call Stack:
    0.0026     208184   1. {main}() C:\Users\karen_000\AppData\Local\Temp\ide-phpunit.php:0
    0.0430     841760   2. IDE_Base_PHPUnit_TextUI_Command::main() C:\Users\karen_000\AppData\Local\Temp\ide-phpunit.php:491
    0.0430     848816   3. PHPUnit_TextUI_Command->run() C:\Users\karen_000\AppData\Local\Temp\ide-phpunit.php:243
   11.7887   51571912   4. PHPUnit_TextUI_TestRunner->doRun() phar://C:/Users/karen_000/Sites/phpunit.phar/phpunit/TextUI/Command.php:179
   11.7934   51699304   5. PHPUnit_Framework_TestSuite->run() C:\Users\karen_000\Sites\d8\core\vendor\phpunit\phpunit\src\TextUI\TestRunner.php:426
   17.9066   53537344   6. PHPUnit_Framework_TestSuite->run() C:\Users\karen_000\Sites\d8\core\vendor\phpunit\phpunit\src\Framework\TestSuite.php:675
   18.2253   55078688   7. PHPUnit_Framework_TestCase->run() C:\Users\karen_000\Sites\d8\core\vendor\phpunit\phpunit\src\Framework\TestSuite.php:675
   18.2253   55078656   8. PHPUnit_Framework_TestResult->run() C:\Users\karen_000\Sites\d8\core\vendor\phpunit\phpunit\src\Framework\TestCase.php:753
   18.2255   55079304   9. PHPUnit_Framework_TestCase->runBare() C:\Users\karen_000\Sites\d8\core\vendor\phpunit\phpunit\src\Framework\TestResult.php:686
   18.2283   55220080  10. PHPUnit_Framework_TestCase->runTest() C:\Users\karen_000\Sites\d8\core\vendor\phpunit\phpunit\src\Framework\TestCase.php:817
   18.2283   55220640  11. ReflectionMethod->invokeArgs() C:\Users\karen_000\Sites\d8\core\vendor\phpunit\phpunit\src\Framework\TestCase.php:951
   18.2283   55220656  12. Drupal\Tests\Core\Access\AccessManagerTest->testCheckNamedRouteWithUpcastedValues() C:\Users\karen_000\Sites\d8\core\vendor\phpunit\phpunit\src\Framework\TestCase.php:951

PHP Fatal error:  Call to undefined method Mock_Request_5a8ef19b::staticExpects() in C:\Users\karen_000\Sites\d8\core\tests\Drupal\Tests\Core\Access\AccessManagerTest.php on line 442
PHP Stack trace:
PHP   1. {main}() C:\Users\karen_000\AppData\Local\Temp\ide-phpunit.php:0
PHP   2. IDE_Base_PHPUnit_TextUI_Command::main() C:\Users\karen_000\AppData\Local\Temp\ide-phpunit.php:491
PHP   3. PHPUnit_TextUI_Command->run() C:\Users\karen_000\AppData\Local\Temp\ide-phpunit.php:243
PHP   4. PHPUnit_TextUI_TestRunner->doRun() phar://C:/Users/karen_000/Sites/phpunit.phar/phpunit/TextUI/Command.php:179
PHP   5. PHPUnit_Framework_TestSuite->run() C:\Users\karen_000\Sites\d8\core\vendor\phpunit\phpunit\src\TextUI\TestRunner.php:426
PHP   6. PHPUnit_Framework_TestSuite->run() C:\Users\karen_000\Sites\d8\core\vendor\phpunit\phpunit\src\Framework\TestSuite.php:675
PHP   7. PHPUnit_Framework_TestCase->run() C:\Users\karen_000\Sites\d8\core\vendor\phpunit\phpunit\src\Framework\TestSuite.php:675
PHP   8. PHPUnit_Framework_TestResult->run() C:\Users\karen_000\Sites\d8\core\vendor\phpunit\phpunit\src\Framework\TestCase.php:753
PHP   9. PHPUnit_Framework_TestCase->runBare() C:\Users\karen_000\Sites\d8\core\vendor\phpunit\phpunit\src\Framework\TestResult.php:686
PHP  10. PHPUnit_Framework_TestCase->runTest() C:\Users\karen_000\Sites\d8\core\vendor\phpunit\phpunit\src\Framework\TestCase.php:817
PHP  11. ReflectionMethod->invokeArgs() C:\Users\karen_000\Sites\d8\core\vendor\phpunit\phpunit\src\Framework\TestCase.php:951
PHP  12. Drupal\Tests\Core\Access\AccessManagerTest->testCheckNamedRouteWithUpcastedValues() C:\Users\karen_000\Sites\d8\core\vendor\phpunit\phpunit\src\Framework\TestCase.php:951

Process finished with exit code 255
ParisLiakos’s picture

Component: other » phpunit
Category: Bug report » Task
neclimdul’s picture

Yeah thats the error I mentioned. staticExpects was removed as is documented in the upgrade guide I posted.
Fatal error: Call to undefined method Mock_Request_5a8ef19b::staticExpects() in

tim.plunkett’s picture

I called it out in #7 as well.

cosmicdreams’s picture

So it seems like the last good direction we got on this issue was from #7 where it sounds like tim's calling for a rewrite of the EntityManagerTest. Seems like that is what's needed in order to advance this issue. I'm not the best equipped to do that but I'll give it a shot over the next week.

Xano’s picture

Status: Needs work » Needs review
FileSize
15.88 MB

This updates PHPUnit to 4.1.1. I will continue working on replacing staticExpects() usages.

Status: Needs review » Needs work

The last submitted patch, 21: drupal_2114823_21.patch, failed testing.

Xano’s picture

Status: Needs work » Needs review
FileSize
15.89 MB

This patch contains the upgrade and the necessary staticExpects() conversions.

Status: Needs review » Needs work

The last submitted patch, 23: drupal_2114823_23_combined.patch, failed testing.

Xano’s picture

Status: Needs work » Needs review
FileSize
15.97 MB

Status: Needs review » Needs work

The last submitted patch, 25: drupal_2114823_25_combined.patch, failed testing.

neclimdul’s picture

Status: Needs work » Needs review
FileSize
12.93 MB

Some tests ran through with this. Lets see how testbot likes it.

Status: Needs review » Needs work

The last submitted patch, 27: drupal_2114823_27_combined.patch, failed testing.

Xano’s picture

Status: Needs work » Needs review
FileSize
15.97 MB
ParisLiakos’s picture

cool its green. can we have the changes excluding /vendor so dreditor doesnt crash?

sun’s picture

Is it possible to split those functional test changes into a separate issue?

Xano’s picture

Is it possible to split those functional test changes into a separate issue?

What changes? There is nothing in here that isn't necessary for the upgrade.

neclimdul’s picture

I think he meant fix the tests first since the changes will work in the current version of phpunit, then do the upgrade changes.

Xano’s picture

Status: Needs review » Postponed
alexpott’s picture

FileSize
2.75 MB

Here is a patch to only upgrade PHPUnit and not touch any other files.

Instructions to generate this patch:

  1. Edit composer.json change phpunit version to 4.1.*
  2. Remove /core/vendor/phpunit
  3. remove /core/vendor/bin/phpunit
  4. run "composer update phpunit/phpunit"
Xano’s picture

Thank you for the instructions!

neclimdul’s picture

Status: Postponed » Needs work
Issue tags: +Needs reroll

#2278705: Make all tests compatible with PHPUnit 4 is in so we'll need a re-roll and this is back active!

cosmicdreams’s picture

i must be having problems with the git or something because I can't seem to get all the folder renaming to commit.

neclimdul’s picture

Status: Needs work » Needs review
FileSize
13.04 MB

Yeah I couldn't apply it either. I had to export with --binary to get the patch to re-apply. Lets see what the bot says.

Status: Needs review » Needs work

The last submitted patch, 39: 2114823.39.patch, failed testing.

neclimdul’s picture

Status: Needs work » Needs review
FileSize
12.95 MB
1.37 KB

gugh, the simpletest.module fix.

Status: Needs review » Needs work

The last submitted patch, 41: 2114823.41.patch, failed testing.

Berdir’s picture

Looks like the latest patches have the whole zend framework in them, I also tried the approach in #35 manually and it resulted in the same.

alexpott’s picture

Status: Needs work » Needs review
FileSize
3.56 MB

Dunno why but the steps in 35 still work for me.

Status: Needs review » Needs work

The last submitted patch, 44: 2114823.44.patch, failed testing.

alexpott’s picture

Status: Needs work » Needs review
FileSize
6.01 MB

Now including the simpletest.module fix too :) And patch made with --binary option too... hence the size increase.

alexpott’s picture

After applying the patch with -a the following changes outsite /core/vendor/phpunit and core/vendor/sebastian are made:

git st | grep -v 'core/vendor/sebastian' | grep -v 'core/vendor/phpunit'
M  composer.json
M  composer.lock
M  core/modules/simpletest/simpletest.module
M  core/vendor/bin/phpunit
M  core/vendor/composer/autoload_classmap.php
M  core/vendor/composer/include_paths.php
M  core/vendor/composer/installed.json

Which are all expected.

Xano’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs reroll

The patch adds a few new packages to the sebastian vendor directory, but since they are all licensed under the BSD-3, this still allows us to add the code to our own repo. Other than that, the patch only changes core's composer.json and simpletest.module, and updates phpunit packages, so I think we're good to go!

Thanks for helping move this forward, people!

The last submitted patch, 35: 2114823.35.patch, failed testing.

Xano’s picture

Ignore that. It's feedback for an old patch.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Holy crow. This patch officially wins the "Most Deceptively Simple Looking But Biggest Pain In The Rear To Actually Commit Patch" award. ;)

For some reason—I suspect because I'm on Mac OS which is case-insensitive, and there are file renames here—the patch would not apply for me, even with git apply --binary --index. It complained loudly about a bunch of files already in my working directory. Neither a git clean -df; git reset --hard nor a fresh git clone resolved the matter, nor did blitzing the core/vendor/phpunit dir.

What we ended up resorting to was chx applying the patch on his local clone of D8 and then tarring it up and sending it to me over Skype for me to execute on my machine. :P However, because of various reasons, that needed to actually be done 3(!) times, at ~145M of transfer a pop. :)

Long story short, committed and pushed to 8.x, and I added chx to the commit credit here, because without him, this never would've been committed, at least by me. :P Thanks!

  • Commit da85a66 on 8.x by webchick:
    Issue #2114823 by alexpott, neclimdul, Xano, cosmicdreams, chx: Update...
tim.plunkett’s picture

Title: Update PHPUnit to 4.x » [HEAD BROKEN] Update PHPUnit to 4.x
Status: Fixed » Reviewed & tested by the community
FileSize
1.63 KB

All PHPUnit tests are being ignored by run-tests.sh now.
The last core test run before this patch had ~72000 passes. The first one after this had ~67000, and we have ~5000 unit test assertions.

The typehint changes to simpletest.module explains the problem. What we have as $test_suite is actually an array of test suites.
We need to retrieve the test from the suite.

If this patch has ~72000 passes, it's good.

tim.plunkett’s picture

Status: Reviewed & tested by the community » Needs review

Hmmmm, it didn't get back to 70K, but I do now see unit tests like AddRoleUserTest and LocalActionManagerTest in the list, which aren't on https://qa.drupal.org/8.x-status.

So maybe my math is off?

Berdir’s picture

Category: Task » Bug report
Priority: Normal » Critical

Yeah, we're still missing tests.

I can't see a pattern yet, but one that is missing and that's contributing 2800 assertions is SystemControllerTest. What's weird is that I can run it if I pass it explicitly but the discovery doesn't find it:

$ php core/scripts/run-tests.sh --list | grep SystemControllerTest

Finds nothing. But...

$ php core/scripts/run-tests.sh --class "Drupal\system\Tests\Controller\SystemControllerTest"

Drupal test run
---------------

Tests to be run:
  - Drupal\system\Tests\Controller\SystemControllerTest

Test run started:
  Sunday, June 15, 2014 - 10:35

Test summary
------------

Drupal\system\Tests\Controller\SystemControllerTest          2808 passes                                      

Test run duration: 4 sec
olli’s picture

FileSize
781 bytes

Can we do this?

olli’s picture

FileSize
726 bytes
682 bytes

Or without is_subclass_of().

Xano’s picture

+++ b/core/modules/simpletest/simpletest.module
@@ -789,8 +789,8 @@ function simpletest_phpunit_get_available_tests($module = NULL) {
+      if (is_subclass_of($name, '\Drupal\Tests\UnitTestCase') && !array_key_exists($name, $test_classes) && (!$module || substr($name, 0, $n) == $prefix)) {

Why does is_subclass_of() work, while instanceof doesn't?

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

Because $test is PHPUnit_Framework_TestSuite, while $name is the test class itself.
#57 works great, and has 72K passes, and php core/scripts/run-tests.sh --list | grep SystemControllerTest works for it. Thanks @olli!

webchick’s picture

Status: Reviewed & tested by the community » Fixed

I knew there was no way we were getting off that easily. :)

Committed and pushed to 8.x. Thanks so much for the quick find + fix!

  • Commit 81d8d75 on 8.x by webchick:
    Issue #2114823 follow-up by olli: Fixed SimpleTest no longer finding...
tim.plunkett’s picture

Title: [HEAD BROKEN] Update PHPUnit to 4.x » Update PHPUnit to 4.x
Category: Bug report » Task
Priority: Critical » Normal

Thanks @webchick!

sun’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.