Skip to content
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

Update dependencies + add support for psr/http-message 2.x #27

Merged
merged 5 commits into from
Dec 17, 2023
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
17 changes: 7 additions & 10 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ jobs:

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

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

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
Expand All @@ -41,26 +41,23 @@ jobs:
strategy:
matrix:
php:
- 7.2
- 7.3
- 7.4
- 8.1
- 8.2
- 8.3
composer-args: [ "" ]
include:
- php: 8.0
composer-args: --ignore-platform-reqs
fail-fast: false

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

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

- name: Cache PHP dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [3.4.0] - 2023-12-15
### Added
- Support for psr/http-message 2.x (if you don't use slim/psr7 or sunrise/http-message as factory)
### Changed
- Updated dependencies and tests

## [3.3.0] - 2021-07-04
### Added
- Support for psr/container v2.x [#26]
Expand Down
27 changes: 12 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,23 @@
"issues": "https://github.com/middlewares/utils/issues"
},
"require": {
"php": "^7.2 || ^8.0",
"psr/http-message": "^1.0",
"php": ">=8.1",
mikespub marked this conversation as resolved.
Show resolved Hide resolved
"psr/http-message": "^1.0 || ^2.0",
"psr/http-server-middleware": "^1.0",
"psr/container": "^1.0 || ^2.0",
"psr/http-factory": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^8|^9",
"phpstan/phpstan": "^0.12",
"laminas/laminas-diactoros": "^2.4",
"friendsofphp/php-cs-fixer": "^v2.16",
"oscarotero/php-cs-fixer-config": "^1.0",
"squizlabs/php_codesniffer": "^3.5",
"slim/psr7": "^1.4",
"guzzlehttp/psr7": "^2.0",
"sunrise/stream": "^1.0.15",
"sunrise/uri": "^1.0.15",
"sunrise/http-message": "^1.0",
"sunrise/http-server-request": "^1.0",
"nyholm/psr7": "^1.0"
"phpunit/phpunit": "^10.5",
"phpstan/phpstan": "^1.10",
"laminas/laminas-diactoros": "^3.3",
"friendsofphp/php-cs-fixer": "^3.41",
"oscarotero/php-cs-fixer-config": "^2.0",
"squizlabs/php_codesniffer": "^3.8",
"slim/psr7": "^1.6",
"guzzlehttp/psr7": "^2.6",
"sunrise/http-message": "^3.0",
"nyholm/psr7": "^1.8"
},
"autoload": {
"psr-4": {
Expand Down
36 changes: 36 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
parameters:
mikespub marked this conversation as resolved.
Show resolved Hide resolved
ignoreErrors:
-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
count: 1
path: src/Dispatcher.php

-
message: "#^Negated boolean expression is always false\\.$#"
count: 1
path: src/Factory.php

-
message: "#^Method Middlewares\\\\Utils\\\\FactoryDiscovery\\:\\:getFactory\\(\\) has no return type specified\\.$#"
count: 1
path: src/FactoryDiscovery.php

-
message: "#^Parameter \\#1 \\$class of function class_exists expects string, array\\<string, class\\-string\\>\\|string given\\.$#"
count: 1
path: src/FactoryDiscovery.php

-
message: "#^Property Middlewares\\\\Utils\\\\FactoryDiscovery\\:\\:\\$factory has no type specified\\.$#"
count: 1
path: src/FactoryDiscovery.php

-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
count: 1
path: src/HttpErrorException.php

-
message: "#^Method Middlewares\\\\Utils\\\\RequestHandlerContainer\\:\\:resolve\\(\\) has no return type specified\\.$#"
count: 1
path: src/RequestHandlerContainer.php
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#
# phpstan at max level leaves a mess for factory
#
includes:
- phpstan-baseline.neon

parameters:
level: max
checkMissingIterableValueType: false
Expand Down
37 changes: 16 additions & 21 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
colors="true"
verbose="true"
failOnWarning="true">
<coverage processUncoveredFiles="true">
<include>
<directory>./src</directory>
</include>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="Skeleton test suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" beStrictAboutOutputDuringTests="true" colors="true" failOnWarning="true" cacheDirectory=".phpunit.cache">
<coverage/>
<testsuites>
<testsuite name="Skeleton test suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>./src</directory>
</include>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</source>
</phpunit>
6 changes: 6 additions & 0 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public static function getRequestFactory(): RequestFactoryInterface
return self::getFactory()->getRequestFactory();
}

/**
* @param UriInterface|string $uri
*/
public static function createRequest(string $method, $uri): RequestInterface
{
return self::getRequestFactory()->createRequest($method, $uri);
Expand All @@ -63,6 +66,9 @@ public static function getServerRequestFactory(): ServerRequestFactoryInterface
return self::getFactory()->getServerRequestFactory();
}

/**
* @param UriInterface|string $uri
*/
public static function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface
{
return self::getServerRequestFactory()->createServerRequest($method, $uri, $serverParams);
Expand Down
14 changes: 7 additions & 7 deletions src/FactoryDiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class FactoryDiscovery implements FactoryInterface
'uri' => '\Laminas\Diactoros\UriFactory',
];

/** @var array<string, class-string> */
/** @var string */
public const GUZZLE = '\GuzzleHttp\Psr7\HttpFactory';

/** @var array<string, class-string> */
Expand All @@ -39,20 +39,20 @@ class FactoryDiscovery implements FactoryInterface
'uri' => '\Slim\Psr7\Factory\UriFactory',
];

/** @var array<string, class-string> */
/** @var string */
public const NYHOLM = '\Nyholm\Psr7\Factory\Psr17Factory';

/** @var array<string, class-string> */
public const SUNRISE = [
'request' => '\Sunrise\Http\Message\RequestFactory',
'response' => '\Sunrise\Http\Message\ResponseFactory',
'serverRequest' => '\Sunrise\Http\ServerRequest\ServerRequestFactory',
'stream' => '\Sunrise\Stream\StreamFactory',
'uploadedFile' => '\Sunrise\Http\ServerRequest\UploadedFileFactory',
'uri' => '\Sunrise\Uri\UriFactory',
'serverRequest' => '\Sunrise\Http\Message\ServerRequestFactory',
'stream' => '\Sunrise\Http\Message\StreamFactory',
'uploadedFile' => '\Sunrise\Http\Message\UploadedFileFactory',
'uri' => '\Sunrise\Http\Message\UriFactory',
];

/** @var array<array<string, class-string>> */
/** @var array<array<string, class-string>|string> */
private $strategies = [
self::DIACTOROS,
self::GUZZLE,
Expand Down
2 changes: 1 addition & 1 deletion src/HttpErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class HttpErrorException extends Exception
{
/** @var array<int, string> */
/** @var array<int, string> */
private static $phrases = [
// CLIENT ERROR
400 => 'Bad Request',
Expand Down
2 changes: 1 addition & 1 deletion src/RequestHandlerContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function has($id): bool
}

/**
* @param mixed $id
* @param string $id
* @return RequestHandlerInterface
*/
public function get($id)
Expand Down
5 changes: 5 additions & 0 deletions tests/Assets/RequestHandlerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@ final class RequestHandlerController implements RequestHandlerInterface
{
public function handle(ServerRequestInterface $request): ResponseInterface
{
$testcase = new TestCase('controller');
/** @var ResponseInterface $stub */
$stub = $testcase->makeStub(ResponseInterface::class);

return $stub;
}
}
18 changes: 18 additions & 0 deletions tests/Assets/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
declare(strict_types = 1);

namespace Middlewares\Tests\Assets;

use PHPUnit\Framework\TestCase as PHPUnit_TestCase;

final class TestCase extends PHPUnit_TestCase
{
/**
* @param class-string $className
* @return mixed
*/
public function makeStub(string $className)
{
return $this->createStub($className);
}
}
12 changes: 6 additions & 6 deletions tests/Factory/FactoryDiactorosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

namespace Middlewares\Tests\Factory;

use Laminas\Diactoros\RequestFactory;
use Laminas\Diactoros\ResponseFactory;
use Laminas\Diactoros\ServerRequestFactory;
use Laminas\Diactoros\StreamFactory;
use Laminas\Diactoros\UploadedFileFactory;
use Laminas\Diactoros\UriFactory;
use Middlewares\Utils\FactoryDiscovery;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\RequestFactoryInterface;
Expand All @@ -11,12 +17,6 @@
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\UploadedFileFactoryInterface;
use Psr\Http\Message\UriFactoryInterface;
use Laminas\Diactoros\RequestFactory;
use Laminas\Diactoros\ResponseFactory;
use Laminas\Diactoros\ServerRequestFactory;
use Laminas\Diactoros\StreamFactory;
use Laminas\Diactoros\UploadedFileFactory;
use Laminas\Diactoros\UriFactory;

class FactoryDiactorosTest extends TestCase
{
Expand Down
8 changes: 4 additions & 4 deletions tests/Factory/FactorySunriseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
use Psr\Http\Message\UriFactoryInterface;
use Sunrise\Http\Message\RequestFactory;
use Sunrise\Http\Message\ResponseFactory;
use Sunrise\Http\ServerRequest\ServerRequestFactory;
use Sunrise\Http\ServerRequest\UploadedFileFactory;
use Sunrise\Stream\StreamFactory;
use Sunrise\Uri\UriFactory;
use Sunrise\Http\Message\ServerRequestFactory;
use Sunrise\Http\Message\StreamFactory;
use Sunrise\Http\Message\UploadedFileFactory;
use Sunrise\Http\Message\UriFactory;

class FactorySunriseTest extends TestCase
{
Expand Down