开发者

How put a Task (sfBaseTask) in unitest?

开发者 https://www.devze.com 2023-01-08 04:30 出处:网络
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:

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

精彩评论

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