我正在为我的班级写一个测试但是我收到了这个错误:
PHPUnit_Framework_MockObject_Builder_InvocationMocker Object (...) does not match expected type "array".
我的测试班:
<?php
namespace User\UserBundle\Tests\Dto\Template;
use User\UserBundle\Dto\Template\GenerateReportsTemplate;
use User\UserBundle\Doctrine\DatabaseRepository;
use User\UserBundle\Validation\ValidationClass;
class GenerateReportsTemplateTest extends \PHPUnit_Framework_TestCase
{
public static $reportData = array
(
'rowid' => '',
'emailaddress' => '',
'firstname' => '',
'surname' => '',
'contact_number' => '',
);
protected $object;
public $validate;
public $db;
protected function setUp()
{
$this->validate = $this->getMockBuilder('User\UserBundle\Validation\ValidationClass')
->disableOriginalConstructor()
->getMock();
$this->db = $this->getMockBuilder('User\UserBundle\UFODoctrine\DatabaseRepository')
->disableOriginalConstructor()
->getMock();
$this->object = $this->createGenerateReportsTemplateInstance();
}
public function createGenerateReportsTemplateInstance()
{
return new GenerateReportsTemplate
(
$this->validate,
$this->db
);
}
public function reportTestData()
{
}
public function testGenerateReports()
{
$data = array
(
'rowid' => '',
'emailaddress' => '',
'firstname' => '',
'surname' => '',
'contact_number' => '',
);
$report = $this->db->expects($this->any())
->method('getReportData')
->will($this->returnValue(self::$reportData));
$this->assertEquals($data, $report);
}
}
我想检查样本数据是否等于存根方法返回的数据getReportData
我相信存根返回对象,我想将它与数组进行比较,如果是这样的情况我怎么能断言这两个...?
聚苯乙烯。我正在使用Symfony2和Phpunit
答案 0 :(得分:8)
$this->assertEquals($data, $report);
你正在将数组与对象进行比较,实际上是;)
$this->assertEquals($data, $this->object->getReportData());
会做你想做的事