Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit 5284d06

Browse files
authored
Merge pull request cdaguerre#44 from augustohp/maintenance/2-years-catch-up
PHP ecosystem catch up
2 parents 04b5266 + 9ddd3d5 commit 5284d06

22 files changed

+373
-702
lines changed

.travis.yml

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
11
language: php
2-
3-
php:
4-
- 5.3.3
5-
- 5.3
6-
- 5.4
7-
- 5.5
8-
- 5.6
9-
- hhvm
10-
112
sudo: false
3+
matrix:
4+
include:
5+
- php: 5.3
6+
env: DISABLE_TLS="yes"
7+
- php: 5.4
8+
env: DISABLE_TLS="no"
9+
- php: 5.5
10+
env: DISABLE_TLS="no"
11+
- php: 5.6
12+
env: DISABLE_TLS="no"
13+
- php: 7.0
14+
env: DISABLE_TLS="no"
15+
- php: 7.1
16+
env: DISABLE_TLS="no"
17+
- php: hhvm
18+
env: DISABLE_TLS="no"
19+
allow_failures:
20+
- php: 5.3
21+
- php: 5.4
22+
- php: 5.5
23+
- php: hhvm
1224

1325
before_script:
14-
- if [ "$TRAVIS_PHP_VERSION" == "5.3.3" ]; then composer config disable-tls true; fi
15-
- composer self-update
16-
- composer install --no-interaction --prefer-source --dev
26+
- if [ "$DISABLE_TLS" == "yes" ]; then composer config disable-tls true; fi
1727

1828
script:
19-
- mkdir -p build/logs
20-
- phpunit --coverage-clover build/logs/clover.xml
21-
- sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml; fi;'
29+
- composer ci
30+
31+
after_success:
32+
- wget https://scrutinizer-ci.com/ocular.phar
33+
- sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; the php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml; fi;'
34+
35+
# vim: noet ts=2 sw=2 ft=yaml nospell:

composer.json

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,41 @@
11
{
2-
"name": "cdaguerre/php-trello-api",
3-
"type": "library",
4-
"description": "Trello API v1 client",
5-
"homepage": "https://github.com/cdaguerre/php-trello-api",
6-
"keywords": ["trello"],
7-
"license": "MIT",
8-
"authors": [
9-
{
10-
"name": "Christian Daguerre",
11-
"email": "[email protected]"
12-
}
13-
],
14-
"require": {
15-
"php": ">=5.3.2",
16-
"guzzle/guzzle": "~3.7"
17-
},
18-
"require-dev": {
19-
"phpunit/phpunit": ">=4.1"
20-
},
21-
"suggest": {
22-
"symfony/http-foundation": "Needed for the Trello webhook service"
23-
},
24-
"autoload": {
25-
"psr-0": { "Trello\\": "lib/" }
26-
}
2+
"name": "cdaguerre/php-trello-api",
3+
"type": "library",
4+
"description": "Trello API v1 client",
5+
"homepage": "https://github.com/cdaguerre/php-trello-api",
6+
"keywords": ["trello"],
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Christian Daguerre",
11+
"email": "[email protected]"
12+
}
13+
],
14+
"require": {
15+
"php": ">=5.3",
16+
"guzzle/guzzle": "~3.7"
17+
},
18+
"require-dev": {
19+
"phpunit/phpunit": "^4.8"
20+
},
21+
"suggest": {
22+
"symfony/http-foundation": "Needed for the Trello webhook service"
23+
},
24+
"autoload": {
25+
"psr-0": { "Trello\\": "lib/" }
26+
},
27+
"autoload-dev": {
28+
"psr-4": {"Trello\\Tests\\": "test/Trello/Tests"}
29+
},
30+
"scripts": {
31+
"test": [
32+
"@composer install",
33+
"phpunit -v --no-coverage"
34+
],
35+
"ci": [
36+
"mkdir -p build/logs",
37+
"@composer install",
38+
"phpunit --coverage-clover build/logs/clover.xml"
39+
]
40+
}
2741
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Trello\Exception;
4+
5+
class ApiLimitExceedException extends \InvalidArgumentException implements ExceptionInterface
6+
{
7+
8+
}

lib/Trello/HttpClient/Listener/ErrorListener.php

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
use Trello\Exception\RuntimeException;
99
use Trello\Exception\PermissionDeniedException;
1010
use Trello\Exception\ValidationFailedException;
11+
use Trello\Exception\ApiLimitExceedException;
1112

