4 months ago

PHPUnit returning 404 after first GET request

Posted 4 months ago by pedroroccon


I'm getting an error 404 in my PHPUnit Tests. After doing my first GET Request, every next requests returns a 404 error. To make easier to understand, I made 2 methods with exactly same tests.

The first test returns me success, but the second fails with 404 error. If I try to run the second test alone, it returns me success!

Someone knows how to fix that? Thanks :)

My test class:


namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\Sys\Organizacao;

class OrganizacaoCrudTest extends TestCase
    use RefreshDatabase;

    protected $organizacao;

    protected $user;

    public function setUp() : void
        $this->organizacao = factory(Organizacao::class)->create();
        $this->user = factory('App\User')->create();

    /** @test */
    public function has_index()
         // Returns success.

    /** @test */
    public function has_create_form()
         // Running this test alone, returns success, but when I run the entire class, this method fails (404 error)

My PHPUnit Return

phpunit --filter=OrganizacaoCrudTest

PHPUnit 7.5.13 by Sebastian Bergmann and contributors.

.F                                                                  2 / 2 (100%)

Time: 547 ms, Memory: 22.00 MB

There was 1 failure:

1) Tests\Feature\OrganizacaoCrudTest::has_create_form
Expected status code 200 but received 404.
Failed asserting that false is true.


Tests: 2, Assertions: 2, Failures: 1.

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