From e2c9998a082b8ba0b0e36c60c3bb63073f0a6718 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Wed, 1 May 2024 17:39:38 +0400 Subject: [PATCH] Fix tests --- src/Config/Server/Frontend.php | 2 +- src/Service/Config/ConfigLoader.php | 8 ++++++-- src/Service/Container.php | 2 +- tests/Unit/Service/Config/ConfigLoaderTest.php | 3 ++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Config/Server/Frontend.php b/src/Config/Server/Frontend.php index 77e0aa8d..76ad55bb 100644 --- a/src/Config/Server/Frontend.php +++ b/src/Config/Server/Frontend.php @@ -13,7 +13,7 @@ */ final class Frontend { - /** @var int<1, max> */ + /** @var int<1, 65535> */ #[Env('TRAP_FRONTEND_PORT')] #[CliOption('ui')] #[XPath('/trap/frontend/@port')] diff --git a/src/Service/Config/ConfigLoader.php b/src/Service/Config/ConfigLoader.php index 2a8bb03d..5b6b1196 100644 --- a/src/Service/Config/ConfigLoader.php +++ b/src/Service/Config/ConfigLoader.php @@ -16,6 +16,7 @@ final class ConfigLoader /** * @param null|callable(): non-empty-string $xmlProvider + * @psalm-suppress RiskyTruthyFalsyComparison */ public function __construct( private Logger $logger, @@ -57,7 +58,7 @@ public function hidrate(object $config): void /** * @param \ReflectionProperty $property - * @param array<\ReflectionAttribute> $attributes + * @param list<\ReflectionAttribute> $attributes */ private function injectValue(object $config, \ReflectionProperty $property, array $attributes): void { @@ -65,6 +66,7 @@ private function injectValue(object $config, \ReflectionProperty $property, arra try { $attribute = $attribute->newInstance(); + /** @var mixed $value */ $value = match (true) { $attribute instanceof XPath => $this->xml?->xpath($attribute->path)[$attribute->key], $attribute instanceof Env => \getenv($attribute->name) === false ? null : \getenv($attribute->name), @@ -78,8 +80,10 @@ private function injectValue(object $config, \ReflectionProperty $property, arra // Cast value to the property type $type = $property->getType(); + + /** @var mixed $result */ $result = match (true) { - $type === null => $value, + !$type instanceof \ReflectionNamedType => $value, $type->allowsNull() && $value === '' => null, $type->isBuiltin() => match ($type->getName()) { 'int' => (int) $value, diff --git a/src/Service/Container.php b/src/Service/Container.php index cbb1370c..90508388 100644 --- a/src/Service/Container.php +++ b/src/Service/Container.php @@ -41,7 +41,7 @@ public function __construct() * @param array $arguments Will be used if the object is created for the first time. * @return T * - * @psalm-suppress MoreSpecificImplementedParamType + * @psalm-suppress MoreSpecificImplementedParamType, InvalidReturnType */ public function get(string $id, array $arguments = []): object { diff --git a/tests/Unit/Service/Config/ConfigLoaderTest.php b/tests/Unit/Service/Config/ConfigLoaderTest.php index 97f025fa..b33ed0e4 100644 --- a/tests/Unit/Service/Config/ConfigLoaderTest.php +++ b/tests/Unit/Service/Config/ConfigLoaderTest.php @@ -4,6 +4,7 @@ namespace Buggregator\Trap\Tests\Unit\Service\Config; +use Buggregator\Trap\Logger; use Buggregator\Trap\Service\Config\ConfigLoader; use Buggregator\Trap\Service\Config\XPath; use PHPUnit\Framework\TestCase; @@ -33,7 +34,7 @@ public function testSimpleHydration(): void XML; - $loader = new ConfigLoader(fn() => $xml); + $loader = new ConfigLoader(new Logger(), null, fn() => $xml); $loader->hidrate($dto); self::assertTrue($dto->myBool);