user1593846
user1593846

Reputation: 756

Global variables in phpunit_Selenium2

I have an array with names I use to generate random names in a form and I want to use it in more then one function.

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');
}

This gives me the error "Undefined variable: firstNameArray" on the row where I declare the $name variabel. I dont want to have to have to declare the same array in every function I want to use it. so how do I solve this?

Upvotes: 0

Views: 71

Answers (1)

Mark Baker
Mark Baker

Reputation: 212412

It's not a global variable, it's a class/instance variable:

$this->byId('customer-name')->value($this->firstNameArray[$name].' '.$this->lastNameArray[$name]);
$this->byId('customer-email')->value($this->firstNameArray[$name].'.'.$this->lastNameArray[$name].'@testcomp.com');

EDIT

Sorry, I missed another reference:

$name = rand(0,count($this->firstNameArray)-1);

Upvotes: 1

Related Questions