testing returning InvalidArgumentException when using factory

Posted 7 months ago by nhayder

i was watching jeffries let's build a forum together to learn some testing stuff, but i got stuck with this error.

Time: 142 ms, Memory: 16.00MB

There was 1 error:

1) Tests\Unit\ThreadsTest::a_user_can_browse_threads
InvalidArgumentException: You requested 1 items, but there are only 0 items available.

/Applications/MAMP/htdocs/vendor/laravel/framework/src/Illuminate/Support/Arr.php:480
/Applications/MAMP/htdocs/vendor/laravel/framework/src/Illuminate/Support/Collection.php:1298
/Applications/MAMP/htdocs/database/factories/ThreadFactory.php:7
/Applications/MAMP/htdocs/vendor/laravel/framework/src/Illuminate/Database/Eloquent/FactoryBuilder.php:263
/Applications/MAMP/htdocs/vendor/laravel/framework/src/Illuminate/Database/Eloquent/FactoryBuilder.php:281
/Applications/MAMP/htdocs/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/GuardsAttributes.php:122
/Applications/MAMP/htdocs/vendor/laravel/framework/src/Illuminate/Database/Eloquent/FactoryBuilder.php:289
/Applications/MAMP/htdocs/vendor/laravel/framework/src/Illuminate/Database/Eloquent/FactoryBuilder.php:208
/Applications/MAMP/htdocs/vendor/laravel/framework/src/Illuminate/Database/Eloquent/FactoryBuilder.php:167
/Applications/MAMP/htdocs/tests/Unit/ThreadsTest.php:17

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.

not sure what is going on but this is my test

<?php

namespace Tests\Unit;

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

class ThreadsTest extends TestCase
{
    
    use DatabaseMigrations;

    /** @test */
    public function a_user_can_browse_threads()
    {
        $thread = factory('App\Thread')->create();

        $response = $this->get('/threads');
        
        $response->assertSee($thread->title);


    }
} 

the factory part is the reason for the error. Any ideas?

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

Reply to

Use Markdown with GitHub-flavored code blocks.