【发布时间】:2014-10-31 06:15:42
【问题描述】:
我目前正在开发一个相当大的网络应用程序,它使用 Silex 作为后端。我在项目中添加了 PHPUnit 创建了一个简单的测试用例:
class IndexControllerText extends BaseControllerTest
{
public function testIndexPage()
{
$this->assertTrue(true);
}
}
我的BaseControllerTest 用于将应用程序创建为described in the docs:
<?php
namespace VendorName\AppName\Tests;
use Silex\WebTestCase;
use Symfony\Component\HttpKernel\HttpKernel;
abstract class BaseControllerTest extends WebTestCase
{
public function createApplication()
{
$app = require __DIR__ . '/../../../../app/bootstrap.php';
$app['debug'] = true;
$app['exception_handler']->disable();
return $app;
}
}
我的app/bootstrap.php 加载了 composer 自动加载器:
<?php
require_once __DIR__ . '/../vendor/autoload.php';
$app = new Silex\Application();
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/routing.php';
return $app;
最后在我的项目根目录中有我的phpunit.xml。见this gist。
不幸的是,当我运行 phpunit -c phpunit.xml 时,结果显示:
没有执行任何测试!
当我直接运行IndexControllerTest 时:
phpunit -c phpunit.xml src/VendorName/AppName/Tests/IndexControllerText.php
它运行测试并按预期返回成功。我很确定这是我的phpunit.xml 中的配置错误,但我似乎无法弄清楚。
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="YourApp Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
【问题讨论】:
-
您没有显示您怀疑错误所在的文件:
phpunit.xml。 -
它在我提供的链接中。这篇文章太长了。
-
我认为该文件的行数少于您的其他代码,并添加了在您链接的页面上找到的内容。请确认这是您正在使用的文件。
标签: php phpunit composer-php silex autoloader