在Laravel 8中进行测试时,会话错误返回null

时间:2020-10-07 10:48:12

标签: phpunit php-7.4 laravel-8

为什么session('errors')为测试返回空值?

规则:

'number' => ['required', 'integer', 'min:1', 'max:66', new BookNumberExists($translation, $book)]

测试:

$this->actingAs($user)
  ->patch(route('books.update', ['translation' => $translation, 'book' => $book]), [
      'name' => $book->name,
      'abbr' => $book->abbr,
      'number' => 0
  ])
  ->assertSessionHasErrors([
      'number' => 'The number must be at least 1.'
  ]);

  // this returns null when I comment out the assert
  dd(session('errors');

0 个答案:

没有答案