lundi 31 octobre 2016

Laravel Model Factory Freezes PHPUnit test

I have this test that checks getting a list of bank accounts. If I remove the factory line the test will run and fail as no record was created, but with it there the test just hangs and spikes my CPU.

public function get_list_of_bank_accounts()
    {
        $user = $this->newLoggedInUser();
        factory(App\BankAccount::class)->create(["account_id" => $user->account_id]);

        $json = $this->get($this->url . "/", $this->userAuthHeader($user));
        $json->assertResponseStatus(200);
        $bankAccounts = self::jsonToArray($json);
        $this->assertEquals(1, count($bankAccounts));
    }

If I output $bankAccount after the line I get the output and the tests stop so it does not seem to hang because of the factory and then the get request will run if I do not have the factory so I do not know why these combined is breaking.

public function get_list_of_bank_accounts()
    {
        $user = $this->newLoggedInUser();
        $bankAccount = factory(App\BankAccount::class)->create(["account_id" => $user->account_id]);
        dd($bankAccount);    

        $json = $this->get($this->url . "/", $this->userAuthHeader($user));
        $json->assertResponseStatus(200);
        $bankAccounts = self::jsonToArray($json);
        $this->assertEquals(1, count($bankAccounts));
    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire