我有一個名稱用於在表單中生成隨機名的數組,我想在多個函數中使用它。phpunit_Selenium2中的全局變量
class TestMyTest extends PHPUnit_Extensions_Selenium2TestCase {
public function setUp()
{
$this->setHost('localhost');
$this->setPort(4444);
$this->setBrowser("firefox");
$this->setBrowserUrl("xxxxxxxxxxxxxxxxxx");
}
public $firstNameArray = array(
"Howard",
"Sheldon",
"Leonard",
"Rajesh"
);
public $lastNameArray = array(
"Wolowitz",
"Cooper",
"Hofstadter",
"Koothrappali"
);
public function testCreateNewCustomer()
{
$name = rand(0,count($firstNameArray));
$this->byId('customer-name')->value($firstNameArray[$name].' '.$lastNameArray[$name]);
$random_phone_nr = rand(1000000,9999999);
$this->byId('customer-phone')->value('070'.$random_phone_nr);
$this->byId('customer-email')->value($firstNameArray[$name].'.'.$lastNameArray[$name].'@testcomp.com');
}
這給我錯誤「Undefined variable:firstNameArray」在我聲明$ name的變量的行上。我不希望必須在每個我想使用它的函數中聲明相同的數組。那麼我該如何解決這個問題?
要使用爲什麼這個數據通過一個類變量?我認爲你應該考慮使用Dataprovider(http://phpunit.de/manual/3.7/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.data-providers)或簡單地把這個日期在你的測試方法中。 – nonsenz