/** * @test */ public function it_throws_a_422_when_fetching_all_enrollments_to_a_given_invalid_program() { //arrange $attendeeTest = new AttendeesTest(); $programTest = new ProgramsTest(); $this->times(1)->make('App\\Attendee', $attendeeTest->getStub()); $this->times(1)->make('App\\Program', $programTest->getStub()); foreach (App\Program::all() as $program) { foreach (App\Attendee::all() as $attendee) { App\Enrollment::create(['attendee_id' => $attendee->id, 'program_id' => $program->id, 'start_date' => $this->faker->dateTimeBetween($startDate = '-12 months')]); } } //act $response = $this->getJson('enrollments', 'GET', ['program_id' => 'x']); //assert $this->assertResponseStatus(422); $this->assertObjectHasAttributes($response, 'error'); $this->assertObjectHasAttributes($response->error, 'message'); $this->assertContains('Program provided does not exist.', $response->error->message); }