Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 编写功能测试,检查是否使用正确的参数分派了Laravel作业?_Php_Laravel_Unit Testing_Phpunit_Functional Testing - Fatal编程技术网

Php 编写功能测试,检查是否使用正确的参数分派了Laravel作业?

Php 编写功能测试,检查是否使用正确的参数分派了Laravel作业?,php,laravel,unit-testing,phpunit,functional-testing,Php,Laravel,Unit Testing,Phpunit,Functional Testing,我正在尝试编写一个功能测试,以检查RESTAPI的一个方法是否正确地分派了一个作业 我知道Laravel包括expectsJobs方法。但这只会检查作业是否已分派我还需要检查实例化时使用的参数是否正确。 这样,我就可以依靠这个功能测试+另一个单元测试来检查当使用正确的参数实例化时作业本身是否运行良好。否则,我只知道: RESTAPI调用分派作业 当使用正确的参数实例化作业时,该作业工作正常 但我不知道RESTAPI调用是否使用正确的参数实例化了作业 为了清楚起见,这里有一些伪代码: REST

我正在尝试编写一个功能测试,以检查RESTAPI的一个方法是否正确地分派了一个作业

我知道Laravel包括expectsJobs方法。但这只会检查作业是否已分派我还需要检查实例化时使用的参数是否正确。

这样,我就可以依靠这个功能测试+另一个单元测试来检查当使用正确的参数实例化时作业本身是否运行良好。否则,我只知道:

  • RESTAPI调用分派作业
  • 当使用正确的参数实例化作业时,该作业工作正常
但我不知道RESTAPI调用是否使用正确的参数实例化了作业

为了清楚起见,这里有一些伪代码:

REST api调用的功能测试:

    $this->expectsJobs(\App\Jobs\UpdatePricesJob);
    $this->json("POST", "/api/resource/{$someresource->id}", [
        "update_prices" => 1,
        "prices" => [
          /** the prices list **/
        ]
    ])->seeJson(["success" => true]);
    /** The test succeeds if an UpdatePricesJob is dispatched **/
    $someresource = Resource::find($someResourceId);
    $newPrices = [ /** properly-formatted prices **/ ]
    $this->dispatch(new UpdatePricesJob($someresource, $newPrices));
    $this->assertEquals($someresource->prices, $newPrices);
    /** The test succeeds if running UpdatePricesJob properly updates the resource prices to the ones specified in the job params **/
更新许可证作业的单元测试:

    $this->expectsJobs(\App\Jobs\UpdatePricesJob);
    $this->json("POST", "/api/resource/{$someresource->id}", [
        "update_prices" => 1,
        "prices" => [
          /** the prices list **/
        ]
    ])->seeJson(["success" => true]);
    /** The test succeeds if an UpdatePricesJob is dispatched **/
    $someresource = Resource::find($someResourceId);
    $newPrices = [ /** properly-formatted prices **/ ]
    $this->dispatch(new UpdatePricesJob($someresource, $newPrices));
    $this->assertEquals($someresource->prices, $newPrices);
    /** The test succeeds if running UpdatePricesJob properly updates the resource prices to the ones specified in the job params **/
如您所见,无法知道REST api调用是否使用一些格式正确的价格实例化了UpdatePricesJob

提前谢谢