Skip to content

Commit

Permalink
Merge pull request #13 from exonet/rsp/dep-update
Browse files Browse the repository at this point in the history
Dependency updates
  • Loading branch information
styxit authored Oct 19, 2021
2 parents 9e0e818 + c1e000b commit c00db64
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 80 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea
.history
.vscode
/vendor/
composer.lock
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
language: php

php:
- 7.3

services:
- docker

Expand All @@ -9,8 +12,6 @@ cache:
- $HOME/.composer/cache

before_install:
- docker pull php:7.1-cli
- docker pull php:7.2-cli
- docker pull php:7.3-cli
- docker pull php:7.4-cli

Expand Down
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@ All notable changes to `exonet-api-php` will be documented in this file.
Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.

## Unreleased
[Compare v2.4.1 - Unreleased](https://github.com/exonet/exonet-api-php/compare/v2.4.1...master)
[Compare v3.0.0 - Unreleased](https://github.com/exonet/exonet-api-php/compare/v3.0.0...master)

## [v3.0.0](https://github.com/exonet/exonet-api-php/releases/tag/v3.0.0) - 2021-10-19
[Compare v2.4.1 - v3.0.0](https://github.com/exonet/exonet-api-php/compare/v2.4.1...v3.0.0)
### Breaking
- Dependency updates for:
- `php` from `7.1` to `7.3`
- `guzzlehttp/guzzle` from `~6.0` to `~7.3`
- `psr/log` from `^1.0` to `^1.1`

### Changed
- Updated dev dependencies.

## [v2.4.1](https://github.com/exonet/exonet-api-php/releases/tag/v2.4.1) - 2021-01-29
[Compare v2.4.0 - v2.4.1](https://github.com/exonet/exonet-api-php/compare/v2.4.0...v2.4.1)
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
}
],
"require": {
"php": "~7.1",
"guzzlehttp/guzzle": "~6.0",
"psr/log": "^1.0",
"php": "~7.3",
"guzzlehttp/guzzle": "~7.3",
"psr/log": "^1.1",
"ext-json": "*"
},
"require-dev": {
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^7",
"symfony/var-dumper": "^4.0"
"symfony/var-dumper": "^4.0",
"mockery/mockery": "^1.4.2",
"phpunit/phpunit": "^9.3.3"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion examples/dns_record_post.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
// Ask user if record should be updated.
echo sprintf("\n\nDo you want to patch this record? [y/n] ");
if ('Y' === strtoupper(trim(fgets(STDIN)))) {
$newRecord->attribute('content', 'Exonet API PATCH example '.microtime());
$newRecord->attribute('content', '"Exonet API PATCH example '.microtime().'"');
$newRecord->patch();
echo "\nDNS record patched:\n";
echo sprintf(
Expand Down
31 changes: 12 additions & 19 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.0/phpunit.xsd"
backupGlobals="true"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
cacheTokens="false"
colors="true"
>
<testsuites>
<testsuite name="Exonet API">
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="true" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Exonet API">
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
2 changes: 1 addition & 1 deletion run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if [ "$#" -eq 1 ]; then
run "$SET_PHP_VERSION"
else
# Run tests for different PHP 7 versions.
for phpversion in {1..4}; do
for phpversion in {3..4}; do
run "7.$phpversion"
RESULTS="$RESULTS\n"
done
Expand Down
35 changes: 12 additions & 23 deletions tests/ConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
namespace Exonet\Api;

use Exonet\Api\Auth\PersonalAccessToken;
use Exonet\Api\Exceptions\AuthenticationException;
use Exonet\Api\Exceptions\ValidationException;
use Exonet\Api\Structures\ApiResource;
use Exonet\Api\Structures\ApiResourceSet;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
Expand All @@ -22,7 +21,7 @@ class ConnectorTest extends TestCase
/*
* Setup the the resources by using the setup method, because of the object typecasting.
*/
public function setUp()
public function setUp(): void
{
$this->singleResource = (object) [
'data' => [
Expand Down Expand Up @@ -125,8 +124,8 @@ public function testGetInvalidResponse()

$handler = HandlerStack::create($mock);

$this->expectException(AuthenticationException::class);
$this->expectExceptionMessage('Unauthenticated');
$this->expectException(ClientException::class);
$this->expectExceptionMessage('Unauthorized');

new Client(new PersonalAccessToken('test-token'));
$connectorClass = new Connector($handler);
Expand Down Expand Up @@ -212,6 +211,9 @@ public function testDelete()

public function testInvalidPatch()
{
$this->expectException(ClientException::class);
$this->expectExceptionCode(422);

$apiCalls = [];
$mock = new MockHandler([
new Response(
Expand All @@ -229,19 +231,14 @@ public function testInvalidPatch()
$connectorClass = new Connector($handler);

$payload = ['test' => 'demo'];

try {
$connectorClass->patch('url', $payload);
} catch (ValidationException $exception) {
$validationTested = true;
$this->assertSame($exception->getMessage(), 'There is 1 validation error.');
$this->assertCount(1, $exception->getFailedValidations());
$this->assertSame('Validation did not pass.', $exception->getFailedValidations()['generic'][0]);
}
$connectorClass->patch('url', $payload);
}

public function testInvalidDelete()
{
$this->expectException(ClientException::class);
$this->expectExceptionCode(422);

$apiCalls = [];
$mock = new MockHandler([
new Response(
Expand All @@ -259,14 +256,6 @@ public function testInvalidDelete()
$connectorClass = new Connector($handler);

$payload = ['test' => 'demo'];

try {
$connectorClass->patch('url', $payload);
} catch (ValidationException $exception) {
$validationTested = true;
$this->assertSame($exception->getMessage(), 'There is 1 validation error.');
$this->assertCount(1, $exception->getFailedValidations());
$this->assertSame('Validation did not pass.', $exception->getFailedValidations()['generic'][0]);
}
$connectorClass->patch('url', $payload);
}
}
29 changes: 10 additions & 19 deletions tests/Structures/RelationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,12 @@

namespace Exonet\Api\Structures;

use Exonet\Api\Exceptions\InvalidRequestException;
use Exonet\Api\Request;
use PHPUnit\Framework\TestCase;

class RelationTest extends TestCase
{
public function testConstruct()
{
$relationClass = new Relation(
'something_related',
'test_resources',
'ABC1'
);

$this->assertAttributeEquals('something_related', 'name', $relationClass);
$this->assertAttributeInstanceOf(Request::class, 'request', $relationClass);

// Test parsing url pattern to url.
$this->assertAttributeEquals(
'/test_resources/ABC1/something_related',
'url',
$relationClass
);
}

public function testCall()
{
$relationClass = new Relation('testRelation', 'test_resources', 'ABC1');
Expand All @@ -34,4 +16,13 @@ public function testCall()

$this->assertInstanceOf(Request::class, $result);
}

public function testCallRequestNull()
{
$this->expectException(InvalidRequestException::class);

$relationClass = new Relation('testRelation', 'test_resources');

$relationClass->filter('test');
}
}
79 changes: 71 additions & 8 deletions tests/Structures/RelationshipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,89 @@
namespace Exonet\Api\Structures;

use Exonet\Api\Request;
use Mockery;
use PHPUnit\Framework\TestCase;

class RelationshipTest extends TestCase
{
public function testConstruct()
public function testCall()
{
$relationshipClass = new Relationship(
'something_related',
'test_resources',
'ABC1'
);

$this->assertAttributeEquals('something_related', 'name', $relationshipClass);
$this->assertAttributeInstanceOf(Request::class, 'request', $relationshipClass);
$result = $relationshipClass->filter('test');

// Test parsing url pattern to url.
$this->assertAttributeEquals(
'/test_resources/ABC1/relationships/something_related',
'url',
$relationshipClass
$this->assertInstanceOf(Request::class, $result);
}

public function testToJsonNoIdentifier()
{
$relationshipClass = new Relationship(
'something_related',
'test_resources',
'ABC1'
);

$resultJson = $relationshipClass->toJson();

$this->assertNull($resultJson);
}

public function testToJsonSingleRelation()
{
$relationshipClass = new Relationship(
'something_related',
'test_resources',
'ABC1',
);

$relationshipClass->setResourceIdentifiers(new ApiResourceIdentifier('related', 'XYZ'));

$resultJson = $relationshipClass->toJson();

$this->assertSame(
[
'type' => 'related',
'id' => 'XYZ',
],
$resultJson
);
}

public function testToJsonMultiRelation()
{
$relationshipClass = Mockery::mock(
Relationship::class.'[getResourceIdentifiers]',
[
'something_related',
'test_resources',
'ABC1',
]
)
->makePartial();

$relationshipClass->shouldReceive('getResourceIdentifiers')->andReturn([
new ApiResourceIdentifier('related', 'XYZ'),
new ApiResourceIdentifier('related', '999'),
]);

$resultJson = $relationshipClass->toJson();

$this->assertSame(
[
[
'type' => 'related',
'id' => 'XYZ',
],
[
'type' => 'related',
'id' => '999',
],
],
$resultJson
);
}
}

0 comments on commit c00db64

Please sign in to comment.