/** * @param \stdClass $apiJob * @param $country * * @return Job * @throws CareerjetException */ public static function fromApi(\stdClass $apiJob, string $country) : Job { self::validateJob($apiJob); $job = new Job(); $job->setTitle($apiJob->title); $job->setDate(new \DateTime($apiJob->date)); $job->setSnippet($apiJob->description); $job->setViewUrl($apiJob->url); if (isset($apiJob->salary_currency_code)) { $job->setSalaryCurrencyCode($apiJob->salary_currency_code); } if (isset($apiJob->salary_min)) { $job->setSalaryMin($apiJob->salary_min); } if (isset($apiJob->salary_max)) { $job->setSalaryMax($apiJob->salary_max); } $job->setCountry($country); switch ($country) { case 'Brazil': $job = JobWithBrazilianLocationsBuilder::fromApi($apiJob, $job); break; default: break; } $job->setSource($apiJob->site); if (!empty($apiJob->company)) { $job->setCompany($apiJob->company); } return $job; }
/** * @dataProvider statesDataProvider * @param $stateName * @param $shortState * @throws \Jobles\Careerjet\Exception\CareerjetException */ public function testLocationsAsStateNameSetsShortStateOnJob($stateName, $shortState) { $this->apiJob->locations = $stateName; $this->job = JobWithBrazilianLocationsBuilder::fromApi($this->apiJob, $this->job); $this->assertEquals($shortState, $this->job->getState()); $this->assertEmpty($this->job->getCity()); $this->assertEquals('Brazil', $this->job->getCountry()); }