Skip to content

Commit

Permalink
Merge pull request #2 from ddrv-fork/master
Browse files Browse the repository at this point in the history
Added github actions CI configuration
  • Loading branch information
ddrv committed Nov 4, 2020
2 parents 838c4a4 + 7be9353 commit e4dd3d9
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 27 deletions.
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 @@ -17,8 +17,8 @@
"psr/http-factory": "^1.0"
},
"require-dev": {
"nyholm/psr7": "^1.3",
"phpunit/phpunit": "^6.5",
"guzzlehttp/psr7": "^1.7",
"phpunit/phpunit": ">=6.5",
"squizlabs/php_codesniffer": "^3.5"
},
"suggest": {
Expand All @@ -35,6 +35,7 @@
},
"autoload-dev": {
"psr-4": {
"Stuff\\Webclient\\Helper\\Form\\": "stuff/",
"Tests\\Webclient\\Helper\\Form\\": "tests/"
}
}
Expand Down
1 change: 1 addition & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
<!-- Paths to check -->
<file>src</file>
<file>tests</file>
<file>stuff</file>
</ruleset>
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/HttpFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace Stuff\Webclient\Helper\Form;

use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Stream;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UriInterface;

class HttpFactory implements RequestFactoryInterface, StreamFactoryInterface
{

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

public function createStream(string $content = ''): StreamInterface
{
$resource = fopen('php://temp', 'w+');
fwrite($resource, $content);
rewind($resource);
return $this->createStreamFromResource($resource);
}

public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface
{
$resource = fopen($filename, $mode);
return $this->createStreamFromResource($resource);
}

public function createStreamFromResource($resource): StreamInterface
{
return new Stream($resource);
}
}
25 changes: 3 additions & 22 deletions tests/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
namespace Tests\Webclient\Helper\Form;

use InvalidArgumentException;
use Nyholm\Psr7\Factory\Psr17Factory;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Stuff\Webclient\Helper\Form\HttpFactory;
use Webclient\Helper\Form\Form;

use function dirname;
Expand All @@ -20,24 +18,6 @@
class FormTest extends TestCase
{

/**
* @var ResponseFactoryInterface
*/
private $responseFactory;

/**
* @var StreamFactoryInterface
*/
private $streamFactory;

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

/**
* @param string $method
* @param string $uri
Expand Down Expand Up @@ -266,6 +246,7 @@ public function provideConstruct()

private function getForm(string $uri, string $method): Form
{
return new Form($this->responseFactory, $this->streamFactory, $uri, $method);
$factory = new HttpFactory();
return new Form($factory, $factory, $uri, $method);
}
}
4 changes: 2 additions & 2 deletions tests/WizardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Tests\Webclient\Helper\Form;

use Nyholm\Psr7\Factory\Psr17Factory;
use PHPUnit\Framework\TestCase;
use Stuff\Webclient\Helper\Form\HttpFactory;
use Webclient\Helper\Form\Form;
use Webclient\Helper\Form\Wizard;

Expand All @@ -19,7 +19,7 @@ class WizardTest extends TestCase
*/
public function testCreateForm(string $method, string $uri)
{
$factory = new Psr17Factory();
$factory = new HttpFactory();
$wizard = new Wizard($factory, $factory);
$form = $wizard->createForm($uri, $method);
$this->assertInstanceOf(Form::class, $form);
Expand Down

0 comments on commit e4dd3d9

Please sign in to comment.