phpunit :: Laravel redirect upon validation failure

Posted 3 months ago by DawgOnKing

Please consider the following:

public function store()
        $attributes = request()->validate([
            'name' => 'required',
            'title' => 'required',
        flash('POST CREATED!');
        return redirect('/posts');
//test validation for name requirement
        $this->actingAs($admin)->post('/posts', factory(Post::class)->raw(['name' => '']))
            ->assertSessionHasErrors(['name' => 'The name field is required.'])

The logic works in development but fails when testing:

1) Tests\Unit\PostTest::post_name_validations
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@

Any ideas?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.