Skip to content

Commit bae017c

Browse files
committed
Updated QA settings for 5.1 test utilities
1 parent 921ddd7 commit bae017c

9 files changed

+101
-82
lines changed

Diff for: .php_cs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php declare(strict_types=1);
2+
3+
use ApiClients\Tools\CsFixerConfig\PhpCsFixerConfig;
4+
use PhpCsFixer\Config;
5+
6+
return (function (): Config
7+
{
8+
$paths = [
9+
__DIR__ . DIRECTORY_SEPARATOR . 'src',
10+
__DIR__ . DIRECTORY_SEPARATOR . 'tests',
11+
];
12+
13+
return PhpCsFixerConfig::create()
14+
->setFinder(
15+
PhpCsFixer\Finder::create()
16+
->in($paths)
17+
->append($paths)
18+
)
19+
->setUsingCache(false)
20+
;
21+
})();

Diff for: .travis.yml

+18-29
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,51 @@
11
language: php
2-
sudo: false
32

43
## Cache composer bits
54
cache:
65
directories:
7-
- $HOME/.composer/cache
8-
9-
## PHP versions we test against
10-
php:
11-
- 7.0
12-
- 7.1
13-
- nightly
14-
15-
## Environment variables
16-
env:
17-
- coverage=true
6+
- $HOME/.composer/cache/files
187

198
## Build matrix for lowest and highest possible targets
209
matrix:
2110
include:
22-
- php: 7.0
11+
- php: 7.2
2312
env:
24-
- dependencies=lowest
25-
- coverage=false
26-
- php: 7.1
13+
- qaExtended=true
14+
- dropPlatform=false
15+
- php: nightly
16+
env:
17+
- dropPlatform=false
18+
- php: 7.2
2719
env:
2820
- dependencies=lowest
29-
- coverage=false
21+
- dropPlatform=false
3022
- php: nightly
3123
env:
3224
- dependencies=lowest
33-
- coverage=false
34-
- php: 7.0
35-
env:
36-
- dependencies=highest
37-
- coverage=false
38-
- php: 7.1
25+
- dropPlatform=false
26+
- php: 7.2
3927
env:
4028
- dependencies=highest
41-
- coverage=false
29+
- dropPlatform=false
4230
- php: nightly
4331
env:
4432
- dependencies=highest
45-
- coverage=false
33+
- dropPlatform=false
4634

4735
## Install or update dependencies
4836
install:
4937
- composer validate
50-
- if [ "$coverage" = "false" ]; then phpenv config-rm xdebug.ini || :; fi;
38+
- if [ -z "$dropPlatform" ]; then composer config --unset platform.php; fi;
39+
- if [ -z "$qaExtended" ]; then phpenv config-rm xdebug.ini || :; fi;
5140
- if [ -z "$dependencies" ]; then composer install --prefer-dist; fi;
5241
- if [ "$dependencies" = "lowest" ]; then composer update --prefer-lowest --prefer-dist -n; fi;
5342
- if [ "$dependencies" = "highest" ]; then composer update --prefer-dist -n; fi;
5443
- composer show
5544

5645
## Run the actual test
5746
script:
58-
- if [ "$coverage" = "false" ]; then make ci; fi;
59-
- if [ "$coverage" = "true" ]; then make ci-with-coverage; fi;
47+
- if [ -z "$qaExtended" ]; then make ci; fi;
48+
- if [ "$qaExtended" = "true" ]; then make ci-extended; fi;
6049

6150
## Gather coverage and set it to coverage servers
62-
after_script: make ci-coverage
51+
after_script: if [ "$qaExtended" = "true" ]; then make ci-coverage; fi;

Diff for: Makefile

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ all-coverage:
77
ci:
88
composer run-script qa-ci --timeout=0
99

10-
ci-with-coverage:
11-
composer run-script qa-ci-coverage --timeout=0
10+
ci-extended:
11+
composer run-script qa-ci-extended --timeout=0
1212

1313
contrib:
1414
composer run-script qa-contrib --timeout=0
@@ -19,6 +19,9 @@ init:
1919
cs:
2020
composer cs
2121

22+
cs-fix:
23+
composer cs-fix
24+
2225
unit:
2326
composer run-script unit --timeout=0
2427

Diff for: appveyor.yml

