Skip to content


Unable to run tests with phpunit and composer installed globally #1248

adityamenon opened this Issue · 13 comments

4 participants


I'm on debian squeeze. When I run phpunit in ./tests without any dependencies, I get feedback that many tests are passing but many tests also fail for lack of vfsStreamWrapper.

I did composer install on ./, and it installed the vfsStreamWrapper package, but also created another composer directory in vendor/ with some autoload functionality. Now when I run tests, I see

PHP Fatal error: Cannot redeclare class Composer\Autoload\ClassLoader in
/home/username/src/username/CodeIgniter/vendor/composer/ClassLoader.php on line 44

So I removed line 44 from ./tests/Bootstrap.php - which looks like it includes the local Autoloader. Now when I run the tests, I again see that many tests pass, but also many errors about vfsStreamWrapper not being found. Here's a sample:

Warning: Class 'org\bovigo\vfs\vfsStreamWrapper' not found in /home/username/src/username/CodeIgniter/tests/Bootstrap.php on line 31
PHPUnit 3.7.8 by Sebastian Bergmann.

Configuration read from /home/username/src/username/CodeIgniter/tests/phpunit.xml

........................EEEEEEEEEEEE........................SS.  63 / 238 ( 26%)
S......................ES.EEEEE................................ 126 / 238 ( 52%)
.................................................EEEE.......... 189 / 238 ( 79%)

Time: 3 seconds, Memory: 8.25Mb

There were 45 errors:

1) Loader_test::test_library
InvalidArgumentException: Unable to load vfsStreamWrapper.

2) Loader_test::test_load_library_in_application_dir
InvalidArgumentException: Unable to load vfsStreamWrapper.

3) Loader_test::test_non_existent_model
InvalidArgumentException: Unable to load vfsStreamWrapper.

4) Loader_test::test_models
InvalidArgumentException: Unable to load vfsStreamWrapper.

and so on...

How do I get this to work? I just want to see the glorious All tests passing message ;_;


I'm extremely sorry, I believed I was on the Ellislab/CodeIgniter repo when I hit 'report issue' - just noticed this is the composer issue queue :eek:!

I will delete/close this issue if it is totally irrelevant, but on second thought, this also looks like a good place to ask this question. Please forgive me and feel free to close this in case this is off-topic here... sorry again!

Composer member

It's a known issue, since both phpunit and your project use composer's autoloader things clash.


Oh-kay, thanks for that piece of info, feel better =) So, removing composer is the temporary solution to getting this to work? That does seem possible because I was wondering how Travis was able to run any tests - it says build-status:passing on CodeIgniter.

If it helps, here is a stack trace I got after installing xdebug:

munna@debian:~/src/munna/CodeIgniter/tests$ phpunit
PHP Fatal error:  Cannot redeclare class Composer\Autoload\ClassLoader in /home/munna/src/munna/CodeIgniter/vendor/composer/ClassLoader.php on line 44
PHP Stack trace:
PHP   1. {main}() /home/munna/src/munna/phpunit/vendor/phpunit/phpunit/composer/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /home/munna/src/munna/phpunit/vendor/phpunit/phpunit/composer/bin/phpunit:65
PHP   3. PHPUnit_TextUI_Command->run() /home/munna/src/munna/phpunit/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:129
PHP   4. PHPUnit_TextUI_Command->handleArguments() /home/munna/src/munna/phpunit/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:138
PHP   5. PHPUnit_TextUI_Command->handleBootstrap() /home/munna/src/munna/phpunit/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:606
PHP   6. PHPUnit_Util_Fileloader::checkAndLoad() /home/munna/src/munna/phpunit/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:778
PHP   7. PHPUnit_Util_Fileloader::load() /home/munna/src/munna/phpunit/vendor/phpunit/phpunit/PHPUnit/Util/Fileloader.php:76
PHP   8. include_once() /home/munna/src/munna/phpunit/vendor/phpunit/phpunit/PHPUnit/Util/Fileloader.php:92
PHP   9. include_once() /home/munna/src/munna/CodeIgniter/tests/Bootstrap.php:25
PHP  10. require_once() /home/munna/src/munna/CodeIgniter/vendor/autoload.php:5
PHP  11. require() /home/munna/src/munna/CodeIgniter/vendor/composer/autoload_real.php:5

