Skip to content

Commit 1aaf45a

Browse files
author
Harry Bragg
committed
100% coverage, tidy make and README.md
1 parent f5ccbaf commit 1aaf45a

File tree

5 files changed

+81
-13
lines changed

5 files changed

+81
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/vendor/
22
composer.lock
3+
/tests/report/

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: test test-coverage test-unit test-unit-coverage test-functional test-functional-coverage install
1+
.PHONY: test lint lint-auto-fix test-coverage test-unit test-unit-coverage test-functional test-functional-coverage test-performance install
22

33
test:
44
@./vendor/bin/phpunit --exclude-group performance
@@ -10,7 +10,7 @@ lint-auto-fix:
1010
@./vendor/bin/phpcbf -p --standard=PSR2 src/ tests/
1111

1212
test-coverage:
13-
@./vendor/bin/phpunit --coverage-text --coverage-html ./tests/report
13+
@./vendor/bin/phpunit --coverage-text --coverage-html ./tests/report --exclude-group performance
1414

1515
test-unit:
1616
@./vendor/bin/phpunit --testsuite unit

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
[![Total Downloads](https://img.shields.io/packagist/dt/graze/gigya-client.svg?style=flat-square)](https://packagist.org/packages/graze/gigya-client)
99
[![StyleCI](https://styleci.io/repos/43295589/shield)](https://styleci.io/repos/43295589)
1010

11-
Basic Client for Gigya's REST API
11+
Client for Gigya's REST API
1212

1313
## Install
1414

15-
Via Composer
15+
The simplest way to install the client is with composer and running:
1616

1717
``` bash
1818
$ composer require graze/gigya-client
@@ -21,8 +21,8 @@ $ composer require graze/gigya-client
2121
## Usage
2222

2323
``` php
24-
$client = new \Graze\Gigya\Gigya($key, $secret, Gigya::DC_EU);
25-
$response = $client->accounts()->getAccountInfo(['uid' => $uid]);
24+
$gigya = new Gigya($key, $secret);
25+
$response = $gigya->accounts()->getAccountInfo(['uid' => $uid]);
2626
$account = $response->getData();
2727
```
2828

tests/unit/GigyaTest.php

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,12 @@ private function setupCall($fixtureName, $uri, $getOptions, $key, $secret, $user
117117
$response = m::mock('GuzzleHttp\Message\ResponseInterface');
118118
$response->shouldReceive('getBody')->andReturn(TestFixtures::getFixture($fixtureName));
119119

120-
$this->guzzleClient
121-
->shouldReceive('get')
122-
->with(
123-
$uri,
124-
$getOptions
125-
)
126-
->andReturn($response);
120+
$this->guzzleClient->shouldReceive('get')
121+
->with(
122+
$uri,
123+
$getOptions
124+
)
125+
->andReturn($response);
127126

128127
$gigyaResponse = m::mock('Graze\Gigya\Response\ResponseInterface');
129128

@@ -134,6 +133,58 @@ private function setupCall($fixtureName, $uri, $getOptions, $key, $secret, $user
134133
return $gigyaResponse;
135134
}
136135

136+
public function testConstructorConfig()
137+
{
138+
139+
$this->guzzleClient->shouldReceive('__construct')
140+
->once()
141+
->with([
142+
'emitter' => $this->emitter,
143+
])
144+
->andReturn($this->guzzleClient);
145+
146+
$this->emitter->shouldReceive('attach')
147+
->with(m::type(ValidGigyaResponseSubscriber::class))
148+
->once();
149+
150+
$response = m::mock('GuzzleHttp\Message\ResponseInterface');
151+
$response->shouldReceive('getBody')->andReturn(TestFixtures::getFixture('account.getAccountInfo'));
152+
153+
$this->guzzleClient->shouldReceive('get')
154+
->with(
155+
'https://accounts.au1.gigya.com/accounts.getAccountInfo',
156+
[
157+
'cert' => 'some_cert.pem',
158+
'auth' => 'oauth',
159+
'verify' => $this->certPath,
160+
'query' => [],
161+
]
162+
)
163+
->andReturn($response);
164+
165+
$gigyaResponse = m::mock('Graze\Gigya\Response\ResponseInterface');
166+
167+
$this->factory->shouldReceive('getResponse')
168+
->with($response)
169+
->andReturn($gigyaResponse);
170+
171+
$config = [
172+
'dataCenter' => Gigya::DC_AU,
173+
'auth' => 'oauth',
174+
'uidValidator' => false,
175+
'factory' => $this->factory,
176+
'guzzle' => [
177+
'emitter' => $this->emitter,
178+
],
179+
'options' => [
180+
'cert' => 'some_cert.pem',
181+
],
182+
];
183+
$client = new Gigya('key', 'secret', null, $config);
184+
185+
static::assertSame($gigyaResponse, $client->accounts()->getAccountInfo());
186+
}
187+
137188
public function testSettingKeyAndSecretWillPassToGuzzleClient()
138189
{
139190
$key = 'key' . rand(1, 1000);

tests/unit/Validation/ValidGigyaResponseSubscriberTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Graze\Gigya\Test\Unit\Validation;
44

5+
use Graze\Gigya\Exception\UnknownResponseException;
56
use Graze\Gigya\Test\TestCase;
67
use Graze\Gigya\Test\TestFixtures;
78
use Graze\Gigya\Validation\ValidGigyaResponseSubscriber;
@@ -115,4 +116,19 @@ public function testInvalidBody()
115116

116117
$this->validator->onComplete($completeEvent, 'name');
117118
}
119+
120+
public function testUnknownResponseContainsTheOriginalResponse()
121+
{
122+
$completeEvent = m::mock(CompleteEvent::class);
123+
$response = m::mock('GuzzleHttp\Message\ResponseInterface');
124+
$completeEvent->shouldReceive('getResponse')
125+
->andReturn($response);
126+
$response->shouldReceive('getBody')->andReturn(TestFixtures::getFixture('invalid_json'));
127+
128+
try {
129+
$this->validator->onComplete($completeEvent, 'name');
130+
} catch (UnknownResponseException $e) {
131+
static::assertSame($response, $e->getResponse());
132+
}
133+
}
118134
}

0 commit comments

Comments
 (0)