Phpunit testcase中的传递路由参数器
我正在编写一个测试用例,在这个测试用例中,当我们通过路由时,我必须发送参数。这是我的控制器Phpunit testcase中的传递路由参数器,phpunit,laravel-5,testcase,Phpunit,Laravel 5,Testcase,我正在编写一个测试用例,在这个测试用例中,当我们通过路由时,我必须发送参数。这是我的控制器 class TestingControll extends Controller { public function addTestUsingParameters(Response $response) { $firstNum = $response->firstNum ; $secondNum = $response->
class TestingControll extends Controller {
public function addTestUsingParameters(Response $response)
{
$firstNum = $response->firstNum ;
$secondNum = $response->secondNum ;
$sumOfNumbers = $firstNum + $secondNum;
return $sumOfNumbers;
}
}
这是我的路线
Route::get('test/cal/{firstNum}/{secondNum}', array('as' => 'testCal', 'uses' => 'TestingControll@addTestUsingParameters'));
这是我的测试用例代码
我已经阅读了文档,但我不知道该怎么做。?
有人知道这个问题吗?当您在浏览器中尝试时,路由/控制器是否工作?您提供的代码的输出/错误是什么?为什么在addTestUsingParameters中注入响应?assertEquals应该检查8,而不是10:@DanielAntos感谢您指出响应参数,这是我的输入错误,我应该传递请求参数。
class CalculatorTest extends TestCase {
public function testCanAddNumbers()
{
$calcu = $this->action('GET','TestingControll@addTestUsingParameters',['firstNum'=>4,'secondNum'=>4]);
$this->assertEquals(10,$calcu->getContent());
}
}