Skip to content

Commit

Permalink
fixed PHP 8.0 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Aug 13, 2020
1 parent 29e4324 commit 19fe7ae
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/DI/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ private static function autowireArgument(\ReflectionParameter $parameter, callab

} elseif (
$method instanceof \ReflectionMethod
&& $parameter->isArray()
&& $type === 'array'
&& preg_match('#@param[ \t]+([\w\\\\]+)\[\][ \t]+\$' . $parameter->name . '#', (string) $method->getDocComment(), $m)
&& ($itemType = Reflection::expandClassName($m[1], $method->getDeclaringClass()))
&& (class_exists($itemType) || interface_exists($itemType))
Expand Down
45 changes: 25 additions & 20 deletions tests/DI/Compiler.arguments.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,40 @@ class Lorem
}
}

define('MY_CONSTANT_TEST', 'one');

if (PHP_VERSION_ID < 80000) {
Assert::error(function () use (&$container) {
$container = createContainer(new DI\Compiler, '
services:
dolor: Lorem(::MY_FAILING_CONSTANT_TEST)
');
}, E_WARNING, "%a?%Couldn't find constant MY_FAILING_CONSTANT_TEST");
Assert::same([null], $container->getService('dolor')->args[0]);
}



define('MY_CONSTANT_TEST', 'one');

Assert::error(function () use (&$container) {
$container = createContainer(new DI\Compiler, "
services:
lorem:
factory: Lorem(::MY_CONSTANT_TEST, Lorem::DOLOR_SIT, MY_FAILING_CONSTANT_TEST)
setup:
- method( @lorem, @self, @container )
- method( @lorem::add(1, 2), [x: ::strtoupper('hello')] )
- method( [Lorem, method], 'Lorem::add', Lorem::add )
- method( not(true) )
- method( @lorem::var, @self::var, @container::parameters )
- method( @lorem::DOLOR_SIT, @self::DOLOR_SIT )
dolor:
factory: Lorem(::MY_FAILING_CONSTANT_TEST)
");
}, E_WARNING, "%a?%Couldn't find constant MY_FAILING_CONSTANT_TEST");
$container = createContainer(new DI\Compiler, "
services:
lorem:
factory: Lorem(::MY_CONSTANT_TEST, Lorem::DOLOR_SIT, MY_FAILING_CONSTANT_TEST)
setup:
- method( @lorem, @self, @container )
- method( @lorem::add(1, 2), [x: ::strtoupper('hello')] )
- method( [Lorem, method], 'Lorem::add', Lorem::add )
- method( not(true) )
- method( @lorem::var, @self::var, @container::parameters )
- method( @lorem::DOLOR_SIT, @self::DOLOR_SIT )
");

$container->parameters = ['something'];

$lorem = $container->getService('lorem');
$dolor = $container->getService('dolor');

// constants
Assert::same(['one', Lorem::DOLOR_SIT, 'MY_FAILING_CONSTANT_TEST'], $lorem->args[0]);
Assert::same([null], $dolor->args[0]);

// services
Assert::same([$lorem, $lorem, $container], $lorem->args[1]);
Expand Down
6 changes: 3 additions & 3 deletions tests/DI/Compiler.extensionOverride.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ Assert::same([

Assert::exception(function () use ($container) {
$container->getService('one9');
}, TypeError::class, 'Return value of %a%::createServiceOne9() must be an instance of Ipsum, instance of Lorem returned');
}, TypeError::class, '%a% must be %a% Ipsum,%a?% Lorem returned');
Notes::fetch();

Assert::type(Ipsum::class, $container->getService('one10'));
Expand Down Expand Up @@ -243,7 +243,7 @@ Assert::same([

Assert::exception(function () use ($container) {
$container->getService('two11');
}, TypeError::class, 'Return value of %a%::createServiceTwo11() must be an instance of Ipsum, instance of Lorem returned');
}, TypeError::class, '%a% must be %a% Ipsum,%a?% Lorem returned');
Notes::fetch();

Assert::type(Ipsum::class, $container->getService('two12'));
Expand Down Expand Up @@ -290,7 +290,7 @@ Assert::same([

Assert::exception(function () use ($container) {
$container->getService('three8');
}, TypeError::class, 'Return value of %a%::createServiceThree8() must be an instance of Ipsum, instance of Lorem returned');
}, TypeError::class, '%a% must be %a% Ipsum,%a?% Lorem returned');
Notes::fetch();

Assert::type(Ipsum::class, $container->getService('three9'));
Expand Down
2 changes: 1 addition & 1 deletion tests/SearchExtension/parents.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Assert::exception(function () {
in: fixtures
extends: unknown
');
}, ReflectionException::class, 'Class unknown does not exist');
}, ReflectionException::class, 'Class %a?%unknown%a?% does not exist');



Expand Down

0 comments on commit 19fe7ae

Please sign in to comment.