I'm starting to wrap my head around PHPunit.
My questions is the following.
Whenever I use variables that do not change within my range of test methods I can initialize them within my setUp()
method. Otherwise, if they do change, I should rather put them directly in my test methods.
Is my assumption more or less right?
- I put the username into the
setUp()
method because it will not change. - The password comes directly into the functions because it needs to be changed in order to fail the test.
Example:
protected $username;
protected function setUp()
{
$this->username = "Bob";
}
public function testUserCanLogInSuccessfully()
{
$password = "Right_Password";
// code
}
public function testUserCanNotLogInSuccessfully()
{
$password = "Wrong_Password";
//code
}