【发布时间】:2016-11-20 11:09:45
【问题描述】:
我已经启动并运行了一个小型 Web 应用程序,其中包括 phpunit 测试。它是用 composer 构建的,并且有一个非常标准的目录结构:
src/
application files
tests/
bootstrap.php
test files
web/
index.php
.travis.yml
composer.json
composer.lock
phpunit.xml
phpunit.xml 内容:
<?xml version="1.0" encoding="UTF-8" ?>
<phpunit boostrap="./tests/bootstrap.php">
<testsuites>
<testsuite name="Chronos">
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
bootstrap.php 内容:
<?php
require __DIR__ . "/../vendor/autoload.php";
我的问题
运行以下命令完美运行,我的测试通过:
$ vendor/bin/phpunit
PHPUnit 4.8.26 by Sebastian Bergmann and contributors.
..
Time: 104 ms, Memory: 4.00MB
OK (2 tests, 2 assertions)
但是,当我运行全局安装的 phpunit 版本时,它会失败:
$ phpunit
PHPUnit 4.8.26 by Sebastian Bergmann and contributors.
EE
Time: 117 ms, Memory: 4.00MB
There were 2 errors:
1) WelcomeTest::testReturnsAPayload
Error: Class 'Equip\Payload' not found
/Users/tony/Documents/projects/chronos/tests/Domain/WelcomeTest.php:13
2) WelcomeTest::testReturnsOkStatus
Error: Class 'Equip\Payload' not found
/Users/tony/Documents/projects/chronos/tests/Domain/WelcomeTest.php:13
FAILURES!
Tests: 2, Assertions: 0, Errors: 2.
在我的项目根目录中运行 phpunit 的全局安装似乎不包括/解析我的 phpunit.xml 文件(它指定了自动加载器)。我在 TravisCI 上得到了相同的结果。
有人知道为什么会这样吗?我可以在我的 .travis.yml 文件中指定本地版本的 phpunit,但我更想知道是什么导致了这里的差异。
【问题讨论】:
-
你应该发布整个错误信息
-
更新为包含输出
-
请贴出phpunit.xml的相关部分。引导文件可能存在与路径相关的问题。也发布引导文件(或命令)。
-
更新为包含 phpunit.xml 和 bootstrap 文件
-
感谢@MichaelBerkowski,你让我意识到我在 phpunit.xml 中有错字
标签: php xml phpunit composer-php travis-ci