From 2a3169dc6b3667f522d1806f2fac77eab97e7014 Mon Sep 17 00:00:00 2001 From: Ivan Dudarev Date: Wed, 4 Nov 2020 18:32:19 +0700 Subject: [PATCH 1/3] change phpunit version for support PHP 7.0 - 8.0 versions --- composer.json | 2 +- phpunit.xml.dist | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index f0ec57d..be7c38d 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ }, "require-dev": { "nyholm/psr7": "^1.3", - "phpunit/phpunit": "^6.5", + "phpunit/phpunit": ">=6.5", "squizlabs/php_codesniffer": "^3.5" }, "suggest": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 66b98f0..6f90c5c 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,5 @@ - + tests From f0a85ef6c87e430f4a8600c9d1a7bb5cd3816d5e Mon Sep 17 00:00:00 2001 From: Ivan Dudarev Date: Wed, 4 Nov 2020 18:52:55 +0700 Subject: [PATCH 2/3] replace nyholm/psr7 to guzzlehttp/psr7 for PHP 7.0 support --- composer.json | 3 ++- phpcs.xml.dist | 1 + stuff/HttpFactory.php | 46 +++++++++++++++++++++++++++++++++++++++++++ tests/FormTest.php | 25 +++-------------------- tests/WizardTest.php | 4 ++-- 5 files changed, 54 insertions(+), 25 deletions(-) create mode 100644 stuff/HttpFactory.php diff --git a/composer.json b/composer.json index be7c38d..8048419 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "psr/http-factory": "^1.0" }, "require-dev": { - "nyholm/psr7": "^1.3", + "guzzlehttp/psr7": "^1.7", "phpunit/phpunit": ">=6.5", "squizlabs/php_codesniffer": "^3.5" }, @@ -35,6 +35,7 @@ }, "autoload-dev": { "psr-4": { + "Stuff\\Webclient\\Helper\\Form\\": "stuff/", "Tests\\Webclient\\Helper\\Form\\": "tests/" } } diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 7d9a4eb..cfe50aa 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -15,4 +15,5 @@ src tests + stuff \ No newline at end of file diff --git a/stuff/HttpFactory.php b/stuff/HttpFactory.php new file mode 100644 index 0000000..379b1cd --- /dev/null +++ b/stuff/HttpFactory.php @@ -0,0 +1,46 @@ +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); + } +} diff --git a/tests/FormTest.php b/tests/FormTest.php index 63fbf5c..e5c5a5a 100644 --- a/tests/FormTest.php +++ b/tests/FormTest.php @@ -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; @@ -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 @@ -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); } } diff --git a/tests/WizardTest.php b/tests/WizardTest.php index 65f5229..583530a 100644 --- a/tests/WizardTest.php +++ b/tests/WizardTest.php @@ -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; @@ -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); From eb96fe7eeecaa9fb001be413b8f195f0d14395d5 Mon Sep 17 00:00:00 2001 From: Ivan Dudarev Date: Wed, 4 Nov 2020 18:53:51 +0700 Subject: [PATCH 3/3] Added github actions CI configuration --- .github/workflows/ci.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..58bbeb8 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 \ No newline at end of file