I am writing a Test for my class but I am getting this error:
PHPUnit_Framework_MockObject_Builder_InvocationMocker Object (...) does not match expected type "array".
My Test Class:
<?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);
}
}
What I want to check if the sample data equals to the data returned by the stub method getReportData
I belief the stub returns object and i want to compare it against a array, if thats the case how can I Assert the two...?
Ps. I am using Symfony2 and Phpunit
$this->assertEquals($data, $report);
you are comparing an array to an object, actually ;)
$this->assertEquals($data, $this->object->getReportData());
will do what you want
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With