Это проблема. можно легко исправить с помощью специального метода утверждения, например:
Код: Выделить всё
protected function assertListWithoutOrderEquals(array $expected, array $actual): void
{
sort($expected);
sort($actual);
$this->assertEquals($expected, $actual);
}
Например, у меня есть этот тест в Laravel, и у меня проблема с утверждением значения жанров.:< /p>
Код: Выделить всё
use Illuminate\Testing\Fluent\AssertableJson;
public function test_http_response(): void
{
$expectedData = [
'id' => 1,
'name' => 'The fantastic book',
'genres' => ['science-fiction', 'drama', 'mystery'],
// other elements
];
$response = $this->get('url');
$response->assertJson(
fn(AssertableJson $json) => $json->where('id', $expectedData['id'])
->where('name', $expectedData['name'])
->where('genres', $expectedData['genres']) // This is order sensitive and makes tests to fail.
->etc()
);
}
Код: Выделить всё
->where('genres', fn($genres) => $genres->diff($expectedData['genres'])->isEmpty() && $genres->count() == count($expectedData['genres']))
Подробнее здесь: https://stackoverflow.com/questions/791 ... aravel-htt
Мобильная версия