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 to PHPUnit 10 #561

Merged
merged 1 commit into from
Oct 28, 2024
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/vendor
/.phpcs-cache
.env
clover.xml
.phpunit.result.cache
.phpcs-cache
.phpunit.cache
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"doctrine/coding-standard": "^12.0.0",
"laminas/laminas-diactoros": "^3.5.0",
"laminas/laminas-httphandlerrunner": "^2.11.0",
"phpunit/phpunit": "^9.6.21",
"phpunit/phpunit": "^10.5.38",
"psalm/plugin-phpunit": "^0.19.0",
"roave/infection-static-analysis-plugin": "^1.35.0",
"squizlabs/php_codesniffer": "^3.10.3",
Expand Down
591 changes: 237 additions & 354 deletions composer.lock

Large diffs are not rendered by default.

21 changes: 10 additions & 11 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
colors="true"
verbose="true"
backupGlobals="false"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="true"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
colors="true"
beStrictAboutOutputDuringTests="true"
cacheDirectory=".phpunit.cache"
displayDetailsOnPhpunitDeprecations="true"
>
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<testsuite name="PSR7Session tests">
<directory>./test/StoragelessTest</directory>
</testsuite>
<source>
<include>
<directory>./src</directory>
</include>
</source>
</phpunit>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

namespace PSR7SessionsTest\Storageless\Http\ClientFingerprint;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use PSR7Sessions\Storageless\Http\ClientFingerprint\Configuration;
use PSR7Sessions\Storageless\Http\ClientFingerprint\RemoteAddr;
Expand All @@ -28,7 +29,7 @@

use function array_map;

