1

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?

3
  • 1
    Have you tried running phpunit in that directory without specifying a file? That's what I do for non-Yii-based projects, and I cannot imagine it would be any different with Yii. Commented Oct 27, 2011 at 21:53
  • @David Harkness, Edited my question! Commented Oct 27, 2011 at 22:07
  • We wrote a blog post on how to run automated PHP unit testing with Yii. See: geeks.appbackr.com/61971101 Commented Nov 9, 2011 at 19:43

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

That was exactly my problem! Convention over configuration! Thanks @David !!
You can run it from root folder of your project, option -c protected\tests tells the config path. To run all unit tests, phpunit -c protected\tests protected\tests\unit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.