13+
/**
14+
* @TODO Map real errors from Trello API
15+
*/
1216
class ErrorListener
1317
{
1418
/**
@@ -20,46 +24,57 @@ public function onRequestError(Event $event)
2024
$request = $event['request'];
2125
$response = $request->getResponse();
2226

23-
if ($response->isClientError() || $response->isServerError()) {
24-
$content = ResponseMediator::getContent($response);
27+
if (!$response->isClientError() && !$response->isServerError()) {
28+
return;
29+
}
2530

26-
if (is_array($content) && isset($content['message'])) {
27-
if (400 == $response->getStatusCode()) {
28-
throw new ErrorException($content['message'], 400);
29-
} elseif (401 == $response->getStatusCode()) {
30-
throw new PermissionDeniedException($content['message'], 401);
31-
} elseif (422 == $response->getStatusCode() && isset($content['errors'])) {
32-
$errors = array();
33-
foreach ($content['errors'] as $error) {
34-
switch ($error['code']) {
35-
case 'missing':
36-
$errors[] = sprintf('The %s %s does not exist, for resource "%s"', $error['field'], $error['value'], $error['resource']);
37-
break;
31+
switch ($response->getStatusCode()) {
32+
case 429:
33+
throw new ApiLimitExceedException('Wait a second.', 429);
34+
break;
35+
}
3836

39-
case 'missing_field':
40-
$errors[] = sprintf('Field "%s" is missing, for resource "%s"', $error['field'], $error['resource']);
41-
break;
37+
$content = ResponseMediator::getContent($response);
38+
if (is_array($content) && isset($content['message'])) {
39+
if (400 == $response->getStatusCode()) {
40+
throw new ErrorException($content['message'], 400);
41+
}
42+
43+
if (401 == $response->getStatusCode()) {
44+
throw new PermissionDeniedException($content['message'], 401);
45+
}
4246

43-
case 'invalid':
44-
$errors[] = sprintf('Field "%s" is invalid, for resource "%s"', $error['field'], $error['resource']);
45-
break;
47+
if (422 == $response->getStatusCode() && isset($content['errors'])) {
48+
$errors = array();
49+
foreach ($content['errors'] as $error) {
50+
switch ($error['code']) {
51+
case 'missing':
52+
$errors[] = sprintf('The %s %s does not exist, for resource "%s"', $error['field'], $error['value'], $error['resource']);
53+
break;
4654

47-
case 'already_exists':
48-
$errors[] = sprintf('Field "%s" already exists, for resource "%s"', $error['field'], $error['resource']);
49-
break;
55+
case 'missing_field':
56+
$errors[] = sprintf('Field "%s" is missing, for resource "%s"', $error['field'], $error['resource']);
57+
break;
5058

51-
default:
52-
$errors[] = $error['message'];
53-
break;
59+
case 'invalid':
60+
$errors[] = sprintf('Field "%s" is invalid, for resource "%s"', $error['field'], $error['resource']);
61+
break;
5462

55-
}
56-
}
63+
case 'already_exists':
64+
$errors[] = sprintf('Field "%s" already exists, for resource "%s"', $error['field'], $error['resource']);
65+
break;
5766

58-
throw new ValidationFailedException('Validation Failed: '.implode(', ', $errors), 422);
67+
default:
68+
$errors[] = $error['message'];
69+
break;
70+
71+
}
5972
}
73+
74+
throw new ValidationFailedException('Validation Failed: '.implode(', ', $errors), 422);
6075
}
76+
}
6177

62-
throw new RuntimeException(isset($content['message']) ? $content['message'] : $content, $response->getStatusCode());
63-
};
78+
throw new RuntimeException(isset($content['message']) ? $content['message'] : $content, $response->getStatusCode());
6479
}
6580
}

phpunit.xml.dist

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,37 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

33
<phpunit backupGlobals="false"
4-
backupStaticAttributes="false"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false"
11-
syntaxCheck="false"
12-
bootstrap="test/bootstrap.php"
13-
>
14-
<testsuites>
15-
<testsuite name="php-trello-api Test Suite">
16-
<directory>./test/Trello/</directory>
17-
</testsuite>
18-
</testsuites>
4+
backupStaticAttributes="false"
5+
convertErrorsToExceptions="true"
6+
convertNoticesToExceptions="true"
7+
convertWarningsToExceptions="true"
8+
processIsolation="false"
9+
stopOnFailure="false"
10+
syntaxCheck="false"
11+
bootstrap="vendor/autoload.php">
1912

20-
<groups>
21-
<exclude>
22-
<group>functional</group>
23-
</exclude>
24-
</groups>
13+
<php>
14+
<ini name="display_errors" value="1" />
15+
<ini name="error_reporting" value="-1" />
16+
<ini name="date.timezone" value="UTC" />
17+
</php>
18+
<testsuites>
19+
<testsuite name="unit">
20+
<directory>./test/Trello/Tests/Unit/</directory>
21+
</testsuite>
22+
</testsuites>
2523

26-
<filter>
27-
<whitelist>
28-
<directory suffix=".php">./lib/Trello/</directory>
29-
<exclude>
30-
<directory suffix=".php">./lib/Trello/Model</directory>
31-
<directory suffix=".php">./lib/Trello/Event</directory>
32-
<file>./lib/Trello/Service.php</file>
33-
<file>./lib/Trello/Manager.php</file>
34-
</exclude>
35-
</whitelist>
36-
</filter>
37-
38-
<logging>
39-
<log type="coverage-html" target="build/coverage" title="PHP Trello API"
40-
charset="UTF-8" yui="true" highlight="true"
41-
lowUpperBound="35" highLowerBound="70"/>
42-
<log type="coverage-clover" target="build/logs/clover.xml"/>
43-
<log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
44-
</logging>
24+
<filter>
25+
<whitelist>
26+
<directory suffix=".php">./lib/Trello/</directory>
27+
</whitelist>
28+
</filter>
29+
30+
<logging>
31+
<log type="coverage-html" target="build/coverage" title="PHP Trello API"
32+
charset="UTF-8" yui="true" highlight="true"
33+
lowUpperBound="35" highLowerBound="70"/>
34+
<log type="coverage-clover" target="build/logs/clover.xml"/>
35+
<log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
36+
</logging>
4537
</phpunit>

test/Trello/Tests/Functional/Api/BoardTest.php

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)