/** @covers \PSR7Sessions\Storageless\Http\ClientFingerprint\Configuration */
#[CoversClass(Configuration::class)]
final class ConfigurationTest extends TestCase
{
public function testDisabled(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
namespace PSR7SessionsTest\Storageless\Http\ClientFingerprint;

use Laminas\Diactoros\ServerRequest;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use PSR7Sessions\Storageless\Http\ClientFingerprint\RemoteAddr;
use PSR7Sessions\Storageless\Http\ClientFingerprint\SourceMissing;

/**
* @covers \PSR7Sessions\Storageless\Http\ClientFingerprint\RemoteAddr
* @covers \PSR7Sessions\Storageless\Http\ClientFingerprint\SourceMissing
*/
#[CoversClass(RemoteAddr::class)]
#[CoversClass(SourceMissing::class)]
final class RemoteAddrTest extends TestCase
{
private const SERVER_PARAM_NAME = 'REMOTE_ADDR';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Lcobucci\JWT\Token\Plain;
use Lcobucci\JWT\Token\Signature;
use Lcobucci\JWT\Validation\ConstraintViolation;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface;
use PSR7Sessions\Storageless\Http\ClientFingerprint\Configuration;
Expand All @@ -40,7 +41,7 @@

use function strlen;

/** @covers \PSR7Sessions\Storageless\Http\ClientFingerprint\SameOriginRequest */
#[CoversClass(SameOriginRequest::class)]
final class SameOriginRequestTest extends TestCase
{
private const SOURCE_DATA = 'ID';
Expand Down
7 changes: 3 additions & 4 deletions test/StoragelessTest/Http/ClientFingerprint/UserAgentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
namespace PSR7SessionsTest\Storageless\Http\ClientFingerprint;

use Laminas\Diactoros\ServerRequest;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use PSR7Sessions\Storageless\Http\ClientFingerprint\SourceMissing;
use PSR7Sessions\Storageless\Http\ClientFingerprint\UserAgent;

/**
* @covers \PSR7Sessions\Storageless\Http\ClientFingerprint\UserAgent
* @covers \PSR7Sessions\Storageless\Http\ClientFingerprint\SourceMissing
*/
#[CoversClass(UserAgent::class)]
#[CoversClass(SourceMissing::class)]
final class UserAgentTest extends TestCase
{
private const HEADER_NAME = 'User-Agent';
Expand Down
3 changes: 2 additions & 1 deletion test/StoragelessTest/Http/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
use Lcobucci\JWT\Configuration as JwtConfig;
use Lcobucci\JWT\Signer\Hmac\Sha256;
use Lcobucci\JWT\Signer\Key\InMemory;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use PSR7Sessions\Storageless\Http\ClientFingerprint\Configuration as FingerprintConfig;
use PSR7Sessions\Storageless\Http\Configuration;

use function random_bytes;

/** @covers \PSR7Sessions\Storageless\Http\Configuration */
#[CoversClass(Configuration::class)]
final class ConfigurationTest extends TestCase
{
private JwtConfig $jwtConfig;
Expand Down
6 changes: 3 additions & 3 deletions test/StoragelessTest/Http/SessionMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use Lcobucci\JWT\Token\Plain;
use Lcobucci\JWT\Token\RegisteredClaims;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
Expand All @@ -57,7 +58,7 @@
use function time;
use function uniqid;

/** @covers \PSR7Sessions\Storageless\Http\SessionMiddleware */
#[CoversClass(SessionMiddleware::class)]
final class SessionMiddlewareTest extends TestCase
{
private Configuration $config;
Expand Down Expand Up @@ -730,8 +731,7 @@ private function fakeDelegate(callable $callback): RequestHandlerInterface
return $middleware;
}

/** @return ServerRequest */
private function requestWithResponseCookies(ResponseInterface $response): ServerRequestInterface
private function requestWithResponseCookies(ResponseInterface $response): ServerRequest
{
return (new ServerRequest())->withCookieParams([
$this->config->getCookie()->getName() => $this->getCookie($response)->getValue(),
Expand Down
63 changes: 21 additions & 42 deletions test/StoragelessTest/Session/DefaultSessionDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

use JsonException;
use JsonSerializable;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use PSR7Sessions\Storageless\Session\DefaultSessionData;
use ReflectionClass;
Expand All @@ -33,7 +35,7 @@
use const PHP_INT_MAX;
use const PHP_INT_MIN;

/** @covers \PSR7Sessions\Storageless\Session\DefaultSessionData */
#[CoversClass(DefaultSessionData::class)]
final class DefaultSessionDataTest extends TestCase
{
public function testEqualityOfEmptySessions(): void
Expand Down Expand Up @@ -104,11 +106,8 @@ public function testStorageKeysAreConvertedToStringKeys(): void
);
}

/**
* @param int|bool|string|float|mixed[]|object|JsonSerializable|null $value
*
* @dataProvider storageScalarDataProvider
*/
/** @param int|bool|string|float|mixed[]|object|JsonSerializable|null $value */
#[DataProvider('storageScalarDataProvider')]
public function testContainerDataIsStoredAndRetrieved(string $key, int|bool|string|float|array|object|null $value): void
{
$session = DefaultSessionData::newEmptySession();
Expand All @@ -117,11 +116,8 @@ public function testContainerDataIsStoredAndRetrieved(string $key, int|bool|stri
self::assertSame($value, $session->get($key));
}

/**
* @param int|bool|string|float|mixed[]|object|JsonSerializable|null $value
*
* @dataProvider storageScalarDataProvider
*/
/** @param int|bool|string|float|mixed[]|object|JsonSerializable|null $value */
#[DataProvider('storageScalarDataProvider')]
public function testSettingDataInAContainerMarksTheContainerAsMutated(string $key, int|bool|string|float|array|object|null $value): void
{
$session = DefaultSessionData::newEmptySession();
Expand All @@ -146,11 +142,8 @@ public function testChangingTheDataTypeOfAValueIsConsideredAsAChange(): void
self::assertFalse($session->hasChanged());
}

/**
* @param int|bool|string|float|mixed[]|object|JsonSerializable|null $value
*
* @dataProvider storageScalarDataProvider
*/
/** @param int|bool|string|float|mixed[]|object|JsonSerializable|null $value */
#[DataProvider('storageScalarDataProvider')]
public function testContainerIsNotChangedWhenScalarDataIsSetAndOverwrittenInIt(string $key, int|bool|string|float|array|object|null $value): void
{
$session = DefaultSessionData::fromTokenData([$key => $value]);
Expand All @@ -162,11 +155,8 @@ public function testContainerIsNotChangedWhenScalarDataIsSetAndOverwrittenInIt(s
self::assertFalse($session->hasChanged());
}

/**
* @param int|bool|string|float|mixed[]|object|JsonSerializable|null $nonScalarValue
*
* @dataProvider storageNonScalarDataProvider
*/
/** @param int|bool|string|float|mixed[]|object|JsonSerializable|null $nonScalarValue */
#[DataProvider('storageNonScalarDataProvider')]
public function testContainerIsNotChangedWhenNonScalarDataIsSetAndOverwrittenInIt(int|bool|string|float|array|object|null $nonScalarValue): void
{
$session = DefaultSessionData::fromTokenData(['key' => $nonScalarValue]);
Expand All @@ -178,11 +168,8 @@ public function testContainerIsNotChangedWhenNonScalarDataIsSetAndOverwrittenInI
self::assertFalse($session->hasChanged());
}

/**
* @param int|bool|string|float|mixed[]|object|JsonSerializable|null $value
*
* @dataProvider storageScalarDataProvider
*/
/** @param int|bool|string|float|mixed[]|object|JsonSerializable|null $value */
#[DataProvider('storageScalarDataProvider')]
public function testContainerBuiltWithDataContainsData(string $key, int|bool|string|float|array|object|null $value): void
{
$session = DefaultSessionData::fromTokenData([$key => $value]);
Expand All @@ -191,11 +178,8 @@ public function testContainerBuiltWithDataContainsData(string $key, int|bool|str
self::assertSame($value, $session->get($key));
}

/**
* @param int|bool|string|float|mixed[]|object|JsonSerializable|null $value
*
* @dataProvider storageScalarDataProvider
*/
/** @param int|bool|string|float|mixed[]|object|JsonSerializable|null $value */
#[DataProvider('storageScalarDataProvider')]
public function testContainerBuiltWithStdClassContainsData(string $key, int|bool|string|float|array|object|null $value): void
{
if ($key === "\0" || $value === "\0" || $key === '') {
Expand All @@ -211,9 +195,8 @@ public function testContainerBuiltWithStdClassContainsData(string $key, int|bool
/**
* @param int|bool|string|float|mixed[]|object|JsonSerializable|null $nonScalar
* @param int|bool|string|float|mixed[]|null $expectedScalar
*
* @dataProvider storageNonScalarDataProvider
*/
#[DataProvider('storageNonScalarDataProvider')]
public function testContainerStoresScalarValueFromNestedObjects(int|bool|string|float|array|object|null $nonScalar, int|bool|string|float|array|null $expectedScalar): void
{
$session = DefaultSessionData::fromTokenData(['key' => $nonScalar]);
Expand All @@ -225,11 +208,8 @@ public function testContainerStoresScalarValueFromNestedObjects(int|bool|string|
self::assertSame($expectedScalar, $session->get('otherKey'));
}

/**
* @param int|bool|string|float|mixed[]|object|JsonSerializable|null $value
*
* @dataProvider storageScalarDataProvider
*/
/** @param int|bool|string|float|mixed[]|object|JsonSerializable|null $value */
#[DataProvider('storageScalarDataProvider')]
public function testGetWillReturnDefaultValueOnNonExistingKey(string $key, int|bool|string|float|array|object|null $value): void
{
$session = DefaultSessionData::newEmptySession();
Expand All @@ -241,9 +221,8 @@ public function testGetWillReturnDefaultValueOnNonExistingKey(string $key, int|b
/**
* @param int|bool|string|float|mixed[]|object|JsonSerializable|null $nonScalar
* @param int|bool|string|float|mixed[]|null $expectedScalar
*
* @dataProvider storageNonScalarDataProvider
*/
#[DataProvider('storageNonScalarDataProvider')]
public function testGetWillReturnScalarCastDefaultValueOnNonExistingKey(int|bool|string|float|array|object|null $nonScalar, int|bool|string|float|array|null $expectedScalar): void
{
self::assertSame($expectedScalar, DefaultSessionData::newEmptySession()->get('key', $nonScalar));
Expand Down Expand Up @@ -279,7 +258,7 @@ public function testRejectsNonJsonSerializableData(): void
* @return (int|bool|string|float|mixed[]|object|JsonSerializable|null)[][]
* @psalm-return non-empty-array<non-empty-string, array{(int|bool|string|float|object|array<mixed>|null), (int|bool|string|float|array<mixed>|null)}>
*/
public function storageNonScalarDataProvider(): array
public static function storageNonScalarDataProvider(): array
{
return [
'null' => [
Expand Down Expand Up @@ -354,7 +333,7 @@ public function jsonSerialize(): object
* @return (int|bool|string|float|mixed[]|null)[][]
* @psalm-return non-empty-array<non-empty-string, array{string, int|bool|string|float|array<mixed>|null}>
*/
public function storageScalarDataProvider(): array
public static function storageScalarDataProvider(): array
{
return [
'string' => ['foo', 'bar'],
Expand Down
3 changes: 2 additions & 1 deletion test/StoragelessTest/Session/LazySessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

namespace PSR7SessionsTest\Storageless\Session;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use PSR7Sessions\Storageless\Session\LazySession;
Expand All @@ -28,7 +29,7 @@

use function uniqid;

/** @covers \PSR7Sessions\Storageless\Session\LazySession */
#[CoversClass(LazySession::class)]
final class LazySessionTest extends TestCase
{
/** @var SessionInterface&MockObject */
Expand Down