0

再会

我正在为一个项目使用 PHP Symfony 1.4.20 框架。我已经构建了启动 TASKS 的功能测试页面,以便在任务完成运行后从它生成的数据库中捕获数据,并监视此异步脚本行为的输出。问题是,当调用 TASK 时,它会输出所有 Doctrine 查询和 TASK 输出,在执行 test:all 时,即使测试用例都成功,也会产生可疑的输出。 我的问题:如何从我的功能测试脚本中抑制此输出?

这是任务调用的示例

chdir ( sfConfig::get ( 'sf_root_dir' ) ); // Trick plugin into thinking you are in a project directory
$task = new someTask ( $this->dispatcher, new sfFormatter () );
$task->run ( array (), array (
        'limit' => '1000',
        'env' => 'dev' 
) );

这是我希望抑制的输出示例

2013-08-29 20:34:56: TASK STARTED
>> Doctrine_Connection_Statement execute : SELECT m.id AS m__id, m.subscription_id AS m__subscription_id, m.object AS m__object, m.status AS m__status, m.retries AS m__retries, m.type AS m__type, m.created_at AS m__created_at, m.updated_at AS m__updated_at FROM message_queue m WHERE (m.status = ?) LIMIT 1000 - (1)
>> Doctrine_Connection_Statement execute : SELECT s.id AS s__id, s.mobile_id AS s__mobile_id, s.campaign_id AS s__campaign_id, s.status AS s__status, s.send_content_message AS s__send_content_message, s.last_sent_content_group_rel_id AS s__last_sent_content_group_rel_id, s.billed_total AS s__billed_total, s.billed_current_month AS s__billed_current_month, s.billed_count AS s__billed_count, s.created_at AS s__created_at, s.updated_at AS s__updated_at FROM subscription s WHERE (s.id = ?) - (188)
>> Doctrine_Connection_Statement execute : INSERT INTO log_tx (subscription_id, is_content_message, billing_rule_id, content_charge, toaddress, mobile_network_id, content, toc, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) - (188, 1, 4, 250, 27820000090, 2, Test for legal mobile, SMS, 2013-08-29 20:34:56, 2013-08-29 20:34:56)
>> Doctrine_Connection_Statement execute : UPDATE message_queue SET status = ?, updated_at = ? WHERE id = ? - (0, 2013-08-29 20:34:57, 694)
2013-08-29 20:34:57: SUCCESS: Message id [694] processed to [27820000090]
2013-08-29 20:34:57: TASK COMPLETED
>> Doctrine_Connection_Statement execute : SELECT MAX(l.id) AS l__0 FROM log_tx l WHERE (l.subscription_id = ? AND l.content_charge > 0) - (188)
>> Doctrine_Connection_Statement execute : SELECT l.id AS l__id, l.toaddress AS l__toaddress, l.subscription_id AS l__subscription_id, l.mobile_network_id AS l__mobile_network_id, l.toc AS l__toc, l.content AS l__content, l.content_charge AS l__content_charge, l.delivery_status AS l__delivery_status, l.sub_code AS l__sub_code, l.result_text AS l__result_text, l.is_content_message AS l__is_content_message, l.billing_rule_id AS l__billing_rule_id, l.created_at AS l__created_at, l.updated_at AS l__updated_at FROM log_tx l WHERE (l.id = ?) - (858)
ok 2 - LogTx Content Charge Matches

你会注意到ok 2 - LogTx Content Charge Matches这是一个通过的测试用例

我已经搜索过这个答案,但似乎以前没有人遇到过这个问题,所以任何帮助都将不胜感激。也许我做错了?

提前致谢...

4

1 回答 1

0

我假设您正在任务之外进行实际断言,在这种情况下,我认为最简单的方法就是打开一个新的输出缓冲区,然后刷新它而不打印,例如:

ob_start();
$task->run ( array (), array (
        'limit' => '1000',
        'env' => 'dev' 
) );
ob_end_clean();

任何到标准输出的输出都将被输出缓冲区捕获并在ob_end_clean不打印后丢弃。

于 2013-08-29T23:06:13.720 回答