简体   繁体   中英

Laravel Dusk Testing: Class property doesn't reflect the updated value in the next 'test' function

Testing class having a variable $uid is defined. It is then modified in the function testCreateNewUser. But when I try to use the variable in the function testRetrieveUser, it still holds the value with which it was declared. Why is the new value of variable $uid not reflected in the next test function?

class Testing extends DuskTestCase{

protected $uid = 'seed';

public function testCreateNewUser()
{
    $this->browse(function (Browser $browser) use ($user) {
        $browser->visit('/')
                ->assertSee('Laravel');
    });

    $this->uid = 'my new value';  //value assigned to $this->uid

    logger($this->uid);    //this logs correctly 'my new value'
}

public function testRetrieveUser()
{
    $uid = $this->uid;
    logger($uid);        //when logged, it shows 'seed'
}
}

Dusk/PHPUnit creates a new Testing instance for every test.

You have to use static properties:

protected static $uid = 'seed';

static::$uid = 'my new value';

$uid = static::$uid;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM