Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a62472b

Browse files
authored
Merge pull request #2 from ddrv-fork/master
Added github actions CI configuration
2 parents 795ca69 + 1bc17a2 commit a62472b

File tree

5 files changed

+94
-11
lines changed

5 files changed

+94
-11
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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
"psr/http-server-handler": "^1.0"
2020
},
2121
"require-dev": {
22-
"nyholm/psr7": "^1.3",
23-
"phpunit/phpunit": "^6.5",
22+
"psr/http-factory": "^1.0",
23+
"guzzlehttp/psr7": "^1.7",
24+
"phpunit/phpunit": ">=6.5",
2425
"squizlabs/php_codesniffer": "^3.5"
2526
},
2627
"provide": {

‎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/Factory/HttpFactory.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Webclient\Stuff\Fake\Factory;
6+
7+
use GuzzleHttp\Psr7\Request;
8+
use GuzzleHttp\Psr7\Response;
9+
use GuzzleHttp\Psr7\ServerRequest;
10+
use Psr\Http\Message\RequestFactoryInterface;
11+
use Psr\Http\Message\RequestInterface;
12+
use Psr\Http\Message\ResponseFactoryInterface;
13+
use Psr\Http\Message\ResponseInterface;
14+
use Psr\Http\Message\ServerRequestFactoryInterface;
15+
use Psr\Http\Message\ServerRequestInterface;
16+
use Psr\Http\Message\UriInterface;
17+
18+
class HttpFactory implements RequestFactoryInterface, ServerRequestFactoryInterface, ResponseFactoryInterface
19+
{
20+
21+
/**
22+
* @param string $method
23+
* @param UriInterface|string $uri
24+
* @return RequestInterface
25+
*/
26+
public function createRequest(string $method, $uri): RequestInterface
27+
{
28+
return new Request($method, $uri);
29+
}
30+
31+
/**
32+
* @param string $method
33+
* @param UriInterface|string $uri
34+
* @param array $serverParams
35+
* @return ServerRequestInterface
36+
*/
37+
public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface
38+
{
39+
return new ServerRequest($method, $uri, [], null, '1.1', $serverParams);
40+
}
41+
42+
public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
43+
{
44+
return new Response($code, [], null, '1.1', $reasonPhrase);
45+
}
46+
}

‎tests/ClientTest.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
namespace Webclient\Tests\Fake;
66

77
use Webclient\Fake\Client;
8+
use Webclient\Stuff\Fake\Factory\HttpFactory;
89
use Webclient\Stuff\Fake\Handler\ErrorHandler;
910
use Webclient\Stuff\Fake\Handler\UniversalHandler;
10-
use Nyholm\Psr7\Factory\Psr17Factory;
1111
use PHPUnit\Framework\TestCase;
1212
use Psr\Http\Client\ClientExceptionInterface;
1313
use Psr\Http\Client\NetworkExceptionInterface;
@@ -16,21 +16,16 @@ class ClientTest extends TestCase
1616
{
1717

1818
/**
19-
* @var Psr17Factory
19+
* @var HttpFactory
2020
*/
2121
private $factory;
2222

23-
public function setUp()
24-
{
25-
parent::setUp();
26-
$this->factory = new Psr17Factory();
27-
}
28-
2923
/**
3024
* @throws ClientExceptionInterface
3125
*/
3226
public function testSuccessWithRequest()
3327
{
28+
$this->init();
3429
$request = $this->factory->createRequest('GET', 'http://phpunit.de/?return=302&redirect=https://phpunit.de');
3530
$client = new Client(new UniversalHandler($this->factory));
3631
$response = $client->sendRequest($request);
@@ -44,6 +39,7 @@ public function testSuccessWithRequest()
4439
*/
4540
public function testSuccessWithServerRequest()
4641
{
42+
$this->init();
4743
$request = $this->factory->createServerRequest(
4844
'GET',
4945
'https://phpunit.de',
@@ -64,6 +60,7 @@ public function testSuccessWithServerRequest()
6460
*/
6561
public function testSuccessWithPreparedServerRequest()
6662
{
63+
$this->init();
6764
$request = $this->factory->createServerRequest(
6865
'GET',
6966
'https://phpunit.de',
@@ -83,9 +80,15 @@ public function testSuccessWithPreparedServerRequest()
8380
*/
8481
public function testFailWithNetworkError()
8582
{
83+
$this->init();
8684
$request = $this->factory->createRequest('GET', '/');
8785
$client = new Client(new ErrorHandler());
8886
$this->expectException(NetworkExceptionInterface::class);
8987
$client->sendRequest($request);
9088
}
89+
90+
private function init()
91+
{
92+
$this->factory = new HttpFactory();
93+
}
9194
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /