Skip to content

Added github actions CI configuration #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI

on: [push, pull_request]

jobs:
tests:
runs-on: ubuntu-latest

strategy:
matrix:
php: [7.0, 7.1, 7.2, 7.3, 7.4, 8.0]

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-interaction --no-suggest

- name: Check code style
run: vendor/bin/phpcs

- name: Run test suite
run: vendor/bin/phpunit
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
"psr/http-server-handler": "^1.0"
},
"require-dev": {
"nyholm/psr7": "^1.3",
"phpunit/phpunit": "^6.5",
"psr/http-factory": "^1.0",
"guzzlehttp/psr7": "^1.7",
"phpunit/phpunit": ">=6.5",
"squizlabs/php_codesniffer": "^3.5"
},
"provide": {
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php" colors="true">
<phpunit bootstrap="vendor/autoload.php" colors="true" cacheResult="false">
<testsuites>
<testsuite name="all">
<directory>tests</directory>
Expand Down
46 changes: 46 additions & 0 deletions stuff/Factory/HttpFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace Webclient\Stuff\Fake\Factory;

use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\ServerRequest;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestFactoryInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\UriInterface;

class HttpFactory implements RequestFactoryInterface, ServerRequestFactoryInterface, ResponseFactoryInterface
{

/**
* @param string $method
* @param UriInterface|string $uri
* @return RequestInterface
*/
public function createRequest(string $method, $uri): RequestInterface
{
return new Request($method, $uri);
}

/**
* @param string $method
* @param UriInterface|string $uri
* @param array $serverParams
* @return ServerRequestInterface
*/
public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface
{
return new ServerRequest($method, $uri, [], null, '1.1', $serverParams);
}

public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
{
return new Response($code, [], null, '1.1', $reasonPhrase);
}
}
19 changes: 11 additions & 8 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Webclient\Tests\Fake;

use Webclient\Fake\Client;
use Webclient\Stuff\Fake\Factory\HttpFactory;
use Webclient\Stuff\Fake\Handler\ErrorHandler;
use Webclient\Stuff\Fake\Handler\UniversalHandler;
use Nyholm\Psr7\Factory\Psr17Factory;
use PHPUnit\Framework\TestCase;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Client\NetworkExceptionInterface;
Expand All @@ -16,21 +16,16 @@ class ClientTest extends TestCase
{

/**
* @var Psr17Factory
* @var HttpFactory
*/
private $factory;

public function setUp()
{
parent::setUp();
$this->factory = new Psr17Factory();
}

/**
* @throws ClientExceptionInterface
*/
public function testSuccessWithRequest()
{
$this->init();
$request = $this->factory->createRequest('GET', 'http://phpunit.de/?return=302&redirect=https://phpunit.de');
$client = new Client(new UniversalHandler($this->factory));
$response = $client->sendRequest($request);
Expand All @@ -44,6 +39,7 @@ public function testSuccessWithRequest()
*/
public function testSuccessWithServerRequest()
{
$this->init();
$request = $this->factory->createServerRequest(
'GET',
'https://phpunit.de',
Expand All @@ -64,6 +60,7 @@ public function testSuccessWithServerRequest()
*/
public function testSuccessWithPreparedServerRequest()
{
$this->init();
$request = $this->factory->createServerRequest(
'GET',
'https://phpunit.de',
Expand All @@ -83,9 +80,15 @@ public function testSuccessWithPreparedServerRequest()
*/
public function testFailWithNetworkError()
{
$this->init();
$request = $this->factory->createRequest('GET', '/');
$client = new Client(new ErrorHandler());
$this->expectException(NetworkExceptionInterface::class);
$client->sendRequest($request);
}

private function init()
{
$this->factory = new HttpFactory();
}
}