Skip to content

Commit

Permalink
Improving test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
karllhughes committed Jun 7, 2015
1 parent 176cb9c commit cdc1280
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 7 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
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.3"
"php": ">=5.5.0",
"jobbrander/jobs-common": "~0.7"
},
"require-dev": {
"phpunit/phpunit": "3.7.*",
Expand Down
4 changes: 2 additions & 2 deletions src/Careerbuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function createJobObject($payload)
'Location',
'City',
'State',
'PostedTime',
'PostedDate',
'Pay',
'JobTitle',
'CompanyImageURL',
Expand Down Expand Up @@ -83,7 +83,7 @@ public function createJobObject($payload)
)->setCompanyUrl($payload['CompanyDetailsURL'])
->setCity($payload['City'])
->setState($payload['State'])
->setDatePostedAsString($payload['PostedTime'])
->setDatePostedAsString($payload['PostedDate'])
->setCompanyLogo($payload['CompanyImageURL']);

if (isset($payload['Skills']['Skill'])) {
Expand Down
60 changes: 59 additions & 1 deletion tests/src/CareerbuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

class CareerbuilderTest 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 Careerbuilder();
Expand Down Expand Up @@ -162,6 +166,46 @@ public function testItCanCreateJobFromPayload()
$this->assertEquals($payload['JobDetailsURL'], $results->url);
}

public function testItCanConnect()
{
$provider = $this->getProviderAttributes(['format' => 'xml']);
$payload = [];

$responseBody = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><ResponseJobSearch><Results>";

for ($i = 0; $i < $provider['jobs_count']; $i++) {
$jobArray = $this->createJobArray();
$path = $provider['path'];
array_push($payload, $jobArray);
$responseBody .= "<JobSearchResult><JobTitle>".$jobArray['JobTitle']."</JobTitle>";
$responseBody .= "<PostedDate>".$jobArray['PostedDate']."</PostedDate>";
$responseBody .= "</JobSearchResult>";
}

$responseBody .= "</Results></ResponseJobSearch>";

$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('getBody')->once()->andReturn($responseBody);

$http = m::mock('GuzzleHttp\Client');
$http->shouldReceive(strtolower($this->client->getVerb()))
->with($this->client->getUrl(), $this->client->getHttpClientOptions())
->once()
->andReturn($response);
$this->client->setClient($http);

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

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

private function createJobArray() {
return [
'Company' => uniqid(),
Expand All @@ -176,7 +220,7 @@ private function createJobArray() {
'Location' => uniqid(),
'City' => uniqid(),
'State' => uniqid(),
'PostedTime' => date('F j, Y, g:i a'),
'PostedDate' => date('m/d/Y'),
'Pay' => uniqid(),
'JobTitle' => uniqid(),
'CompanyImageURL' => uniqid(),
Expand All @@ -190,4 +234,18 @@ private function createJobArray() {
]
];
}

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 cdc1280

Please sign in to comment.