Skip to content

Commit adaae17

Browse files
committed
CI setup
1 parent fe1607b commit adaae17

File tree

9 files changed

+71
-21
lines changed

9 files changed

+71
-21
lines changed

.travis.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
language: php
2+
3+
php:
4+
- 5.6
5+
- 7.0
6+
- 7.1
7+
- 7.2
8+
9+
install: composer install
10+
11+
cache:
12+
directories:
13+
- $HOME/.composer/cache/repo/
14+
- $TRAVIS_BUILD_DIR/vendor/
15+
16+
script:
17+
- vendor/bin/phpunit tests
18+
- vendor/bin/php-cs-fixer fix src
19+
- vendor/bin/php-cs-fixer fix tests
20+
21+
branches:
22+
only:
23+
- master
24+
25+
notifications:
26+
email:
27+
on_success: never

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"php-http/mock-client": "^1.0",
2626
"guzzlehttp/psr7": "^1.2",
2727
"cache/array-adapter": "^0.4",
28-
"phpstan/phpstan": "^0.9.1",
2928
"friendsofphp/php-cs-fixer": "^2.10"
3029
},
3130
"autoload": {

src/Api/AbstractApi.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ protected function get($path, array $parameters = [], array $headers = [])
2929
if (count($parameters) > 0) {
3030
$path .= '?'.http_build_query($parameters);
3131
}
32-
$response = $this->client->getHttpClient()->get($path, $headers);
32+
$response = $this->client->getHttpClient()->get(
33+
$path,
34+
array_merge($headers, ['Accept' => 'application/json'])
35+
);
3336

3437
return $this->responseMediator->getContent($response);
3538
}
@@ -44,7 +47,7 @@ protected function post($path, array $parameters = [], array $headers = [])
4447
{
4548
$response = $this->client->getHttpClient()->post(
4649
$path,
47-
$headers,
50+
array_merge($headers, ['Accept' => 'application/json']),
4851
$this->createJsonBody($parameters)
4952
);
5053

@@ -61,7 +64,7 @@ protected function delete($path, array $parameters = [], array $headers = [])
6164
{
6265
$response = $this->client->getHttpClient()->delete(
6366
$path,
64-
$headers,
67+
array_merge($headers, ['Accept' => 'application/json']),
6568
$this->createJsonBody($parameters)
6669
);
6770

src/Api/Customers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public function all()
1111

1212
public function create($name)
1313
{
14-
return $this->postRaw('/customers/', $this->createJsonBody(['name' => $name]));
14+
return $this->post('/customers/', ['name' => $name]);
1515
}
1616

1717
public function remove($customerId)
@@ -26,7 +26,7 @@ public function listPackages($customerId)
2626

2727
public function addPackages($customerId, array $packages)
2828
{
29-
return $this->postRaw(sprintf('/customers/%s/packages/', $customerId), $this->createJsonBody($packages));
29+
return $this->post(sprintf('/customers/%s/packages/', $customerId), $packages);
3030
}
3131

3232
public function removePackage($customerId, $packageId)

src/HttpClient/HttpPluginClientBuilder.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@
88
use Http\Client\HttpClient;
99
use Http\Discovery\HttpClientDiscovery;
1010
use Http\Discovery\MessageFactoryDiscovery;
11-
use Http\Message\MessageFactory;
1211
use Http\Message\RequestFactory;
1312

1413
class HttpPluginClientBuilder
1514
{
1615
/** @var HttpClient */
1716
private $httpClient;
18-
/** @var HttpMethodsClient */
17+
/** @var HttpMethodsClient|null */
1918
private $pluginClient;
20-
/** @var MessageFactory */
19+
/** @var RequestFactory */
2120
private $requestFactory;
2221
/** @var Plugin[] */
2322
private $plugins = [];

tests/Api/ApiTestCase.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ abstract protected function getApiClass();
1919
*/
2020
protected function getApiMock()
2121
{
22+
/** @var HttpClient&\PHPUnit_Framework_MockObject_MockObject $httpClient */
2223
$httpClient = $this->getMockBuilder(HttpClient::class)
2324
->setMethods(['sendRequest'])
2425
->getMock();
@@ -30,7 +31,7 @@ protected function getApiMock()
3031
$client = new Client(new HttpPluginClientBuilder($httpClient));
3132

3233
return $this->getMockBuilder($this->getApiClass())
33-
->setMethods(['get', 'post', 'postRaw', 'patch', 'delete', 'put', 'head'])
34+
->setMethods(['get', 'post', 'patch', 'delete', 'put', 'head'])
3435
->setConstructorArgs([$client])
3536
->getMock();
3637
}

tests/Api/CustomersTest.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function testAll()
1414
],
1515
];
1616

17-
/** @var Customers $api */
17+
/** @var Customers&\PHPUnit_Framework_MockObject_MockObject $api */
1818
$api = $this->getApiMock();
1919
$api->expects($this->once())
2020
->method('get')
@@ -34,11 +34,11 @@ public function testCreate()
3434
],
3535
];
3636

