mercredi 27 juillet 2022

Could not load mock: class already exists when run with RefreshDatabase Trait

public function testSomething()
{
    $this->login();

    m::mock('overload:MyClass', function ($mock) {
        $mock->shouldReceive('METHOD')
            ->andReturn(
                (object)[
                    'status'  => true,
                    'message' => 'Message',
                ]
            );
    });

    $this->post(route('ROUTE'))
        ->assertRedirect()
        ->assertSessionHas(
            'success',
            'Message'
        );
}

When I try to run this with:

use DatabaseTrasactions: It works

use RefreshDatabase: It does NOT work

Error: Mockery\Exception\RuntimeException : Could not load mock \MyClass, class already exists

Laravel: 5.5 PHPUnit: 6.5.14

Tried

  • @runTestsInSeparateProcesses (on entire class)
  • @runInSeparateProcess (on single test)


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire