Skip to content

Commit

Permalink
Upating for guzzle 6
Browse files Browse the repository at this point in the history
  • Loading branch information
karllhughes committed Jun 7, 2015
1 parent 64de54b commit 95452a1
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 49 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
# Changelog
All Notable changes to `jobs-govt` will be documented in this file

## 0.4.1 - 2015-06-07

### Added
- Nothing

### Deprecated
- Nothing

### Fixed
- Fixing tests for guzzle v.6.0

### Removed
- Nothing

### Security
- Nothing

## 0.4.0 - 2015-05-16

### Added
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
}
],
"require": {
"php": ">=5.4.0",
"jobbrander/jobs-common": "~0.4"
"php": ">=5.5.0",
"jobbrander/jobs-common": "~0.7"
},
"require-dev": {
"phpunit/phpunit": "3.7.*",
Expand Down
123 changes: 76 additions & 47 deletions tests/src/GovtTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

class GovtTest extends \PHPUnit_Framework_TestCase
{
private $clientClass = 'JobBrander\Jobs\Client\Providers\AbstractProvider';
private $collectionClass = 'JobBrander\Jobs\Client\Collection';
private $jobClass = 'JobBrander\Jobs\Client\Job';

public function setUp()
{
$this->client = new Govt();
Expand Down Expand Up @@ -131,32 +135,61 @@ public function testUrlNotIncludesFromWhenNotProvided()

public function testItCreatesMultipleJobsWhenMultipleLocationsReturned()
{
$job_count = 1;
$loc_count = rand(1,3);
$jobs = $this->createJobArray($job_count, $loc_count);
$loc_count = rand(2,5);
$jobArray = $this->createJobArray($loc_count);

$array = $this->client->createJobArray($jobArray);

foreach ($array as $key => $job) {
$this->assertEquals($jobArray['position_title'], $array[0]['position_title']);
$this->assertEquals($jobArray['locations'][$key], $array[$key]['location']);
}
$this->assertEquals($loc_count, count($array));
}

public function testItCreatesOneJobWhenOneLocationsReturned()
{
$loc_count = 1;
$jobArray = $this->createJobArray($loc_count);

$array = $this->client->createJobArray($jobs[0]);
$array = $this->client->createJobArray($jobArray);

foreach ($array as $key => $job) {
$this->assertEquals($jobs[0]['position_title'], $array[0]['position_title']);
$this->assertEquals($jobs[0]['locations'][$key], $array[$key]['location']);
$this->assertEquals($jobArray['position_title'], $array[0]['position_title']);
$this->assertEquals($jobArray['locations'][$key], $array[$key]['location']);
}
$this->assertEquals(($job_count*$loc_count), count($array));
$this->assertEquals($loc_count, count($array));
}

public function testItCanCreateJobFromPayload()
{
$payload = $this->createJobArray(2);
$results = $this->client->createJobObject($payload);

$this->assertEquals($payload['id'], $results->sourceId);
$this->assertEquals($payload['position_title'], $results->title);
$this->assertEquals($payload['organization_name'], $results->company);
$this->assertEquals($payload['url'], $results->url);
}

public function testItCanConnect()
{
$job_count = rand(2,10);
$listings = $this->createJobArray($job_count);
$source = $this->client->getSource();
$keyword = 'project manager';
$provider = $this->getProviderAttributes();

$this->client->setKeyword($keyword)
->setCity('Chicago')
->setState('IL');
for ($i = 0; $i < $provider['jobs_count']; $i++) {
$payload[] = $this->createJobArray();
}

$responseBody = json_encode($payload);

$job = m::mock($this->jobClass);
$job->shouldReceive('setQuery')->with($provider['keyword'])
->times($provider['jobs_count'])->andReturnSelf();
$job->shouldReceive('setSource')->with($provider['source'])
->times($provider['jobs_count'])->andReturnSelf();

$response = m::mock('GuzzleHttp\Message\Response');
$response->shouldReceive($this->client->getFormat())->once()->andReturn($listings);
$response->shouldReceive('getBody')->once()->andReturn($responseBody);

$http = m::mock('GuzzleHttp\Client');
$http->shouldReceive(strtolower($this->client->getVerb()))
Expand All @@ -167,40 +200,22 @@ public function testItCanConnect()

$results = $this->client->getJobs();

foreach ($listings as $i => $result) {
$this->assertEquals($listings[$i]['id'], $results->get($i)->sourceId);
$this->assertEquals($listings[$i]['position_title'], $results->get($i)->title);
$this->assertEquals($listings[$i]['url'], $results->get($i)->url);
$this->assertEquals($listings[$i]['organization_name'], $results->get($i)->company);
$this->assertEquals($listings[$i]['start_date'], $results->get($i)->startDate);
$this->assertEquals($listings[$i]['end_date'], $results->get($i)->endDate);
$this->assertEquals($listings[$i]['minimum'], $results->get($i)->minimumSalary);
$this->assertEquals($listings[$i]['maximum'], $results->get($i)->maximumSalary);
$this->assertEquals($keyword, $results->get($i)->query);
$this->assertEquals($source, $results->get($i)->source);
}

$this->assertEquals(count($listings), $results->count());
$this->assertInstanceOf($this->collectionClass, $results);
$this->assertCount($provider['jobs_count'], $results);
}

private function createJobArray($job_count = 10, $loc_count = 1) {
$jobs = [];
$i = 0;
while ($i < $job_count) {
$jobs[] = [
'id' => uniqid(),
'position_title' => uniqid(),
'organization_name' => uniqid(),
'locations' => $this->createLocationsArray($loc_count),
'start_date' => uniqid(),
'end_date' => uniqid(),
'url' => uniqid(),
'minimum' => uniqid(),
'maximum' => uniqid(),
];
$i++;
}
return $jobs;
private function createJobArray($loc_count = 1) {
return [
'id' => uniqid(),
'position_title' => uniqid(),
'organization_name' => uniqid(),
'locations' => $this->createLocationsArray($loc_count),
'start_date' => uniqid(),
'end_date' => uniqid(),
'url' => uniqid(),
'minimum' => uniqid(),
'maximum' => uniqid(),
];
}

private function createLocationsArray($loc_count = 3) {
Expand All @@ -212,4 +227,18 @@ private function createLocationsArray($loc_count = 3) {
}
return $locations;
}

private function getProviderAttributes($attributes = [])
{
$defaults = [
'path' => uniqid(),
'format' => 'json',
'keyword' => uniqid(),
'source' => uniqid(),
'params' => [uniqid()],
'jobs_count' => rand(2,10),

];
return array_replace($defaults, $attributes);
}
}

0 comments on commit 95452a1

Please sign in to comment.