lundi 14 mars 2022

Testing when using the Eloquent "on" method

I am writing the test now.

I have multiple databases and am switching between them using the "on" method.

Here is the code I want to test. I've abbreviated a few things. Post::on("connection2")->get(); and return api

in postApiTest.php

//create any post use factory in code

//debug
Post::on("connection2")->count() // return 0
Post::on("connection_default")->count()// return many post

$response->assertOk()  //200
            ->assertJsonCount(10) // but return 0
            ->assertJsonFragment([ // but dont have json
                'title' => 'title',
            ]);

I want to test the number of pieces coming back from the API, but it is zero

Use the same connection or Mock methods or Is there a better way?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire