4

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

1 Answer 1

12
$this->assertEquals($data, $report);

you are comparing an array to an object, actually ;)

$this->assertEquals($data, $this->object->getReportData());

will do what you want

Sign up to request clarification or add additional context in comments.

2 Comments

Ye sorry array to object :P either way just tried your solution and I get Call to undefined method PHPUnit_Framework_MockObject_Builder_InvocationMocker::getReportData()
Try changing the assertion to: $this->assertEquals($data, $this->object->{YOUR_METHOD_HERE}());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.