1
1

More than 3 years have passed since last update.

phpUnitで配列の値を順不同で比較したい時

Last updated at Posted at 2020-08-17

assertSameだと順不同で比較してくれない。
そういう時はassertEqualsCanonicalizingを使えば解決。
phpUnit7.5以降のversionで使用することができます。

使用例
//成功例。配列を順不同で比較してくれる。
$this->assertEqualsCanonicalizing([1,2,3,4],[4,1,3,2]);

//失敗例。他の関数と同じく第3引数でコメントしてくれる
$this->assertEqualsCanonicalizing([1,2,3,4],[4,1,3,3],"失敗しました");

参考:https://www.geeksforgeeks.org/phpunit-assertequalscanonicalizing-function/

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1