How to put a task (sfBaseTask) in unitest?

How can I write unit test for my task (sfBaseTask)?

+6
symfony1
source share
1 answer

If you are asking how to write a unit test for a task, than you need to initialize the configuration first:

$configuration = ProjectConfiguration::hasActive() ? ProjectConfiguration::getActive() : new ProjectConfiguration(realpath($_test_dir . '/..')); 

Later, since tasks are just classes, you can easily initialize and test them:

 $task = new myTask($configuration->getEventDispatcher(), new sfFormatter()); $task->run($argumentsArray, $optionsArray); 

However, I believe that it is better to put the logic of the task in a separate class and use them in the execute () method of the task. It is even easier to verify this way.

+8
source share

All Articles