Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How put a Task (sfBaseTask) in unitest?

How i can write an unit test, for my Task (sfBaseTask) ?

like image 404
bux Avatar asked Jul 22 '10 13:07

bux


1 Answers

If you're asking how to write a unit test for a task than firstly you need to initialize configuration:

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

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

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

However, I think it's better to put task logic into separate class(es) and use them in task's execute() method. It's even easier to test this way.

like image 74
Jakub Zalas Avatar answered Sep 16 '22 18:09

Jakub Zalas