【发布时间】:2020-02-16 20:51:10
【问题描述】:
我正在尝试编写一个 phpunit 测试,以便我可以测试我得到了正确的断言,我目前拥有的这个测试正在通过并按预期工作。
/**
@test
*/
$filmInfo = $this->postRequest();
$this->assertFilm($this->requestData, $filmInfo['id']);
$film = Film::findOrFail($filmInfo['id']);
$this->assertEquals('LOTR', $filmInfo['name']);
$this->assertEquals('Film about a ring', $filmInfo['description']);
$this->assertEquals('Fantasy', $filmInfo['genre']['main']);
$this->assertEquals('Adventure', $filmInfo['genre']['sub']);
}
这是它所指的请求数据数组:
private function requestData(): array
{
return [
'name' => 'LOTR',
'description' => 'Film about a ring',
'main' => 'Fantasy',
'sub' => 'Adventure',
];
}
这个测试工作正常并且它通过了,但我想在一个断言中测试它,如下所示:
$this->assertEquals([
'name' => 'LOTR',
'description' => 'Film about a ring',
'genre' => [
'main' => 'Fantasy',
'sub' => 'Adventure'
]
,
], $filmInfo);
但我不断收到一个错误,即我断言的 2 个数组不匹配,你们知道是什么原因造成的吗?
【问题讨论】:
-
$filmInfo中是否有更多数据?你可以转储/发布它吗?