Skip to content

Commit

Permalink
Adding test coverage for guzzle 6
Browse files Browse the repository at this point in the history
  • Loading branch information
karllhughes committed Jun 7, 2015
1 parent 2e866d7 commit 721af2c
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ checks:
tools:
external_code_coverage:
timeout: 600
runs: 3
runs: 2
php_analyzer: true
php_code_coverage: false
php_code_sniffer:
Expand Down
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
Expand Down
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-indeed` will be documented in this file

## 0.3.2 - 2015-06-07

### Added
- Nothing

### Deprecated
- Nothing

### Fixed
- Test coverage for Guzzle 6

### Removed
- Nothing

### Security
- Nothing

## 0.3.1 - 2015-05-24

### Added
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,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
81 changes: 58 additions & 23 deletions tests/src/IndeedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@

class IndeedTest 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->params = [
'publisherId' => '3806336598146294',
'publisherId' => '12345667',
'version' => 2,
'highlight' => 0,
];
Expand Down Expand Up @@ -215,21 +219,37 @@ public function testUrlNotIncludesVersionWhenNotProvided()
$this->assertNotContains($param, $url);
}

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

$this->assertEquals($payload['jobtitle'], $results->title);
$this->assertEquals($payload['snippet'], $results->description);
$this->assertEquals($payload['company'], $results->company);
$this->assertEquals($payload['url'], $results->url);
$this->assertEquals($payload['jobkey'], $results->sourceId);
$this->assertEquals($payload['formattedLocation'], $results->location);
}

public function testItCanConnect()
{
$jobCount = rand(2,10);
$listings = ['results' => $this->getResultItems($jobCount)];
$source = $this->client->getSource();
$keyword = 'project manager';
$city = 'Chicago';
$state = 'IL';
$provider = $this->getProviderAttributes();

$this->client->setKeyword($keyword)
->setCity($city)
->setState($state);
for ($i = 0; $i < $provider['jobs_count']; $i++) {
$payload['results'][] = $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 @@ -240,17 +260,32 @@ public function testItCanConnect()

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

$this->assertCount($jobCount, $results);

foreach ($listings['results'] as $i => $result) {
$this->assertEquals($listings['results'][$i]['jobtitle'], $results->get($i)->title);
$this->assertEquals($listings['results'][$i]['company'], $results->get($i)->company);
$this->assertEquals($listings['results'][$i]['formattedLocation'], $results->get($i)->location);
$this->assertEquals($listings['results'][$i]['snippet'], $results->get($i)->description);
$this->assertEquals($listings['results'][$i]['url'], $results->get($i)->url);
$this->assertEquals($listings['results'][$i]['jobkey'], $results->get($i)->sourceId);
$this->assertEquals($source, $results->get($i)->source);
$this->assertEquals($keyword, $results->get($i)->query);
}
$this->assertInstanceOf($this->collectionClass, $results);
$this->assertCount($provider['jobs_count'], $results);
}

private function createJobArray() {
return [
'jobtitle' => uniqid(),
'company' => uniqid(),
'formattedLocation' => uniqid(),
'snippet' => uniqid(),
'url' => uniqid(),
'jobkey' => uniqid(),
];
}

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 721af2c

Please sign in to comment.