这是我的完整代码,我将其写入控制器的测试功能
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\Concerns\MakesHttpRequests;
class RouteForecastTest extends TestCase
{
protected $password = 'rightpassword';
public function setUp()
{
parent::setUp();
$this->createApplication();
$this->user = factory(App\User::class)->create([
'email' => 'testuser@email.com',
'password' => bcrypt($this->password),
'type' => 'admin'
]);
}
/** @test */
public function createTest()
{
$this->actingAs($user);
$this->visit('/client/ocp/profile/247')
->click('New ')
->seePageIs('/client/ocp/profile/247/create')
->see('name');
}
public function tearDown(){
parent::tearDown();
$this->user->delete();
}
}
我尝试使用setup和teardown方法编写此代码并使用phpunit运行测试我收到此错误
ErrorException: Undefined variable: user
我该如何解决此错误?