diff --git a/Cache/CacheInterface.php b/Cache/CacheInterface.php index a4fcea731e596d30a126386e1e8b9fc1df5f8b4b..3e4aaf65c48d1a1ce82723847dd68e0180d5c286 100644 --- a/Cache/CacheInterface.php +++ b/Cache/CacheInterface.php @@ -44,7 +44,7 @@ interface CacheInterface * * @throws InvalidArgumentException When $key is not valid or when $beta is negative */ - public function get(string $key, callable $callback, float $beta = null, array &$metadata = null): mixed; + public function get(string $key, callable $callback, ?float $beta = null, ?array &$metadata = null): mixed; /** * Removes an item from the pool. diff --git a/Cache/CacheTrait.php b/Cache/CacheTrait.php index 8a4b0bda8229fd9972adb57dd895688dd46d564b..c2f6580480035b797f5fef04193c01682288171d 100644 --- a/Cache/CacheTrait.php +++ b/Cache/CacheTrait.php @@ -25,7 +25,7 @@ class_exists(InvalidArgumentException::class); */ trait CacheTrait { - public function get(string $key, callable $callback, float $beta = null, array &$metadata = null): mixed + public function get(string $key, callable $callback, ?float $beta = null, ?array &$metadata = null): mixed { return $this->doGet($this, $key, $callback, $beta, $metadata); } @@ -35,7 +35,7 @@ trait CacheTrait return $this->deleteItem($key); } - private function doGet(CacheItemPoolInterface $pool, string $key, callable $callback, ?float $beta, array &$metadata = null, LoggerInterface $logger = null): mixed + private function doGet(CacheItemPoolInterface $pool, string $key, callable $callback, ?float $beta, ?array &$metadata = null, ?LoggerInterface $logger = null): mixed { if (0 > $beta ??= 1.0) { throw new class(sprintf('Argument "$beta" provided to "%s::get()" must be a positive number, %f given.', static::class, $beta)) extends \InvalidArgumentException implements InvalidArgumentException {}; diff --git a/EventDispatcher/EventDispatcherInterface.php b/EventDispatcher/EventDispatcherInterface.php index 610d6ac069d4da624cf2a69c6505195061e341bb..2d7840d32dff4e6ab4461f703e30edb97d8fc4e4 100644 --- a/EventDispatcher/EventDispatcherInterface.php +++ b/EventDispatcher/EventDispatcherInterface.php @@ -29,5 +29,5 @@ interface EventDispatcherInterface extends PsrEventDispatcherInterface * * @return T The passed $event MUST be returned */ - public function dispatch(object $event, string $eventName = null): object; + public function dispatch(object $event, ?string $eventName = null): object; } diff --git a/HttpClient/HttpClientInterface.php b/HttpClient/HttpClientInterface.php index 59636258ff6e318d7487679500926a4a1640bdd7..4bb1dd376a08e94853ec3ca41a4116432885d8fa 100644 --- a/HttpClient/HttpClientInterface.php +++ b/HttpClient/HttpClientInterface.php @@ -90,7 +90,7 @@ interface HttpClientInterface * @param ResponseInterface|iterable<array-key, ResponseInterface> $responses One or more responses created by the current HTTP client * @param float|null $timeout The idle timeout before yielding timeout chunks */ - public function stream(ResponseInterface|iterable $responses, float $timeout = null): ResponseStreamInterface; + public function stream(ResponseInterface|iterable $responses, ?float $timeout = null): ResponseStreamInterface; /** * Returns a new instance of the client with new default options. diff --git a/HttpClient/ResponseInterface.php b/HttpClient/ResponseInterface.php index 62d0f8f52f36bf8765d026099f605bb5e70dcf56..387345cc1afaeeb58b6e7392970beb86e51ca8f4 100644 --- a/HttpClient/ResponseInterface.php +++ b/HttpClient/ResponseInterface.php @@ -105,5 +105,5 @@ interface ResponseInterface * @return mixed An array of all available info, or one of them when $type is * provided, or null when an unsupported type is requested */ - public function getInfo(string $type = null): mixed; + public function getInfo(?string $type = null): mixed; } diff --git a/HttpClient/Test/HttpClientTestCase.php b/HttpClient/Test/HttpClientTestCase.php index 98838ef51ef984e44be3c2df4be80aa33a0e14b1..ec87d06d1f88394b0b5c2ce2f3db84e556e7a0b4 100644 --- a/HttpClient/Test/HttpClientTestCase.php +++ b/HttpClient/Test/HttpClientTestCase.php @@ -28,6 +28,12 @@ abstract class HttpClientTestCase extends TestCase TestHttpServer::start(); } + public static function tearDownAfterClass(): void + { + TestHttpServer::stop(8067); + TestHttpServer::stop(8077); + } + abstract protected function getHttpClient(string $testCase): HttpClientInterface; public function testGetRequest() diff --git a/HttpClient/Test/TestHttpServer.php b/HttpClient/Test/TestHttpServer.php index 86dfa7de9009242d84956af05eaca557ef020f5d..2a278479c2e64eed808b2dac01b4965ce89c1e2e 100644 --- a/HttpClient/Test/TestHttpServer.php +++ b/HttpClient/Test/TestHttpServer.php @@ -45,4 +45,11 @@ class TestHttpServer return $process; } + + public static function stop(int $port = 8057) + { + if (isset(self::$process[$port])) { + self::$process[$port]->stop(); + } + } } diff --git a/Service/Test/ServiceLocatorTestCase.php b/Service/Test/ServiceLocatorTestCase.php index 65a3fe3379e93bcfe6e9f34af339d4a21b417c31..583f72a78ee22a6a255086423d026eeec9521fb8 100644 --- a/Service/Test/ServiceLocatorTestCase.php +++ b/Service/Test/ServiceLocatorTestCase.php @@ -12,9 +12,7 @@ namespace Symfony\Contracts\Service\Test; use PHPUnit\Framework\TestCase; -use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; -use Psr\Container\NotFoundExceptionInterface; use Symfony\Contracts\Service\ServiceLocatorTrait; abstract class ServiceLocatorTestCase extends TestCase @@ -68,29 +66,27 @@ abstract class ServiceLocatorTestCase extends TestCase public function testThrowsOnUndefinedInternalService() { - $locator = $this->getServiceLocator([ - 'foo' => function () use (&$locator) { return $locator->get('bar'); }, - ]); - if (!$this->getExpectedException()) { - $this->expectException(NotFoundExceptionInterface::class); + $this->expectException(\Psr\Container\NotFoundExceptionInterface::class); $this->expectExceptionMessage('The service "foo" has a dependency on a non-existent service "bar". This locator only knows about the "foo" service.'); } + $locator = $this->getServiceLocator([ + 'foo' => function () use (&$locator) { return $locator->get('bar'); }, + ]); $locator->get('foo'); } public function testThrowsOnCircularReference() { + $this->expectException(\Psr\Container\ContainerExceptionInterface::class); + $this->expectExceptionMessage('Circular reference detected for service "bar", path: "bar -> baz -> bar".'); $locator = $this->getServiceLocator([ 'foo' => function () use (&$locator) { return $locator->get('bar'); }, 'bar' => function () use (&$locator) { return $locator->get('baz'); }, 'baz' => function () use (&$locator) { return $locator->get('bar'); }, ]); - $this->expectException(ContainerExceptionInterface::class); - $this->expectExceptionMessage('Circular reference detected for service "bar", path: "bar -> baz -> bar".'); - $locator->get('foo'); } } diff --git a/Translation/Test/TranslatorTest.php b/Translation/Test/TranslatorTest.php index 756228af548a38ad24303a812997bcff7923a4b4..18e669077713aa3c5bc12eb0458996f7a2e9b6a1 100644 --- a/Translation/Test/TranslatorTest.php +++ b/Translation/Test/TranslatorTest.php @@ -183,9 +183,8 @@ class TranslatorTest extends TestCase */ public function testThrowExceptionIfMatchingMessageCannotBeFound($id, $number) { - $translator = $this->getTranslator(); - $this->expectException(\InvalidArgumentException::class); + $translator = $this->getTranslator(); $translator->trans($id, ['%count%' => $number]); } diff --git a/Translation/TranslatableInterface.php b/Translation/TranslatableInterface.php index 47fd6fa029f04b9616f4962a874d3e058b9330dd..8554697ec018d17d94ef48745293f46120e0f097 100644 --- a/Translation/TranslatableInterface.php +++ b/Translation/TranslatableInterface.php @@ -16,5 +16,5 @@ namespace Symfony\Contracts\Translation; */ interface TranslatableInterface { - public function trans(TranslatorInterface $translator, string $locale = null): string; + public function trans(TranslatorInterface $translator, ?string $locale = null): string; } diff --git a/Translation/TranslatorInterface.php b/Translation/TranslatorInterface.php index 018db07ebf4253316324906ca0d1bd3bb688d71e..7fa69878f816d5862174be0455c807479fe9528a 100644 --- a/Translation/TranslatorInterface.php +++ b/Translation/TranslatorInterface.php @@ -59,7 +59,7 @@ interface TranslatorInterface * * @throws \InvalidArgumentException If the locale contains invalid characters */ - public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null): string; + public function trans(string $id, array $parameters = [], ?string $domain = null, ?string $locale = null): string; /** * Returns the default locale. diff --git a/Translation/TranslatorTrait.php b/Translation/TranslatorTrait.php index e3b0adff05980058faa4d3dfb5e27ae90dda8270..63f6fb333da2630b7517d3787e9fac4cf40409aa 100644 --- a/Translation/TranslatorTrait.php +++ b/Translation/TranslatorTrait.php @@ -35,7 +35,7 @@ trait TranslatorTrait return $this->locale ?: (class_exists(\Locale::class) ? \Locale::getDefault() : 'en'); } - public function trans(?string $id, array $parameters = [], string $domain = null, string $locale = null): string + public function trans(?string $id, array $parameters = [], ?string $domain = null, ?string $locale = null): string { if (null === $id || '' === $id) { return ''; diff --git a/composer.json b/composer.json index e016cb8ee0882642398a2132f9920fd1e736717a..b4be947a48d4cf3d8c8ca776c42dee1ab2b5661c 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "require": { "php": ">=8.1", "psr/cache": "^3.0", - "psr/container": "^2.0", + "psr/container": "^1.1|^2.0", "psr/event-dispatcher": "^1.0" }, "require-dev": {