我有一个正常的目录结构:
- root
- vendor
- bin/phpunit
- tests
- bootstrap.php
my composer.json:
{
"name": "test/testing",
"minimum-stability": "dev",
"require": {
"phpunit/phpunit": "4.1.*@dev",
"phpunit/phpunit-mock-objects": "2.2.*@dev"
},
"autoload": {
"classmap": ["tests/config.inc","test.inc"]
}
}
我的bootstrap.php:
<?php
require_once 'vendor/autoload.php';
引导程序中还有其他一些东西,这就是我需要它的原因, 但是我把它删除了,因为它与我的问题无关。
当我尝试在根文件夹中运行PHPUnit时:
vendor/bin/phpunit --bootstrap tests/bootstrap.php tests/ItemsTest.php
我收到错误:
PHP Warning: require(xxxx/vendor/phpunit/phpunit-mock-objects/tests/../vendor/autoload.php): failed to open stream: No such file or directory in xxxxxxx/vendor/phpunit/phpunit-mock-objects/tests/bootstrap.php on line 4
我不知道为什么phpunit / autoloader正在加载这个bootstrap:
phpunit-mock-objects/tests/bootstrap.php
当然还有第4行:
require __DIR__ . '/../vendor/autoload.php';
不起作用。
答案 0 :(得分:2)
无论出于何种原因,PhpUnit都不会将引导路径理解为相对路径。
如下所示更换引导路径似乎可以解决问题:
vendor/bin/phpunit --bootstrap ./tests/bootstrap.php tests/ItemsTest.php