helloRoman5556
helloRoman5556

Reputation: 173

Error: Call to undefined method Tests\Unit\SomeTest::assertStatus()

I wrote the test:

$response = $this->get('/something');
$response->assertStatus(200);

It displays this error:

Error: Call to undefined method Tests\Unit\SomeTest::assertStatus()

I found how I can fix my problem (code is below) but I want to use first method:

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

  $this->assertEquals(200, $this->response->status());

Why doesn't the first code work?

Upvotes: 14

Views: 9951

Answers (3)

mrhn
mrhn

Reputation: 18926

Instead of using the TestCase class PHPUnit\Framework\TestCase you should use Tests\TestCase. The following snippet should work.

use Tests\TestCase;

class ControllerTest extends TestCase

Upvotes: 10

Julker Nien Akib
Julker Nien Akib

Reputation: 65

Use this following code:

namespace Tests\Unit;
use Tests\TestCase;

class SampleTest extends TestCase{

  //your code

}

Upvotes: 1

Amirhossein Shahbazi
Amirhossein Shahbazi

Reputation: 1111

I solved it by changing use PHPUnit\Framework\TestCase to use Tests\TestCase.

Upvotes: 20

Related Questions