From 48999734f9db8260fb03982081cafa28dd0abc14 Mon Sep 17 00:00:00 2001 From: Phil Bennett Date: Mon, 26 Jul 2021 08:02:16 +0100 Subject: [PATCH] Fix to ensure inflection is not applied to non object types --- src/Inflector/InflectorAggregate.php | 2 +- tests/Inflector/InflectorAggregateTest.php | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Inflector/InflectorAggregate.php b/src/Inflector/InflectorAggregate.php index d895258..c719332 100644 --- a/src/Inflector/InflectorAggregate.php +++ b/src/Inflector/InflectorAggregate.php @@ -23,7 +23,7 @@ public function add(string $type, callable $callback = null): Inflector return $inflector; } - public function inflect(object $object): object + public function inflect($object) { foreach ($this->getIterator() as $inflector) { $type = $inflector->getType(); diff --git a/tests/Inflector/InflectorAggregateTest.php b/tests/Inflector/InflectorAggregateTest.php index 268cfa1..567cf18 100644 --- a/tests/Inflector/InflectorAggregateTest.php +++ b/tests/Inflector/InflectorAggregateTest.php @@ -55,12 +55,17 @@ public function testNoInflectionIsAttemptedOnNonObjects(): void 'my-generated-array' => [\DateTimeZone::class, 'listIdentifiers'], 'my-generated-number' => 'time', 'my-generated-string' => function (): string { - return bin2hex(random_bytes(8)); + return 'blahblahblah'; }, ]; foreach ($types as $alias => $concrete) { $container->add($alias, $concrete); + + if (is_callable($concrete)) { + $concrete = $concrete(); + } + self::assertSame($container->get($alias), $concrete); } }