Skip to content

Instantly share code, notes, and snippets.

@davidpeach
Last active October 29, 2020 13:59

Revisions

  1. davidpeach created this gist Oct 29, 2020.
    30 changes: 30 additions & 0 deletions ViewPostsTest.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    <?php

    namespace Tests\Feature;

    use App\Models\Post;
    use Illuminate\Database\Eloquent\Collection;
    use Illuminate\Database\Eloquent\Factories\HasFactory;
    use Illuminate\Foundation\Testing\RefreshDatabase;
    use Illuminate\Foundation\Testing\WithFaker;
    use Tests\TestCase;

    class ViewPostsTest extends TestCase
    {
    use HasFactory;
    use RefreshDatabase;

    /** @test */
    public function a_guest_can_view_the_blog_post_archive()
    {
    list($postA, $postB, $postC) = Post::factory()->count(3)->create();

    $response = $this->get('/posts');

    $response->assertViewHas('posts', new Collection([
    $postA->fresh(),
    $postB->fresh(),
    $postC->fresh(),
    ]));
    }
    }