Follow up question from Autoloader for distributed PHP plugins that includes composer packages
I am writing an application that publishes distributed extensions for a CMS. Think of each distributed extension as a zip that contains the extension code and all its dependencies (which are copied composer packages).
In the package, there's an autoloader that loads it's dependencies.
I am using PHPUnit to test if the dependencies are loading correctly. But when instantiating the class in the test class, the dependencies are already loaded via composer.
I execute composer exec phpunit TestAutoloader
in the test below. How can I write a test so that the dependency does not load from composer?
Test code
class TestAutoloader extends TestCase
{
/**
* @test
*/
public function test_can_load_dependencies() {
$myClass = new MyClass();
$reflection = new \ReflectionClass($myClass->client());
echo $reflection->getFileName(); // This is loading from vendors folder instead of uploads/dependency
//$this->assertTrue(class_exists('GuzzleHttp\Client'));
}
}
The problem illustrated
/upload/MyClass.php
should load
/upload/dependencies/example/src/MyDependency.php
but the test is loading from
/vendor/example/src/MyDependency.php