我正在使用Symfony 2并尝试让PHPunit使用它,所以我已经将它添加到我的composer.json下的required-dev:
"phpunit/phpunit": "4.6.*"
在我的终端中运行此命令:
composer update --dev
执行上述PHPUnit后,出现在vendor
目录下。
根据docs Symfony 2预配置了PHPUnit,可以通过以下方式执行:phpunit -c app/
但它永远不会奏效,我的终端信息是:
Unknown command “phpunit”
The program 'phpunit' is currently not installed. You can install it by typing:
sudo apt-get install phpunit
即使这个./bin/phpunit -c app
似乎触发了phpunit,无论我写什么测试,我总是得到这个:
Configuration read from /home/tomazi/Dev/api.test/app/phpunit.xml.dist
Time: 66 ms, Memory: 4.25Mb
No tests executed!
我的测试:
<?php
namespace BoltMail\User\InteractionBundle\Tests\Dto\Template;
class TestTemplateTest extends \PHPUnit_Framework_TestCase
{
public function testIndex()
{
$this->assertTrue(true);
}
}
答案 0 :(得分:3)
当你从composer安装phpunit时,你应该从项目目录中运行它
$./bin/phpunit -c app
或者如果您希望全局运行:
对于通过Composer进行的系统范围安装,您可以运行:
composer global require&#34; phpunit / phpunit = 3.7。*&#34;确保你有 你路径中的〜/ .composer / vendor / bin /。
更新您的问题:
我想你已经通过指定测试目标解决了空测试的问题。第二种方法是在app / phpunit.xml指定目标
<?xml version="1.0" encoding="UTF-8"?>
<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit
backupGlobals = "false"
backupStaticAttributes = "false"
colors = "true"
convertErrorsToExceptions = "true"
convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true"
processIsolation = "false"
stopOnFailure = "false"
syntaxCheck = "false"
verbose = "true"
bootstrap = "bootstrap.php.cache" >
<!-- more settings here -->
<testsuites>
<testsuite name="My Test Suite">
<directory>../src/*/*Bundle/Tests</directory>
<directory>../src/*/Bundle/*Bundle/Tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>../src</directory>
<exclude>
<directory>../src/*/*Bundle/Resources</directory>
<directory>../src/*/*Bundle/Tests</directory>
<directory>../src/*/Bundle/*Bundle/Resources</directory>
<directory>../src/*/Bundle/*Bundle/Tests</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
答案 1 :(得分:1)
您必须在phpunit配置文件phpunit.xml.dist中指定目录,或者运行带有特定目录或文件的命令
./bin/phpunit -c app/ path/to/your/test/folder