我已经在php单元第一测试symfony上发布了这个问题我通过编写器安装了phpunit作为每个项目的安装。当尝试vendor/bin>phpunit -c ../../app
时,一切都很好,我得到了一个肯定的答案。而此命令给出tests目录中所有测试的答案。
但是我希望每个测试的结果都是单独的。当尝试/vendor/bin>phpunit -c ../../src/xxx/Bundle/tests/entity/yyy.php
时,我得到以下消息:could not load c:'wamp'www'symfony'src/xxx/Bundle/tests/entity/yyy.php Parse PI : PI php never end ... Start ttag expected, '<' not found
,当尝试/vendor/bin>phpunit -c ../../src/xxx/Bundle/tests/entity/yyy
和我得到以下消息:could not read "..'..'src/xxx/Bundle/tests/entity/yyy"
有没有人可以帮助我知道我应该如何写命令,从哪里执行它??有什么想法?
此处不要使用-c
选项。-c
选项是--configuration
的快捷方式,它指向PHPunit配置文件的目录(如app/phpunit.xml.dist
)。该配置告诉PHPunit在哪里寻找测试类和其他一些配置,如引导文件。
如果要为特定测试运行测试,可以执行phpunit path/to/tests/MyTest.php
。但是你会失去自动加载功能。要重新获得它,可以使用--bootstrap
选项指向引导文件。所以是phpunit --bootstrap vendor/autoload.php path/to/tests/MyTest.php
如果您想更频繁地运行这个命令,您可以更好地编辑app/phpunit.xml.dist
文件并创建一个新的套件:
<?xml version="1.0" encoding="utf-8" ?>
<phpunit ...>
<!-- ... -->
<testsuites>
<testsuite name="MyBundle">
<file>path/to/tests/MyTest.php</file>
</testsuite>
</testsuites>
<!-- ... -->
</phpunit>
然后输入:phpunit -c app --testsuite MyBundle
我也发生过,但事实上我们误读了文档,你在命令行中忘记了'app':
phpunit -c app src/AppBundle/Tests/Util/CalculatorTest.php
注意命令句中的app参数