You should be testing your applications. End of story. This post outlines a task I created that makes testing your application easier. This test is great if you fall into one of the following categories:
  1. You want to run a group of test files you've organized into a directory.
  2. You want to run a group of test files based on a word or words they have in common
  3. You want one command line task for all the tests you run, rather than having to type unit or functional and the application every time. Shouldn't the task be smart enough to run individual files?
These reasons are why I wrote sfTestFileTask.class.php. I have pompously given this task the alias "test" so you can run it like this:
# runs all tests in your test suite
$ php symfony test
To run a group of test files you've organized into a directory:
# runs all tests in the directory /path/to/project/test/functional/backend/export
$ php symfony test export
To run a group of test files based on a word or words they have in common:
# runs all tests starting with "User"
$ php symfony test User*
# runs all tests containing the word "content"
$ php symfony test *content*
To run any test file:
# runs the test found in test/functional/backend/export/OrganizationExportTest.php
$ php symfony test OrganizationExport
# task is smart enough to ignore requests ending in "Test"
$ php symfony test OrganizationExportTest
# runs test in "verbose" mode, in order to view errors
$ php symfony test OrganizationExport -v
All these tests run as you see when using the test:all command. Providing the -v command runs all tests as if they are ran individually with test:functional or test:unit. Place the code in lib/task/sfTestFileTask.class.php and you'll be all set! Please let me know if you have any ideas for improvement.

1 comment

  • Kuba - August 10, 2010

    That’s a great idea!

    I find running tests selectively very useful. Your task can be used to run tests for part of application which is currently developed. Of course naming convention and proper organization is needed (which is anyway recommended).

    Time saver! Thanks 🙂