Call to undefined method Tests\Feature\LocationsTest::post() Hi,
Trying following https://laracasts.com/series/build-a-laravel-app-with-tdd which is based Laravel 5.x
and I'm having error (I'm sure this is because things are done in a different now) :
• Tests\Feature\LocationsTest > a user can create a location
PHPUnit\Framework\ExceptionWrapper
Call to undefined method Tests\Feature\LocationsTest::post()
at tests/Feature/LocationsTest.php:21
17▕ 'name' => $this->faker->sentence,
18▕ 'description' => $this->faker->paragraph
19▕ ];
20▕
➜ 21▕ $this->post('/locations', $attributes);
22▕
23▕ $this->assertDatabaseHas('locations', $attributes);
24▕ }
25▕
Test itself:
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\WithFaker;
use PHPUnit\Framework\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
class LocationsTest extends TestCase
{
use WithFaker, RefreshDatabase;
/** @test */
public function a_user_can_create_a_location()
{
$attributes = [
'name' => $this->faker->sentence,
'description' => $this->faker->paragraph
];
$this->post('/locations', $attributes);
$this->assertDatabaseHas('locations', $attributes);
}
}
I'm confused, where to refer in this case...
Here https://laravel.com/docs/9.x/http-tests
or here https://laravel.com/docs/9.x/dusk ?
You need to extend laravels test case
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase; //this
use Illuminate\Foundation\Testing\RefreshDatabase;
class LocationsTest extends TestCase
For me it shows in pest test. Call to undefined method Tests\Unit\urlTest::get()
test('the application returns a successful response', function () {
$response = $this->get('/');
$response->assertStatus(200);
});
Please sign in or create an account to participate in this conversation.