Summer Sale! All accounts are 50% off this week.

learningMonkey's avatar

showing me error , help me out

  1. Tests\Feature\ProjectsTest::test_a_user_can_create_a_project.
Failed asserting that '' contains "Unde hic vitae reprehenderit repudiandae.".
0 likes
9 replies
Sinnbeck's avatar

Show the test and the method you are testing

learningMonkey's avatar

@Sinnbeck test code


namespace Tests\Feature;

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

class ProjectsTest extends TestCase
{
    use WithFaker, RefreshDatabase;
    public function test_a_user_can_create_a_project()
    {
        $this->withoutExceptionHandling();
        $attributes = [
            'title' => $this->faker->sentence,
            'description' => $this->faker->paragraph,
        ];

        $this->post('/projects', $attributes);
        $this->assertDatabaseHas('projects',$attributes);
        $this->get('/projects')->assertSee($attributes['title']);
   
    }
}
learningMonkey's avatar

controller code


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Project;

class ProjectsController extends Controller
{
    public function index()
    {
        
    }

    public function create()
    {
        $projects  = Project::all();
            return view('Birdboardproject.index', compact('projects'));
    }

    public function store(Request $request)
    {
        Project::create(request(['title', 'description']));
        
    }
}
Sinnbeck's avatar

@jaspal you should not assert on multiple routes in one test. Move this to a seperate test and simply add the data before the route call (i would use a factory)

$this->get('/projects')->assertSee($attributes['title'])
1 like
Sinnbeck's avatar

@jaspal ok strange. I would assume he refactors it later. Haven't seen the videos

But it is telling you that the view returns nothing

You are showing the create method but it seems you are testing index()

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@jaspal move the code for the index method into the index method

1 like
learningMonkey's avatar

@Sinnbeck finded the issue ,my bad i have stored it into another method and calling the another method...

Thanks sir

Please or to participate in this conversation.