Omda
1 month ago
227
11
Testing

How can i get id of created row when testing

Posted 1 month ago by Omda

i am working with phpunit when i created new record using endpoint, i cant get id of my new record

/** @test */
    public function authenticated_user_should_create_document()
    {
        $this->withExceptionHandling();
        // create user
        $user = factory('App\User')->create();    
        // authenticated user
        $this->be($user);
        // hit the server to store document
        $document = factory('App\Document')->make(['user_id' => $user->id]);

        $response = $this->post('gate/document', $document->toArray());

    dd($document->path());
        $response->assertRedirect('gate/document/'.$document->path().'/editor');

and the document.php

 public function path()
 {
        return $this->id;
 }

the result is null

Please sign in or create an account to participate in this conversation.