gpt4 book ai didi

Phpunit 断言两个数组是否相等

转载 作者:行者123 更新时间:2023-12-04 16:21:11 25 4
gpt4 key购买 nike

我正在为我的类(class)编写测试,但出现此错误:

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);

}

}

我想检查样本数据是否等于 stub 方法 getReportData 返回的数据

我相信 stub 返回对象,我想将它与数组进行比较,如果是这样,我如何断言这两个......?

附言。我正在使用 Symfony2 和 Phpunit

最佳答案

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

实际上,您正在将数组与对象进行比较;)
$this->assertEquals($data, $this->object->getReportData());

会做你想做的

关于Phpunit 断言两个数组是否相等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36083740/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com