create([ 'happened_at' => '2008-01-01', ]); $lifeEventType = factory(LifeEventType::class)->create([ 'account_id' => $lifeEvent->account_id, ]); $request = [ 'life_event_id' => $lifeEvent->id, 'account_id' => $lifeEvent->account_id, 'life_event_type_id' => $lifeEventType->id, 'happened_at' => '2018-01-01', 'name' => 'This is a name', 'note' => 'This is a note', ]; $lifeEvent = app(UpdateLifeEvent::class)->execute($request); $this->assertDatabaseHas('life_events', [ 'id' => $lifeEvent->id, 'happened_at' => '2018-01-01 00:00:00', 'life_event_type_id' => $lifeEventType->id, 'contact_id' => $lifeEvent->contact_id, 'account_id' => $lifeEvent->account_id, 'name' => 'This is a name', 'note' => 'This is a note', ]); $this->assertInstanceOf( LifeEvent::class, $lifeEvent ); } /** @test */ public function it_fails_if_wrong_parameters_are_given() { $contact = factory(Contact::class)->create([]); $request = [ 'contact_id' => $contact->id, 'happened_at' => now(), ]; $this->expectException(ValidationException::class); app(UpdateLifeEvent::class)->execute($request); } /** @test */ public function it_throws_an_exception_if_life_type_doesnt_exist() { $account = factory(Account::class)->create(); $lifeEvent = factory(LifeEvent::class)->create([]); $lifeEventType = factory(LifeEventType::class)->create([ 'account_id' => $lifeEvent->account_id, ]); $request = [ 'account_id' => $account->id, 'contact_id' => $lifeEvent->contact_id, 'life_event_id' => $lifeEvent->id, 'happened_at' => '2010-02-02', 'life_event_type_id' => $lifeEventType->id, 'name' => 'This is a name', 'note' => 'This is a note', ]; $this->expectException(ModelNotFoundException::class); app(UpdateLifeEvent::class)->execute($request); } }