finchy70
10 months ago

Tests not generating id's.

Posted 10 months ago by finchy70

The following code is giving an error that suggests no values are being generated for 'diary_id', 'labour_id', 'resource_type_id'. I'm new to PHPUnit. Have I got my syntax wrong?

<?php

namespace Tests\Feature;

use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase;


class ResourceTest extends TestCase
{
    use DatabaseMigrations;

    /**
     * @test
     */
    public function it_can_display_resource_attached_to_a_diary_entry()
    {
        $resource = create('App\Resource', [
            'diary_id'          => function() {
                create('App\Diary')->id;
            },

            'resource_type_id'  => function() {
                create('App\ResourceType')->id;
            },

            'labour_id'         => function() {
                create('App\Labour')->id;
            }]);

        $this->get('/diaries/entry/'.$resource->diary_id)
            ->assertSee(e($resource->labour->name));
    }
}

Here are my test helpers.

function create($class, $attributes = [], $times = null)
{
    return factory($class, $times)->create($attributes);
}

function make($class, $attributes = [], $times = null)
{
    return factory($class, $times)->make($attributes);
}

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