+6-11
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,13 @@ clone_folder: c:\projects\php-project-workspace
77
environment:
88
matrix:
99
- dependencies: lowest
10-
php_ver_target: 7.0
11-
- dependencies: lowest
12-
php_ver_target: 7.1
13-
- dependencies: current
14-
php_ver_target: 7.0
10+
php_ver_target: 7.2
1511
- dependencies: current
16-
php_ver_target: 7.1
17-
- dependencies: highest
18-
php_ver_target: 7.0
12+
php_ver_target: 7.2
1913
- dependencies: highest
20-
php_ver_target: 7.1
14+
php_ver_target: 7.2
2115

22-
## Cache composer bits
16+
## Cache composer file
2317
cache:
2418
- '%LOCALAPPDATA%\Composer\files -> composer.lock'
2519

@@ -33,7 +27,7 @@ init:
3327
## Install PHP and composer, and run the appropriate composer command
3428
install:
3529
- IF EXIST c:\tools\php (SET PHP=0)
36-
- ps: appveyor-retry cinst -y php --version ((choco search php --exact --all-versions -r | select-string -pattern $Env:php_ver_target | Select-Object -first 1) -replace '[php|]','')
30+
- ps: appveyor-retry cinst --params '""/InstallDir:C:\tools\php""' --ignore-checksums -y php --version ((choco search php --exact --all-versions -r | select-string -pattern $env:php_ver_target | sort { [version]($_ -split '\|' | select -last 1) } -Descending | Select-Object -first 1) -replace '[php|]','')
3731
- cd c:\tools\php
3832
- IF %PHP%==1 copy php.ini-production php.ini /Y
3933
- IF %PHP%==1 echo date.timezone="UTC" >> php.ini
@@ -44,6 +38,7 @@ install:
4438
- IF %PHP%==1 echo @php %%~dp0composer.phar %%* > composer.bat
4539
- appveyor-retry appveyor DownloadFile https://getcomposer.org/composer.phar
4640
- cd c:\projects\php-project-workspace
41+
- composer config --unset platform.php
4742
- IF %dependencies%==lowest appveyor-retry composer update --prefer-lowest --no-progress --profile -n
4843
- IF %dependencies%==current appveyor-retry composer install --no-progress --profile
4944
- IF %dependencies%==highest appveyor-retry composer update --no-progress --profile -n

Diff for: composer.json

