如何在 Laravel 单元测试期间获取视图数据
本文介绍了如何在 Laravel 单元测试期间获取视图数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查控制器函数中赋予视图的数组是否具有某些键值对.如何使用 phpunit 测试来做到这一点?
I would like to check the array given to a view in a controller function has certain key value pairs. How do I do this using phpunit testing?
推荐答案
我找到了更好的方法.我在 TestCase 中写了一个函数,它从视图数据中返回我想要的数组.
I found a better way to do it. I wrote a function in the TestCase which returns the array I want from the view data.
所以要从 $data 对象中获取值,我只需使用 $user = $this->getResponseData($response, 'user');
So to get a value from the $data object I simply use $user = $this->getResponseData($response, 'user');
这篇关于如何在 Laravel 单元测试期间获取视图数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!