我在 PHPUnit 中模拟对象时遇到问题:
class FootballTest extends PHPUnit_Framework_TestCase
{
/**
* @var Football
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->siteName = 'football';
$this->footballAPIMock = $this->getMock('FootballAPI');
$this->object = new Football($this->siteName,$this->footballAPIMock);
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
$this->object = null;
}
public function testGetByTeamOutrights()
{
$markets = 5;
$this->footballAPIMock->expects($this->any())
->method('getByTeamOutrights')
->with($this->equalTo(5))
->will($this->returnValue(5));
$this->assertNull($this->object->getByTeamOutrights(5));
}
}
而且我断言那个足球对象失败了
PHPUnit 版本 3.6.12