Help us understand the problem. What is going on with this article?

【Laravel】Feature テストをする際に unique バリデーションの結果を Mock する

More than 1 year has passed since last update.

テストする際に次の記述を入れておくことで、DB アクセスを発生させずに unique バリデーションルールをパスすることができる。

$presenceVerifierMock = \Mockery::mock(\Illuminate\Validation\PresenceVerifierInterface::class);

3 行目を ->andReturn(1) に変えれば逆に unique バリデーションルールに引っかかるようになるはず(未確認)。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away