Expression not allowed in variable outside function

I want to associate the directory with the string $ screenshotPath, but an error appears in PHPStorm: the expression is not allowed as the default value for the field. How can i fix this? The code:

use PHPUnit\Extensions\SeleniumTestCase;
use ApplicationTest\Bootstrap;

class AdminLoginLogoutTest extends PHPUnit_Extensions_SeleniumTestCase {
    protected $captureScreenshotOnFailure = true;
    //$screenshotPath is giving me this error...
    protected $screenshotPath = __DIR__ . "/FailedTestsScreenshots";
    protected $screenshotUrl = "http://icho/screenshots";

    protected $path = "http://icho";

    protected function SetUp() {
        $this->setBrowser( "*firefox" );
        $this->SetBrowserUrl( $this->path );
    }

    public function testAdminLoginLogout() {
        $this->open( "/admin" );
        $this->type( "name=username", "test" );
        $this->type( "name=password", "test" );
        $this->click( "id=submitbutton" );
        $this->waitForPageToLoad( "30000" );
        $this->assertEquals( "Dashboard", $this->getText( "link=Dashboard" ) );
        $this->assertEquals( "Haios", $this->getText( "link=Haios" ) );
        $this->assertEquals( "POs", $this->getText( "link=POs" ) );
        $this->assertEquals( "Staco's", $this->getText( "link=Staco's" ) );
        $this->assertEquals( "Mail templates", $this->getText( "link=Mail templates" ) );
        $this->assertEquals( "Mailings", $this->getText( "link=Mailings" ) );
        $this->assertEquals( "Sytem texts", $this->getText( "link=System texts" ) );
        $this->assertEquals( "Advanced admin", $this->getText( "link=Advanced admin" ) );
        $this->click( "css=a[title='Sign Out']" );
        $this->click( "id=bot2-Msg1" );
        $this->waitForPageToLoad( "30000" );
        $this->assertEquals( "Login is vereist", $this->getText( "css=h2" ) );
    }
}
+4
source share
1 answer

Move it to the constructor (or any other function) - you don't seem to have a constructor for the class, but it __constructwill be called anyway:

protected $screenshotPath = '';

public function __construct() {
    $this->$screenshotPath = __DIR__ . "/FailedTestsScreenshots";
}

or in SetUp():

protected function SetUp() {
    $this->$screenshotPath = __DIR__ . "/FailedTestsScreenshots";
    $this->setBrowser( "*firefox" );
    $this->SetBrowserUrl( $this->path );
}
+4
source

All Articles