我有一个应用程序,客户需要该应用程序来存储用户的信用卡详细信息.
我应该在哪里存放?
我想测试它具有的一个控制器:
$deviceGet = strtolower($request->query->get('device'));
我的问题是:如何模拟它以在我的控制器中进行测试?
class SetDeviceListenerTest extends \PHPUnit_Framework_TestCase {
/**
* @test
* @dataProvider deviceGetCases
*/
public function shouldSetRequestDeviceWithDeviceGetOnMasterRequest(
?string $device
): void {
$request = $this->getRequestMock();
$request->expects($this->once())
->method('get')
->with('device')
->willReturn($device);
/* @var Request $request */
$request->server = new ServerBag();
$request->headers = new HeaderBag();
$event = $this->getEventMock();
$event->expects($this->once())
->method('isMasterRequest')
->willReturn(true);
Run Code Online (Sandbox Code Playgroud)
它返回错误,因为
$request->expects($this->once())
->method('get')
->with('device')
->willReturn($device);
Run Code Online (Sandbox Code Playgroud)
失败
谢谢你!!