lundi 10 septembre 2018

for each with laravel testing api

here is my test WP method

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,
                ]

            ])

        }


    }

But I got this failed assertion

Failed asserting that an array has the subset Array &0 (

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

+                    [id] => 4
+                    [name_en] => Cloud ceiling

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



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2wYb8of
via IFTTT

Aucun commentaire:

Enregistrer un commentaire