2015-10-17 105 views
0

环境

  • laravel 5.0.33
  • codeception 2.0.16

App/helpers.php laravel与codeception单元测试:使用的assertEquals时无法检查回波()

function sample($message) 
{ 
    echo $message; 
} 

tests/herpersTest.php

function testsample() 
{ 
    $this->assertEquals('○○○○',sample('test')); 
} 

我要检查的回声,但我不能检查回声和打印。
我知道只有退货支票。

我在做什么错?

+1

'echo'不会返回任何东西,所以你不能运行这样的测试。如果您想测试是否在页面上打印了某些内容,则可以使用Laravel提供的测试工具:http://laravel.com/docs/5.0/testing,或者您可以在代码中使用Laravel模块,该模块提供了一个“ '方法:http://codeception.com/docs/modules/Laravel5#see –

回答

0

您可以使用输出缓冲功能捕捉输出。

function testSample() 
{ 
    ob_start(); 
    sample('test'); 
    $output = ob_get_clean(); 
    $this->assertEquals('○○○○', $output); 
} 
+0

我做到了:)谢谢 – Kouya

相关问题