开发者

How put a Task (sfBaseTask) in unitest?

How i can write开发者_如何学C an unit test, for my Task (sfBaseTask) ?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