Fatal error: Cannot redeclare class Composer\Autoload\ClassLoader in /home/munna/src/munna/CodeIgniter/vendor/composer/ClassLoader.php on line 44

Call Stack:
    0.0021     120756   1. {main}() /home/munna/src/munna/phpunit/vendor/phpunit/phpunit/composer/bin/phpunit:0
    0.0155     321028   2. PHPUnit_TextUI_Command::main() /home/munna/src/munna/phpunit/vendor/phpunit/phpunit/composer/bin/phpunit:65
    0.0165     324124   3. PHPUnit_TextUI_Command->run() /home/munna/src/munna/phpunit/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:129
    0.0166     324340   4. PHPUnit_TextUI_Command->handleArguments() /home/munna/src/munna/phpunit/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:138
    0.0348     568520   5. PHPUnit_TextUI_Command->handleBootstrap() /home/munna/src/munna/phpunit/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:606
    0.0353     574460   6. PHPUnit_Util_Fileloader::checkAndLoad() /home/munna/src/munna/phpunit/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:778
    0.0355     574584   7. PHPUnit_Util_Fileloader::load() /home/munna/src/munna/phpunit/vendor/phpunit/phpunit/PHPUnit/Util/Fileloader.php:76
    0.0360     585444   8. include_once('/home/munna/src/munna/CodeIgniter/tests/Bootstrap.php') /home/munna/src/munna/phpunit/vendor/phpunit/phpunit/PHPUnit/Util/Fileloader.php:92
    0.0382     587284   9. include_once('/home/munna/src/munna/CodeIgniter/vendor/autoload.php') /home/munna/src/munna/CodeIgniter/tests/Bootstrap.php:25
    0.0386     593940  10. require_once('/home/munna/src/munna/CodeIgniter/vendor/composer/autoload_real.php') /home/munna/src/munna/CodeIgniter/vendor/autoload.php:5
    0.0394     618636  11. require('/home/munna/src/munna/CodeIgniter/vendor/composer/ClassLoader.php') /home/munna/src/munna/CodeIgniter/vendor/composer/autoload_real.php:5

Composer member

Travis works because it runs phpunit from pear and not composer, in the meantime you can use phpunit's new phar file distribution:


Glory be to you! The .phar file works perfectly, I did get test errors - but those are real failing tests. So my curiosity is quenched.

I do wonder why travis says everything is passing when I can see failing tests.. but I'll go pester those guys about it :) Have a nice day!

@Seldaek Seldaek closed this in 487e66d
Composer member

Ok this should now work even with a composer-installed phpunit.



@chillu chillu referenced this issue in silverstripe/silverstripe-framework

Fetch PHPUnit dependency through composer #940


This still seems to be happening for me? Installed Composer via homebrew then PHPUnit via Composer to /usr/local/bin and now getting this:

PHP Fatal error:  Cannot redeclare class Composer\Autoload\ClassLoader in /Users/matt/php/php-gitlab-api/vendor/composer/ClassLoader.php on line 44

Fatal error: Cannot redeclare class Composer\Autoload\ClassLoader in /Users/matt/php/php-gitlab-api/vendor/composer/ClassLoader.php on line 44

when I try and run phpunit...

Composer member

@m4tthumphrey this is most likely because you are using the version of homebrew which is the latest tagged release (quite old by now.. I should make a new one). I don't think it has this fix in. Just run composer self-update to update to the latest and then this should be fixed.


Ah ok. Thanks @Seldaek


Here we go again.
1. PHPUnit used as phar.
2. Calling without composer: get an error "File "Composer/Autoload/ClassLoader.php" does not exist or class "Composer\Autoload\ClassLoader" was not found".
3. Calling with composer: get an error "[InvalidArgumentException] Command "path/to/test" is not defined"


Should require as /vendor/autoload.php;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.