+11-4
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,20 @@
2727
}
2828
},
2929
"config": {
30-
"sort-packages": true
30+
"sort-packages": true,
31+
"platform": {
32+
"php": "7.2"
33+
}
3134
},
3235
"scripts": {
3336
"ensure-installed": "composer install --ansi -n -q",
3437
"cs": [
3538
"@ensure-installed",
36-
"phpcs --standard=PSR2 src/"
39+
"php-cs-fixer fix --config=.php_cs --ansi --dry-run --diff --verbose --allow-risky=yes --show-progress=estimating"
40+
],
41+
"cs-fix": [
42+
"@ensure-installed",
43+
"php-cs-fixer fix --config=.php_cs --ansi --verbose --allow-risky=yes --show-progress=estimating"
3744
],
3845
"unit": [
3946
"@ensure-installed",
@@ -63,9 +70,9 @@
6370
"@unit"
6471
],
6572
"qa-ci": [
66-
"@qa-all"
73+
"@unit"
6774
],
68-
"qa-ci-coverage": [
75+
"qa-ci-extended": [
6976
"@qa-all-coverage"
7077
],
7178
"qa-ci-windows": [

Diff for: composer.lock

+7-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/AbstractException.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@ abstract class AbstractException extends Exception
1313
private $response;
1414

1515
/**
16-
* @param ResponseInterface $response
17-
* @return AbstractException
16+
* @return ResponseInterface
1817
*/
19-
protected function setResponse(ResponseInterface $response): AbstractException
18+
public function getResponse(): ResponseInterface
2019
{
21-
$this->response = $response;
22-
return $this;
20+
return $this->response;
2321
}
2422

2523
/**
26-
* @return ResponseInterface
24+
* @param ResponseInterface $response
25+
* @return AbstractException
2726
*/
28-
public function getResponse(): ResponseInterface
27+
protected function setResponse(ResponseInterface $response): AbstractException
2928
{
30-
return $this->response;
29+
$this->response = $response;
30+
31+
return $this;
3132
}
3233
}

Diff for: src/ExceptionFactory.php

+8-9
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,21 @@
22

33
namespace ApiClients\Tools\Psr7\HttpStatusExceptions;
44

5-
use ApiClients\Tools\Psr7\HttpStatusExceptions\Unofficial;
65
use Exception as CoreException;
76
use Psr\Http\Message\ResponseInterface;
8-
use function React\Promise\reject;
97

108
final class ExceptionFactory
119
{
1210
const STATUS_CODE_EXCEPTION_MAP = [
1311
/**
14-
* 1xx codes
12+
* 1xx codes.
1513
*/
1614
100 => ContinueException::class,
1715
101 => SwitchingProtocolsException::class,
1816
102 => ProcessingException::class,
1917

2018
/**
21-
* 2xx codes
19+
* 2xx codes.
2220
*/
2321
200 => OKException::class,
2422
201 => CreatedException::class,
@@ -32,7 +30,7 @@ final class ExceptionFactory
3230
226 => IMUsedException::class,
3331

3432
/**
35-
* 3xx codes
33+
* 3xx codes.
3634
*/
3735
300 => MultiChoicesException::class,
3836
301 => MovedPermanentlyException::class,
@@ -45,7 +43,7 @@ final class ExceptionFactory
4543
308 => PermanentRedirectException::class,
4644

4745
/**
48-
* 4xx codes
46+
* 4xx codes.
4947
*/
5048
400 => BadRequestException::class,
5149
401 => UnauthorizedException::class,
@@ -77,7 +75,7 @@ final class ExceptionFactory
7775
451 => UnavailableForLegalReasonsException::class,
7876

7977
/**
80-
* 5xx codes
78+
* 5xx codes.
8179
*/
8280
500 => InternalServerErrorException::class,
8381
501 => NotImplementedException::class,
@@ -92,15 +90,15 @@ final class ExceptionFactory
9290
511 => NetworkAuthenticationRequiredException::class,
9391

9492
/**
95-
* IIS (Unofficial)
93+
* IIS (Unofficial).
9694
*
9795
* Excluding the 451 as it conflicts with the official 451 code.
9896
*/
9997
440 => Unofficial\IIS\LoginTimeoutException::class,
10098
449 => Unofficial\IIS\RetryWithException::class,
10199

102100
/**
103-
* Cloudflare (Unofficial)
101+
* Cloudflare (Unofficial).
104102
*/
105103
520 => Unofficial\Cloudflare\UnknownErrorException::class,
106104
521 => Unofficial\Cloudflare\WebServerIsDownException::class,
@@ -115,6 +113,7 @@ final class ExceptionFactory
115113
public static function create(ResponseInterface $response, CoreException $previousException)
116114
{
117115
$exception = static::STATUS_CODE_EXCEPTION_MAP[$response->getStatusCode()];
116+
118117
return $exception::create($response, $previousException);
119118
}
120119
}

Diff for: tests/ExceptionFactoryTest.php

+16-15
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
namespace ApiClients\Tests\Tools\Psr7\HttpStatusExceptions;
44

55
use ApiClients\Tools\Psr7\HttpStatusExceptions;
6-
use Exception as CoreException;
76
use ApiClients\Tools\TestUtilities\TestCase;
7+
use Exception as CoreException;
88
use Psr\Http\Message\ResponseInterface;
99
use RingCentral\Psr7\Response;
1010

@@ -17,20 +17,6 @@ public function provideExceptions()
1717
}
1818
}
1919

20-
private function createDataSet(int $code, string $exception)
21-
{
22-
$previousException = new CoreException('foo.bar');
23-
$response = new Response($code);
24-
$expectedException = $exception::create($response, $previousException);
25-
return [
26-
$code,
27-
$exception,
28-
$response,
29-
$previousException,
30-
$expectedException,
31-
];
32-
}
33-
3420
/**
3521
* @dataProvider provideExceptions
3622
*/
@@ -51,4 +37,19 @@ public function testCreate(
5137
self::assertInstanceOf(ResponseInterface::class, $result->getResponse());
5238
self::assertEquals($response, $result->getResponse());
5339
}
40+
41+
private function createDataSet(int $code, string $exception)
42+
{
43+
$previousException = new CoreException('foo.bar');
44+
$response = new Response($code);
45+
$expectedException = $exception::create($response, $previousException);
46+
47+
return [
48+
$code,
49+
$exception,
50+
$response,
51+
$previousException,
52+
$expectedException,
53+
];
54+
}
5455
}

0 commit comments

Comments
 (0)