So I installed phpunit globally using composer. But I want to use it in a project that also uses composer, but doesn't have phpunit installed (the reasons for this are boring).
So I run the first test below and get the error.
Fatal error: Class 'PHPUnit\Framework\TestCase' not found in /vagrant/sites/core/trunk/Notify/php/tests/MyFirstTest.php on line 5
I thought that loading the global composer autoloader would let phpunit look in the global composer directory for the phpunit classes but it doesn't seem to be able to find it. I guess it's setting $vendorDir (below) to the local composer directory instead of the global one. Is there a way to make it check both?
Here's the line from /home/vagrant/.composer/vendor/composer/autoload_classmap.php that shows the class is in the global autoload classmap.
'PHPUnit_Framework_TestCase' => $vendorDir . '/phpunit/phpunit/src/Framework/TestCase.php',
Here's the command line I'm using to start the process.
phpunit --bootstrap tests/bootstrap.php tests/MyFirstTest.php
Here's MyFirstTest.php
<?php
use PHPUnit\Framework\TestCase;
class MyFirstTest extends TestCase {
public function testOneIsOne() {
$this->assertEquals(1, 1);
}
}
Here's bootstrap.php where I load the global phpunit autoloader.
<?php
require_once('/home/vagrant/.composer/vendor/autoload.php');
Writing out this question has helped to clarify my thoughts a lot. If anyone's got a nice solution that'd be great. I'm starting to think I should just install phpunit locally.
Cheers for any advice.
require-dev
section of yourcomposer.lock
file. Just install it for your project. – Bartosz Zasada