0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

備忘録:Laravel 配列の中身をテストする

Last updated at Posted at 2025-11-03

Laravel 配列の中身をテストする際のメソッドについて

今回利用するテストコード

class LaravaelTest extends TestCase
{
    /**
     * 配列の中身をテストする
     * @test
     * @dataProvider test2Data
     * @param array $testCase
     * @return void
     */
    public function test2(array $expect): void
    {
        $actual = ['1', '2', '3', '4', '5'];

        /** 検証1 assertEquals */
        $this->assertEquals($expect, $actual);
        
        /** 検証2 assertEqualsCanonicalizing */
        $this->assertEqualsCanonicalizing($expect, $actual);
    }

    public static function test2Data(): array
    {
        return [
            'ケース1/同値/順番も同じ' => [
                ['1', '2', '3', '4', '5']
            ],
            'ケース2/同値/順不同' => [
                ['4', '3', '2', '1', '5']
            ],
        ];
    }
}

検証結果

■ 検証1 assertEquals
image.png

■ 検証2 assertEqualsCanonicalizing
image.png

配列の中身が意図する値であるかをテストしたい場合は assertEqualsCanonicalizing() を利用する

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?