Running PHPUnit tests Yii Framework

放肆的年华 提交于 2019-12-24 12:13:29

问题


What possibilities are there to run unit tests with my Yii application?

So far, I have been testing them this way:

Open command prompt

> cd C:\WHEREVER MY APP IS\protected\tests

> phpunit unit/TestingTest.php

Now, I was wondering if there is another way. Im new to the testing world so to speak, but it seems to me that there must be a better way than running one by one all tests. Thanks for any tips, im sure the question is quite dumb! But maybe it turns out to be helpful to someone else out there.

EDIT (based on @David Harkness comment) Ok, so now I know that when i do this

phpunit C:\WHEREVER MY APP IS\protected\tests\unit

All the tests within my TestingTest.php file are execute. My problem now is that within that unit folder, I have TWO files, TestingTest.php and TestingTest2.php Testing2Test.php. Only the tests within the first one are executed. Any ideas?


回答1:


PHPUnit by default will scan for all files named <foo>Test.php. That means that TestingTest2.php will be ignored. You can either rename the file to Testing2Test.php, use

phpunit C:\WHEREVER MY APP IS\protected\tests\unit\*.php

to locate the files (not sure this works though), or create a phpunit.xml configuration file that specifies the filename pattern that must match your tests. However, just rename it so all the files end in Test.php and you'll be much happier.

I generally always cd into the root test directory--the one that contains bootstrap.php and phpunit.xml. That way I don't have to tell PHPUnit how to find those files since it always looks in the current directory.



来源:https://stackoverflow.com/questions/7922766/running-phpunit-tests-yii-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!