/** @test */ public function it_can_be_constructed_from_database_row() { $airport = AirportInfo::fromData(['code' => 'RDU', 'name' => 'Raleigh/Durham (NC)', 'country' => 'USA']); $this->assertEquals('RDU', $airport->code); $this->assertEquals('Raleigh/Durham (NC)', $airport->name); $this->assertEquals('USA', $airport->country); }
/** * @param string $code the IATA Airport Code to get information for * * @return AirportInfo * @throws \Exception */ public function withCode($code) { $airport = $this->capsule->table('airports')->where('code', $code)->first(['code', 'name', 'country']); if (!$airport) { throw new \Exception("An airport matching '{$code}' was not found."); } return AirportInfo::fromData($airport); }