首页 > 解决方案 > 对于每个带有 laravel 测试 api 的

问题描述

这是我的测试 WP 方法

public function testGetWP()
    {
        $this->actingAs($this->user, 'api');
        $response = $this->get('/api/w-parm', ['Content-Type' => 'application/x-www-form-urlencoded'
        ])->assertStatus(200);

        $w_parms = WParm::get();


        foreach ($w_parms as $w_parm) {

            $response->assertJson([
                "data" => [
                    [
                        "id" => $w_parameter->id,
                        "name_en" => $w_parameter->name_en,
                ]

            ])

        }


    }

但我得到了这个失败的断言

无法断言数组具有子集 Array &0 (

 'data' => Array &1 (
        0 => Array &2 (
            'id' => 5
            'name_en' => 'Www'
        )
    )
).
--- Expected
+++ Actual
@@ @@
-                    [id] => 5
-                    [name_en] => Wind Speed

+                    [id] => 4
+                    [name_en] => ww

/code/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:290

标签: phpunit-testingfor-looptestinglaravel-5

解决方案


推荐阅读