Skip to content

Commit

Permalink
Updating provider
Browse files Browse the repository at this point in the history
  • Loading branch information
karllhughes committed Jan 6, 2017
1 parent c854a7c commit 441815f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 43 deletions.
9 changes: 2 additions & 7 deletions src/Providers/MonsterProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,8 @@ public function createJobObject($payload)
$job->setDatePostedAsString($payload['pubDate']);

// Set a location if it was set in the query
if ($this->query && $this->query->get('l')) {
$job->setLocation($this->query->get('l'));
}

// Set a company if it was set in the query
if ($this->query && $this->query->get('company')) {
$job->setCompany($this->query->get('company'));
if ($this->query && $this->query->get('where')) {
$job->setLocation($this->query->get('where'));
}

return $job;
Expand Down
52 changes: 16 additions & 36 deletions tests/src/MonsterProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

class MonsterProviderTest extends \PHPUnit_Framework_TestCase
{
/**
* @var MonsterProvider
*/
public $client;

public function setUp()
{
$this->query = m::mock(MonsterQuery::class);
Expand Down Expand Up @@ -59,13 +64,9 @@ public function testItCanCreateJobObjectWhenLocationSet()
$payload = $this->createJobArray();

$this->query->shouldReceive('get')
->with('l')
->with('where')
->once()
->andReturn($location);
$this->query->shouldReceive('get')
->with('company')
->once()
->andReturn(null);

$results = $this->client->createJobObject($payload);

Expand All @@ -77,46 +78,22 @@ public function testItCanCreateJobObjectWhenLocationSet()
$this->assertEquals($location, $results->getLocation());
}

public function testItCanCreateJobObjectWhenCompanySet()
{
$company = uniqid();
$payload = $this->createJobArray();

$this->query->shouldReceive('get')
->with('company')
->once()
->andReturn($company);
$this->query->shouldReceive('get')
->with('l')
->once()
->andReturn(null);

$results = $this->client->createJobObject($payload);

$this->assertInstanceOf(Job::class, $results);
$this->assertEquals($payload['title'], $results->getTitle());
$this->assertEquals($payload['title'], $results->getName());
$this->assertEquals($payload['description'], $results->getDescription());
$this->assertEquals($payload['link'], $results->getUrl());
$this->assertEquals($company, $results->getCompany());
}

/**
* Integration test for the client's getJobs() method.
*/
public function testItCanGetJobs()
{
$options = [
'q' => uniqid(),
'l' => uniqid(),
't' => uniqid(),
'where' => uniqid(),
'page' => rand(1,5),
];

$guzzle = m::mock('GuzzleHttp\Client');

$query = new JobinventoryQuery($options);
$query = new MonsterQuery($options);

$client = new JobinventoryProvider($query);
$client = new MonsterProvider($query);

$client->setClient($guzzle);

Expand Down Expand Up @@ -148,19 +125,22 @@ public function testItCanGetJobsFromApi()
}

$keyword = 'engineering';
$location = 'chicago, il';

$query = new JobinventoryQuery([
$query = new MonsterQuery([
'q' => $keyword,
'where' => $location,
]);

$client = new JobinventoryProvider($query);
$client = new MonsterProvider($query);

$results = $client->getJobs();

$this->assertInstanceOf('JobApis\Jobs\Client\Collection', $results);

foreach($results as $job) {
$this->assertEquals($keyword, $job->query);
$this->assertEquals($location, $job->location);
}
}

Expand All @@ -176,6 +156,6 @@ private function createJobArray()

private function createXmlResponse()
{
return "<?xml version='1.0' encoding='UTF-8' ?><rss version='2.0'><channel><title>Hotel Jobs in Chicago, IL // JobInventory.com</title><item><title>Hotel Specialist Agents</title><link>http://www.jobinventory.com/d/Hotel-Specialist-Agents-Jobs-Chicago-IL-1391153840.html</link><description>Full-time/Regular 9:00 AM to 6:00 PM. 40 hours per week. (Overtime as required) The <b>hotel</b> ... Specialist Agents would pre pay all <b>hotel</b> rooms and help support the reservations team. JOB OVERVIEW work</description><pubDate>2015-04-11 00:48:39</pubDate></item><item><title>Maintenance_Hourly1</title><link>http://www.jobinventory.com/d/Maintenance_hourly1-Jobs-Chicago-IL-1583775509.html</link><description>Data not provided</description><pubDate>2016-05-17 18:13:26</pubDate></item></channel></rss>";
return "<rss version='2.0'><channel><title>Hotel Jobs in Chicago, IL // JobInventory.com</title><item><title>Hotel Specialist Agents</title><link>http://www.jobinventory.com/d/Hotel-Specialist-Agents-Jobs-Chicago-IL-1391153840.html</link><description>Full-time/Regular 9:00 AM to 6:00 PM. 40 hours per week. (Overtime as required) The <b>hotel</b> ... Specialist Agents would pre pay all <b>hotel</b> rooms and help support the reservations team. JOB OVERVIEW work</description><pubDate>2015-04-11 00:48:39</pubDate></item><item><title>Maintenance_Hourly1</title><link>http://www.jobinventory.com/d/Maintenance_hourly1-Jobs-Chicago-IL-1583775509.html</link><description>Data not provided</description><pubDate>2016-05-17 18:13:26</pubDate></item></channel></rss>";
}
}

0 comments on commit 441815f

Please sign in to comment.