I am trying to use PhpUnit with Composer. In this purpose I did:
1 Added phpunit to req composer section:
"require": { "php": ">=5.3.0" }, "require-dev": { "phpunit/phpunit": "3.7.*" }, "autoload": { "psr-0": {"PhpProject": "src/"} }
2 Installed what needed:
php composer.phar install --dev
Operation finished with success.
Installing phpunit/phpunit (3.7.6) Downloading: 100%
Unfortunately when I want to run the tests, I get
./vendor/bin/phpunit PHP Fatal error: Call to a member function add() on a non-object in /home/serek/php/project/tests/bootstrap.php on line 12
Problem occurs because return ComposerAutoloaderInit::getLoader(); in vendor/autoload returns NULL into test bootstrap.
Any idea how can it be solved without hacking Loader?
Code: phpunnit.xml.dist
> <?xml version="1.0" encoding="UTF-8"?>
>
> <phpunit bootstrap="tests/bootstrap.php" colors="true">
> <testsuites>
> <testsuite name="PhpProject Test Suite">
> <directory>tests/PhpProject/</directory>
> </testsuite>
> </testsuites>
>
> <filter>
> <whitelist>
> <directory suffix=".php">src/PhpProject/</directory>
> </whitelist>
> </filter> </phpunit>
tests/bootstrap.php (here I need only autoloader)
> $loader = require_once __DIR__ . "/../vendor/autoload.php";
> $loader->add('PhpProject\\', __DIR__); //<- this is problematic line 12 (comments has 9 lines)
/../vendor/autoload.php
// autoload.php generated by Composer
require_once __DIR__ . '/composer' . '/autoload_real.php';
return ComposerAutoloaderInit::getLoader();
require_once
and return values does not make much sense, it perhaps should berequire
. Also ensure the file is actually returning something. – hakre