Code snippets for symfony 1.x


Refine Tags

Snippets tagged "tests"

Selecting test groups from cli

I find boring to wait to run all the tests while I'm focusing on a single one or few ones. Thus I decided to hack pake simpletest task to accept test group selection.

1st step:

In your Pake tasks folder (eg.: /usr/share/pear/pake/tasks) edit the pakeSimpletestTask.class.php file

public static function call_simpletest($task, $type = 'text', $dirs = array(), $test_file = null)

and add this few lines replacing the single line 48

if (!$test_file) {
    $files = pakeFinder::type('file')->name('*Test.php')->in($test_dirs);
else {
    $files = pakeFinder::type('file')->name($test_file)->in($test_dirs);

This way you are making your pake test task able to accept "hints" about which file to load in the test folder.

2nd step:

Open the sfPakeTest.php file in your symfony/tasks folder and do the following: Add

$test_file = null;
if (count($args) > 1)
    $test_file = $args[1];

at line 14, then change last line into

pakeSimpletestTask::call_simpletest($task, 'text', $dirs_to_test, $test_file);

That's all.

Now you can launch symfony test <app_name> <test_filename> and have this only executed with no loss of time. You can even use wildcards!!! For example: symfont test myportal *ValidatorTest.php It will execute all the tests named with that pattern in your test/myportal folder.

Super confortable testing at last! Test driven programming requires very flexible test groups approach and this could be a small contribution. Hope it helps. Bye!

by Jacopo Romei on 2006-07-10, tagged cli  pake  test  tests