How i can write an unit test, for my Task (sfBaseTask) ?
Asked
Active
Viewed 708 times
1 Answers
8
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.

j0k
- 22,600
- 28
- 79
- 90

Jakub Zalas
- 35,761
- 9
- 93
- 125