我有一个数组,其名称用于在表单中生成随机名称,我想在多个函数中使用它。
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');
}
这在我声明$ name variabel的行上给出了错误“Undefined variable:firstNameArray”。我不想在我想要使用它的每个函数中声明相同的数组。那么我该如何解决这个问题?
答案 0 :(得分:1)
它不是一个全局变量,它是一个类/实例变量:
$this->byId('customer-name')->value($this->firstNameArray[$name].' '.$this->lastNameArray[$name]);
$this->byId('customer-email')->value($this->firstNameArray[$name].'.'.$this->lastNameArray[$name].'@testcomp.com');
修改强>
对不起,我错过了另一个参考:
$name = rand(0,count($this->firstNameArray)-1);