Skip to content

Commit

Permalink
CI setup
Browse files Browse the repository at this point in the history
  • Loading branch information
glaubinix committed Mar 1, 2018
1 parent fe1607b commit adaae17
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 21 deletions.
27 changes: 27 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
language: php

php:
- 5.6
- 7.0
- 7.1
- 7.2

install: composer install

cache:
directories:
- $HOME/.composer/cache/repo/
- $TRAVIS_BUILD_DIR/vendor/

script:
- vendor/bin/phpunit tests
- vendor/bin/php-cs-fixer fix src
- vendor/bin/php-cs-fixer fix tests

branches:
only:
- master

notifications:
email:
on_success: never
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"php-http/mock-client": "^1.0",
"guzzlehttp/psr7": "^1.2",
"cache/array-adapter": "^0.4",
"phpstan/phpstan": "^0.9.1",
"friendsofphp/php-cs-fixer": "^2.10"
},
"autoload": {
Expand Down
9 changes: 6 additions & 3 deletions src/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ protected function get($path, array $parameters = [], array $headers = [])
if (count($parameters) > 0) {
$path .= '?'.http_build_query($parameters);
}
$response = $this->client->getHttpClient()->get($path, $headers);
$response = $this->client->getHttpClient()->get(
$path,
array_merge($headers, ['Accept' => 'application/json'])
);

return $this->responseMediator->getContent($response);
}
Expand All @@ -44,7 +47,7 @@ protected function post($path, array $parameters = [], array $headers = [])
{
$response = $this->client->getHttpClient()->post(
$path,
$headers,
array_merge($headers, ['Accept' => 'application/json']),
$this->createJsonBody($parameters)
);

Expand All @@ -61,7 +64,7 @@ protected function delete($path, array $parameters = [], array $headers = [])
{
$response = $this->client->getHttpClient()->delete(
$path,
$headers,
array_merge($headers, ['Accept' => 'application/json']),
$this->createJsonBody($parameters)
);

Expand Down
4 changes: 2 additions & 2 deletions src/Api/Customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function all()

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

public function remove($customerId)
Expand All @@ -26,7 +26,7 @@ public function listPackages($customerId)

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

public function removePackage($customerId, $packageId)
Expand Down
5 changes: 2 additions & 3 deletions src/HttpClient/HttpPluginClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
use Http\Client\HttpClient;
use Http\Discovery\HttpClientDiscovery;
use Http\Discovery\MessageFactoryDiscovery;
use Http\Message\MessageFactory;
use Http\Message\RequestFactory;

class HttpPluginClientBuilder
{
/** @var HttpClient */
private $httpClient;
/** @var HttpMethodsClient */
/** @var HttpMethodsClient|null */
private $pluginClient;
/** @var MessageFactory */
/** @var RequestFactory */
private $requestFactory;
/** @var Plugin[] */
private $plugins = [];
Expand Down
3 changes: 2 additions & 1 deletion tests/Api/ApiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ abstract protected function getApiClass();
*/
protected function getApiMock()
{
/** @var HttpClient&\PHPUnit_Framework_MockObject_MockObject $httpClient */
$httpClient = $this->getMockBuilder(HttpClient::class)
->setMethods(['sendRequest'])
->getMock();
Expand All @@ -30,7 +31,7 @@ protected function getApiMock()
$client = new Client(new HttpPluginClientBuilder($httpClient));

return $this->getMockBuilder($this->getApiClass())
->setMethods(['get', 'post', 'postRaw', 'patch', 'delete', 'put', 'head'])
->setMethods(['get', 'post', 'patch', 'delete', 'put', 'head'])
->setConstructorArgs([$client])
->getMock();
}
Expand Down
21 changes: 11 additions & 10 deletions tests/Api/CustomersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function testAll()
],
];

/** @var Customers $api */
/** @var Customers&\PHPUnit_Framework_MockObject_MockObject $api */
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
Expand All @@ -34,11 +34,11 @@ public function testCreate()
],
];

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

$this->assertSame($expected, $api->create($name));
Expand All @@ -47,7 +47,8 @@ public function testCreate()
public function testRemove()
{
$expected = '';
/** @var Customers $api */

/** @var Customers&\PHPUnit_Framework_MockObject_MockObject $api */
$api = $this->getApiMock();
$api->expects($this->once())
->method('delete')
Expand All @@ -66,7 +67,7 @@ public function testListPackages()
],
];

/** @var Customers $api */
/** @var Customers&\PHPUnit_Framework_MockObject_MockObject $api */
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
Expand All @@ -87,11 +88,11 @@ public function testAddPackages()

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

/** @var Customers $api */
/** @var Customers&\PHPUnit_Framework_MockObject_MockObject $api */
$api = $this->getApiMock();
$api->expects($this->once())
->method('postRaw')
->with($this->equalTo('/customers/1/packages/'), json_encode($packages))
->method('post')
->with($this->equalTo('/customers/1/packages/'), $this->equalTo($packages))
->will($this->returnValue($expected));

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

/** @var Customers $api */
/** @var Customers&\PHPUnit_Framework_MockObject_MockObject $api */
$api = $this->getApiMock();
$api->expects($this->once())
->method('delete')
Expand Down
2 changes: 1 addition & 1 deletion tests/Api/PackagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function testAll()
],
];

/** @var Packages $api */
/** @var Packages&\PHPUnit_Framework_MockObject_MockObject $api */
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
Expand Down
20 changes: 20 additions & 0 deletions tests/HttpClient/Plugin/RequestSignatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,24 @@ public function testPrefixRequestPath()
}, function () {
});
}

public function testPrefixRequestPathSmoke()
{
$request = new Request('POST', '/packages/?foo=bar', [], json_encode(['foo' => 'bar']));
$expected = [
'PRIVATE-PACKAGIST-API-TOKEN',
'PRIVATE-PACKAGIST-API-TIMESTAMP',
'PRIVATE-PACKAGIST-API-NONCE',
'PRIVATE-PACKAGIST-API-SIGNATURE',
];

$plugin = new RequestSignature($this->token, $this->secret);
$plugin->handleRequest($request, function (Request $actual) use ($expected) {
$headers = $actual->getHeaders();
foreach ($expected as $header) {
$this->assertNotNull($headers[$header][0]);
}
}, function () {
});
}
}

0 comments on commit adaae17

Please sign in to comment.