Domain\Classroom\Http\ClassroomControllerTest::test_get_students PHP Method

test_get_students() public method

Test get students.
public test_get_students ( )
    public function test_get_students()
    {
        $classroom = factory(Classroom::class)->create();
        $students = factory(Student::class, 30)->create()->random(5);
        $students->each(function ($student) use($classroom) {
            $classroom->students()->attach($student);
        });
        $this->get('api/v1/classroom/' . $classroom->id . '/students');
        $this->seeStatusCode(200);
        $response = json_decode($this->response->getContent(), true);
        $this->assertTrue(isset($response['classroom']));
        $this->assertTrue(isset($response['students']));
        $this->seeJson(['id' => $classroom->id, 'name' => $classroom->name]);
        $students->each(function ($student) use($classroom) {
            $this->seeJson(['id' => $student->id, 'name' => $student->name]);
            $this->seeInDatabase('classroom_student', ['classroom_id' => $classroom->id, 'student_id' => $student->id]);
        });
    }