I'm writing tests against the following class:
abstract class EmailMessageRecipient
{
private $_address = null;
public function setAddress($address)
{
$this->_address = $address;
return $this;
}
public function getAddress()
{
return $this->_address;
}
}
The test looks like this:
class EmailMessageRecipientTest extends PHPUnit_Framework_TestCase
{
private $_test_object;
protected function makeTestObject()
{
return $this->createMock(EmailMessageRecipient::class);
}
public function setUp()
{
$this->_test_object = $this->makeTestObject();
}
public function testAddress()
{
$this->_test_object->setAddress('blah@example.com');
$this->assertEquals('blah@example.com', $this->_test_object->getAddress());
}
}
PHPUnit fails the test with the message Failed asserting that null matches expected 'blah@example.com'.
. So $this->_test_object->getAddress()
is returning null
instead of the email address that was passed to it. Why is this happening and how do I adjust the test so that it passes.
Mocking the setAddress()
and getAddress()
methods is not an acceptable answer. The purpose of this test is to cover setAddress()
and getAddress()
.