Skip to content

Commit 9e1fa4e

Browse files
authored
Merge pull request #2 from ddrv-fork/master
Added github actions CI configuration
2 parents 0f3dd40 + 6ec2062 commit 9e1fa4e

File tree

6 files changed

+59
-22
lines changed

6 files changed

+59
-22
lines changed

.github/workflows/ci.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
tests:
7+
runs-on: ubuntu-latest
8+
9+
strategy:
10+
matrix:
11+
php: [7.0, 7.1, 7.2, 7.3, 7.4, 8.0]
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v2
16+
17+
- name: Setup PHP
18+
uses: shivammathur/setup-php@v2
19+
with:
20+
php-version: ${{ matrix.php }}
21+
coverage: none
22+
23+
- name: Validate composer.json and composer.lock
24+
run: composer validate
25+
26+
- name: Install dependencies
27+
run: composer install --prefer-dist --no-progress --no-interaction --no-suggest
28+
29+
- name: Check code style
30+
run: vendor/bin/phpcs
31+
32+
- name: Run test suite
33+
run: vendor/bin/phpunit

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"psr/log": "^1.0"
1818
},
1919
"require-dev": {
20-
"nyholm/psr7": "^1.3",
21-
"phpunit/phpunit": "^6.5",
20+
"guzzlehttp/psr7": "^1.7",
21+
"phpunit/phpunit": ">=6.5",
2222
"squizlabs/php_codesniffer": "^3.5",
2323
"webclient/fake-http-client": "^1.0"
2424
},

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="vendor/autoload.php" colors="true">
2+
<phpunit bootstrap="vendor/autoload.php" colors="true" cacheResult="false">
33
<testsuites>
44
<testsuite name="all">
55
<directory>tests</directory>

stuff/Handler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Stuff\Webclient\Extension\Log;
66

77
use Exception;
8-
use Nyholm\Psr7\Response;
8+
use GuzzleHttp\Psr7\Response;
99
use Psr\Http\Message\ResponseInterface;
1010
use Psr\Http\Message\ServerRequestInterface;
1111
use Psr\Http\Server\RequestHandlerInterface;

tests/LoggedClientTest.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Tests\Webclient\Extension\Log;
66

7-
use Nyholm\Psr7\Request;
7+
use GuzzleHttp\Psr7\Request;
88
use PHPUnit\Framework\TestCase;
99
use Psr\Http\Client\ClientExceptionInterface;
1010
use Psr\Log\LogLevel;
@@ -35,14 +35,6 @@ class LoggedClientTest extends TestCase
3535
*/
3636
private $generator;
3737

38-
public function setUp()
39-
{
40-
parent::setUp();
41-
$this->logger = new Logger();
42-
$this->generator = new StuffIdGenerator($this->getIdGenerator());
43-
$this->formatter = $this->getFormatter();
44-
}
45-
4638
/**
4739
* @param int $status
4840
* @param string $requestLevel
@@ -54,6 +46,7 @@ public function setUp()
5446
*/
5547
public function testLogging(int $status, string $requestLevel, string $responseLevel)
5648
{
49+
$this->init();
5750
$levels = $this->getFreeLevels([$requestLevel, $responseLevel]);
5851
$otherLevel = $levels[0];
5952
$params = [
@@ -89,6 +82,7 @@ public function testLogging(int $status, string $requestLevel, string $responseL
8982
*/
9083
public function testExceptionHandling(string $requestLevel, string $errorLevel)
9184
{
85+
$this->init();
9286
$levels = $this->getFreeLevels([$requestLevel, $errorLevel]);
9387
$otherLevel = $levels[0];
9488
$params = [
@@ -240,4 +234,12 @@ private function getFreeLevels(array $allowed): array
240234
}
241235
return array_keys($levels);
242236
}
237+
238+
private function init()
239+
{
240+
// this code moved from setUp() method for support older phpunit versions
241+
$this->logger = new Logger();
242+
$this->generator = new StuffIdGenerator($this->getIdGenerator());
243+
$this->formatter = $this->getFormatter();
244+
}
243245
}

tests/RawHttpFormatterTest.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace Tests\Webclient\Extension\Log;
66

7-
use Nyholm\Psr7\Request;
8-
use Nyholm\Psr7\Response;
7+
use GuzzleHttp\Psr7\Request;
8+
use GuzzleHttp\Psr7\Response;
99
use PHPUnit\Framework\TestCase;
1010
use Stuff\Webclient\Extension\Log\Error;
1111
use Webclient\Extension\Log\Formatter\RawHttpFormatter;
@@ -23,13 +23,6 @@ class RawHttpFormatterTest extends TestCase
2323
*/
2424
private $formatter;
2525

26-
public function setUp()
27-
{
28-
parent::setUp();
29-
$this->id = 'r1';
30-
$this->formatter = new RawHttpFormatter();
31-
}
32-
3326
/**
3427
* @param string $method
3528
* @param string $uri
@@ -41,6 +34,7 @@ public function setUp()
4134
*/
4235
public function testRequest(string $method, string $uri, array $headers, string $body, string $protocolVersion)
4336
{
37+
$this->init();
4438
$request = new Request($method, $uri, $headers, $body, $protocolVersion);
4539
$expected = 'Request ' . $this->id . PHP_EOL;
4640
$expected .= $method . ' ' . $uri . ' HTTP/' . $protocolVersion . PHP_EOL;
@@ -65,6 +59,7 @@ public function testRequest(string $method, string $uri, array $headers, string
6559
*/
6660
public function testResponse(int $status, string $phrase, array $headers, string $body, string $protocolVersion)
6761
{
62+
$this->init();
6863
$response = new Response($status, $headers, $body, $protocolVersion, $phrase);
6964
$expected = 'Response ' . $this->id . PHP_EOL;
7065
$expected .= 'HTTP/' . $protocolVersion . ' ' . $status . ' ' . $phrase . PHP_EOL;
@@ -82,6 +77,7 @@ public function testResponse(int $status, string $phrase, array $headers, string
8277
*/
8378
public function testError(string $message)
8479
{
80+
$this->init();
8581
$error = new Error($message);
8682
$expected = 'Connection ' . $this->id . PHP_EOL;
8783
$expected .= 'Error: ' . $message;
@@ -115,4 +111,10 @@ public function provideError(): array
115111
['Network error'],
116112
];
117113
}
114+
115+
private function init()
116+
{
117+
$this->id = 'r1';
118+
$this->formatter = new RawHttpFormatter();
119+
}
118120
}

0 commit comments

Comments
 (0)