Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在其他函数中调用在设置函数中创建的用户_Php_Unit Testing_Laravel 5_Phpunit_Laravel 5.1 - Fatal编程技术网

Php 如何在其他函数中调用在设置函数中创建的用户

Php 如何在其他函数中调用在设置函数中创建的用户,php,unit-testing,laravel-5,phpunit,laravel-5.1,Php,Unit Testing,Laravel 5,Phpunit,Laravel 5.1,这是我的完整代码,我写它来测试控制器的功能 <?php use Illuminate\Foundation\Testing\WithoutMiddleware; use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\Concerns\Makes

这是我的完整代码,我写它来测试控制器的功能

       <?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();
    }
}

如何修复此错误?

复制某人的库时,复制所有文件或以不需要的方式重写它
尝试引用另一个php中定义的属性
用户
。另外,给我们一部分代码可能没有帮助(最后一个花括号和行列表表示代码不完整)。我添加了完整的代码:)可以吗?
TestCase
类是否存在,
User
类是否存在于文件夹层次结构中它应该位于的位置?我不知道你想要什么,try$this->actingAs($this->User);
ErrorException: Undefined variable: user