测试时,如何在Laravel控制器方法中关闭dispatch()帮助器?

时间:2018-12-19 14:02:33

标签: php laravel unit-testing phpunit

在测试此控制器方法时遇到问题:

initPerson()

}

这是一种测试方法:

this.name$.next('hi');
this.name$.pipe(
  switchMap(query =>{
    return query;
  })
).subscribe(value => {
  console.log(value);
});

我应该如何使用dispatch()帮助程序关闭操作?

1 个答案:

答案 0 :(得分:0)

尝试这样

您的控制器

public function foo($check) {
    $data = [
        'content' => $content,
        'from' => date('Y-m-d H:i:s'),
        'to' => date('Y-m-d H:i:s'),
    ];
    $report = (new BlockedItemsReport($data))->onQueue('default');

    if($check){
       dispatch($report);  Подскажите, как?
    }
    return back();
}

您的测试方法

public function testFoo()
{
    $faker = Faker\Factory::create();
    $response = $this->call('POST', route('make.foo',[$check => false]), [
        'content' => $faker->text(200),
    ]);
    $response->assertRedirect('/');
}

我希望你平安:)

相关问题