Skip to content

Commit e4dd3d9

Browse files
authored
Merge pull request #2 from ddrv-fork/master
Added github actions CI configuration
2 parents 838c4a4 + 7be9353 commit e4dd3d9

File tree

7 files changed

+89
-27
lines changed

7 files changed

+89
-27
lines changed

.github/workflows/ci.yml

+33
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

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"psr/http-factory": "^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
},
2424
"suggest": {
@@ -35,6 +35,7 @@
3535
},
3636
"autoload-dev": {
3737
"psr-4": {
38+
"Stuff\\Webclient\\Helper\\Form\\": "stuff/",
3839
"Tests\\Webclient\\Helper\\Form\\": "tests/"
3940
}
4041
}

phpcs.xml.dist

+1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@
1515
<!-- Paths to check -->
1616
<file>src</file>
1717
<file>tests</file>
18+
<file>stuff</file>
1819
</ruleset>

phpunit.xml.dist

+1-1
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/HttpFactory.php

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Stuff\Webclient\Helper\Form;
6+
7+
use GuzzleHttp\Psr7\Request;
8+
use GuzzleHttp\Psr7\Stream;
9+
use Psr\Http\Message\RequestFactoryInterface;
10+
use Psr\Http\Message\RequestInterface;
11+
use Psr\Http\Message\StreamFactoryInterface;
12+
use Psr\Http\Message\StreamInterface;
13+
use Psr\Http\Message\UriInterface;
14+
15+
class HttpFactory implements RequestFactoryInterface, StreamFactoryInterface
16+
{
17+
18+
/**
19+
* @param string $method
20+
* @param UriInterface|string $uri
21+
* @return RequestInterface
22+
*/
23+
public function createRequest(string $method, $uri): RequestInterface
24+
{
25+
return new Request($method, $uri);
26+
}
27+
28+
public function createStream(string $content = ''): StreamInterface
29+
{
30+
$resource = fopen('php://temp', 'w+');
31+
fwrite($resource, $content);
32+
rewind($resource);
33+
return $this->createStreamFromResource($resource);
34+
}
35+
36+
public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface
37+
{
38+
$resource = fopen($filename, $mode);
39+
return $this->createStreamFromResource($resource);
40+
}
41+
42+
public function createStreamFromResource($resource): StreamInterface
43+
{
44+
return new Stream($resource);
45+
}
46+
}

tests/FormTest.php

+3-22
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
namespace Tests\Webclient\Helper\Form;
66

77
use InvalidArgumentException;
8-
use Nyholm\Psr7\Factory\Psr17Factory;
98
use PHPUnit\Framework\TestCase;
10-
use Psr\Http\Message\ResponseFactoryInterface;
11-
use Psr\Http\Message\StreamFactoryInterface;
9+
use Stuff\Webclient\Helper\Form\HttpFactory;
1210
use Webclient\Helper\Form\Form;
1311

1412
use function dirname;
@@ -20,24 +18,6 @@
2018
class FormTest extends TestCase
2119
{
2220

23-
/**
24-
* @var ResponseFactoryInterface
25-
*/
26-
private $responseFactory;
27-
28-
/**
29-
* @var StreamFactoryInterface
30-
*/
31-
private $streamFactory;
32-
33-
public function setUp()
34-
{
35-
parent::setUp();
36-
$factory = new Psr17Factory();
37-
$this->responseFactory = $factory;
38-
$this->streamFactory = $factory;
39-
}
40-
4121
/**
4222
* @param string $method
4323
* @param string $uri
@@ -266,6 +246,7 @@ public function provideConstruct()
266246

267247
private function getForm(string $uri, string $method): Form
268248
{
269-
return new Form($this->responseFactory, $this->streamFactory, $uri, $method);
249+
$factory = new HttpFactory();
250+
return new Form($factory, $factory, $uri, $method);
270251
}
271252
}

tests/WizardTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace Tests\Webclient\Helper\Form;
66

7-
use Nyholm\Psr7\Factory\Psr17Factory;
87
use PHPUnit\Framework\TestCase;
8+
use Stuff\Webclient\Helper\Form\HttpFactory;
99
use Webclient\Helper\Form\Form;
1010
use Webclient\Helper\Form\Wizard;
1111

@@ -19,7 +19,7 @@ class WizardTest extends TestCase
1919
*/
2020
public function testCreateForm(string $method, string $uri)
2121
{
22-
$factory = new Psr17Factory();
22+
$factory = new HttpFactory();
2323
$wizard = new Wizard($factory, $factory);
2424
$form = $wizard->createForm($uri, $method);
2525
$this->assertInstanceOf(Form::class, $form);

0 commit comments

Comments
 (0)