37-
/** @var Customers $api */
37+
/** @var Customers&\PHPUnit_Framework_MockObject_MockObject $api */
3838
$api = $this->getApiMock();
3939
$api->expects($this->once())
40-
->method('postRaw')
41-
->with($this->equalTo('/customers/'), $this->equalTo(json_encode(['name' => $name])))
40+
->method('post')
41+
->with($this->equalTo('/customers/'), $this->equalTo(['name' => $name]))
4242
->will($this->returnValue($expected));
4343

4444
$this->assertSame($expected, $api->create($name));
@@ -47,7 +47,8 @@ public function testCreate()
4747
public function testRemove()
4848
{
4949
$expected = '';
50-
/** @var Customers $api */
50+
51+
/** @var Customers&\PHPUnit_Framework_MockObject_MockObject $api */
5152
$api = $this->getApiMock();
5253
$api->expects($this->once())
5354
->method('delete')
@@ -66,7 +67,7 @@ public function testListPackages()
6667
],
6768
];
6869

69-
/** @var Customers $api */
70+
/** @var Customers&\PHPUnit_Framework_MockObject_MockObject $api */
7071
$api = $this->getApiMock();
7172
$api->expects($this->once())
7273
->method('get')
@@ -87,11 +88,11 @@ public function testAddPackages()
8788

8889
$packages = [['id' => 1]];
8990

90-
/** @var Customers $api */
91+
/** @var Customers&\PHPUnit_Framework_MockObject_MockObject $api */
9192
$api = $this->getApiMock();
9293
$api->expects($this->once())
93-
->method('postRaw')
94-
->with($this->equalTo('/customers/1/packages/'), json_encode($packages))
94+
->method('post')
95+
->with($this->equalTo('/customers/1/packages/'), $this->equalTo($packages))
9596
->will($this->returnValue($expected));
9697

9798
$this->assertSame($expected, $api->addPackages(1, $packages));
@@ -101,7 +102,7 @@ public function testRemovePackage()
101102
{
102103
$expected = '';
103104

104-
/** @var Customers $api */
105+
/** @var Customers&\PHPUnit_Framework_MockObject_MockObject $api */
105106
$api = $this->getApiMock();
106107
$api->expects($this->once())
107108
->method('delete')

tests/Api/PackagesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function testAll()
1313
],
1414
];
1515

16-
/** @var Packages $api */
16+
/** @var Packages&\PHPUnit_Framework_MockObject_MockObject $api */
1717
$api = $this->getApiMock();
1818
$api->expects($this->once())
1919
->method('get')

tests/HttpClient/Plugin/RequestSignatureTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,24 @@ public function testPrefixRequestPath()
4444
}, function () {
4545
});
4646
}
47+
48+
public function testPrefixRequestPathSmoke()
49+
{
50+
$request = new Request('POST', '/packages/?foo=bar', [], json_encode(['foo' => 'bar']));
51+
$expected = [
52+
'PRIVATE-PACKAGIST-API-TOKEN',
53+
'PRIVATE-PACKAGIST-API-TIMESTAMP',
54+
'PRIVATE-PACKAGIST-API-NONCE',
55+
'PRIVATE-PACKAGIST-API-SIGNATURE',
56+
];
57+
58+
$plugin = new RequestSignature($this->token, $this->secret);
59+
$plugin->handleRequest($request, function (Request $actual) use ($expected) {
60+
$headers = $actual->getHeaders();
61+
foreach ($expected as $header) {
62+
$this->assertNotNull($headers[$header][0]);
63+
}
64+
}, function () {
65+
});
66+
}
4767
}

0 commit comments

Comments
 (0)