No class autoload in case of running Functional Tests with "processIsolation"

Hi,

I'm setting up remote tests execution from withing PhpStorm (9.0.2).

I did everything, like suggested in this article
And for unit tests it works perfectly: run tests, debug them, generate code coverage - all is good.

Next step was to create "run configuration" for functional tests as well and then I faced errors, like:

PHP Fatal error:  Class 'PHPUnit_Util_Configuration' not found in - on line 368
PHP Stack trace:
PHP   1. {main}() -:0

Fatal error: Class 'PHPUnit_Util_Configuration' not found in - on line 368

Call Stack:
    0.0012     401240   1. {main}() -:0


After some debugging and playing around with configuration, I realized, taht issue comes, when "processIsolation" is set (which is true for functional tests).
So, even 100% working configuration for unit tests also throws such a nerror with "processIsolation" set.

Here are more details:
"Run/Debug Configuration" -> "Test Runner" -> "Defined in the configuration file"
"Run/Debug Configuration" -> "Test Runner" -> "Use alternative configuration file" -> "path to my local UnitTests.xml"

Contents of UnitTests.xml:

 
<phpunit
   backupGlobals="true"
   backupStaticAttributes="false"
   bootstrap="typo3_src/typo3/sysext/core/Build/UnitTestsBootstrap.php"
   colors="true"
   convertErrorsToExceptions="true"
   convertWarningsToExceptions="true"
   forceCoversAnnotation="false"
   processIsolation="false"
   stopOnError="false"
   stopOnFailure="false"
   stopOnIncomplete="false"
   stopOnSkipped="false"
   verbose="false"
>
   <testsuites>
      <testsuite name="My Suite">
         <directory>www/typo3conf/ext/my_ext/Tests/Unit/</directory>
      </testsuite>
   </testsuites>
   <filter>
      <whitelist>
         <directory>www/typo3conf/ext/my_ext/Classes/</directory>
      </whitelist>
   </filter>
</phpunit>


At Settings: "PHPUnit" - remote interpreter is configured and is set to "Use custom autoloader" with "remote_path_to/vendor/autoload.php"
Remote Interpreter is taken from "Deployment configuration" via SFTP.

Running "Unit Tests" configuration with data, provided above:

sftp://user@host:port/usr/bin/php /path_to_home/.phpstorm_helpers/phpunit.php --configuration /path_to_home/UnitTests.xml Testing started at 20:25 ... PHPUnit 4.8.16 by Sebastian Bergmann and contributors. Time: 874 ms, Memory: 24.00Mb OK (61 tests, 99 assertions) Process finished with exit code 0


But as soon as processIsolation="true" is set in XML file, I'm getting:

sftp://user@host:port/usr/bin/php /path_to_home/.phpstorm_helpers/phpunit.php --configuration /path_to_home/UnitTests.xml Testing started at 20:27 ... PHPUnit 4.8.16 by Sebastian Bergmann and contributors. PHP Fatal error:  Class 'PHPUnit_Util_Configuration' not found in - on line 368 PHP Stack trace: PHP   1. {main}() -:0 Fatal error: Class 'PHPUnit_Util_Configuration' not found in - on line 368 Call Stack:     0.0026     535808   1. {main}() -:0 /path_to_home/.phpstorm_helpers/phpunit.php:294 /path_to_home/.phpstorm_helpers/phpunit.php:552


--CUT--

Time: 4.03 seconds, Memory: 17.25Mb FAILURES! Tests: 61, Assertions: 0, Errors: 61. Process finished with exit code 2


For me it seems, like autoload.php file is ignored. What can be the case?

2 comments
Comment actions Permalink

Hi there,

Just a random thought (nothing serious) ... but please try PhpStorm v10 + PHPUnit v5.x (+ possibly PHAR version of it).

The ideas behind such suggestion: In PhpStorm v10 it uses PHPUnit (v5 PHAR in particular) directly without wrapper (at least that's what I see when doing local testing).

0
Comment actions Permalink

I see the same error with phpstorm 10.0.1 + phpunit 5.0.9. I'm using a remote interpreter which is on Vagrant. While it works on the Vagrant shell, I guess phpstorm doesn't add autoloader configuration for @runInSeparateProcess. Let me know if I could provide more useful information.

vagrant:///Users/nobu/usr/bin/php /home/vagrant/.phpstorm_helpers/phpunit.php --bootstrap /vagrant/nobu/bootstrap.php --configuration /vagrant/nobu/phpunit.xml /vagrant/nobu/tests

...skip

PHP Fatal error:  Class 'PHPUnit_Util_Configuration' not found in - on line 77 Fatal error: Class 'PHPUnit_Util_Configuration' not found in - on line 77


UPDATE:

I realize PHPUNIT_COMPOSER_INSTALL is not defined when phpstorm runs phpunit while vendor/bin/phpunit (installed via composer) does define it. This makes $composerAutoload empty when an isolated test is running. The variable will be used in TestCaseMethod.tpl.dist to activate the autoloader.

Adding the constant into /home/vagrant/.phpstorm_helpers/phpunit.php solves the issue:

<?php

define('PHPUNIT_COMPOSER_INSTALL', '/vagrant/nobu/vendor/autoload.php');

class IDE_PHPUnit_Loader
{
    public static $supportedVersions = array(

... skip


Under Preferences --> Languages & Frameworks --> PHP --> PHPUnit, I have a PHPUnit with "Use custom autoloader" checked. I see PHPUnit 5.0, 4.8 are not in $supportedVersions in the .phpstorm_helpers/phpunit.php, though apparently the same issue exists in 4.1.6 as well.

UPDATE2:

There's a better workaround. https://youtrack.jetbrains.com/issue/WI-29458 https://www.drupal.org/node/2597814

0

Please sign in to leave a comment.