diff --git a/composer.json b/composer.json
index 6b3fbd9..794c0cf 100644
--- a/composer.json
+++ b/composer.json
@@ -36,7 +36,8 @@
"autoload-dev": {
"psr-4": {
"Respect\\Config\\": "tests/"
- }
+ },
+ "classmap": ["tests/Stubs/"]
},
"scripts": {
"coverage": "vendor/bin/phpunit --coverage-text",
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index d544ad7..26a3201 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -15,31 +15,4 @@
tests/
-
-
-
- src/Instantiator.php
-
-
-
-
- src/
-
-
-
-
- tests/
-
-
- tests/
-
-
- tests/
-
-
-
-
- tests/
-
diff --git a/src/IniLoader.php b/src/IniLoader.php
index 3b9dade..99d2e8e 100644
--- a/src/IniLoader.php
+++ b/src/IniLoader.php
@@ -172,12 +172,12 @@ protected function removeDuplicatedSpaces(string $string): string
protected function parseInstantiator(string $key, mixed $value): void
{
$key = $this->removeDuplicatedSpaces($key);
+ /** @var class-string $keyClass */
[$keyName, $keyClass] = explode(' ', $key, 2);
if ($keyName === 'instanceof') {
$keyName = $keyClass;
}
- /** @var class-string $keyClass */
$instantiator = $this->createInstantiator($keyClass);
if (is_array($value)) {
@@ -198,9 +198,9 @@ protected function createInstantiator(string $keyClass): Instantiator
return new Instantiator($keyClass);
}
+ /** @var class-string $className */
[$modifier, $className] = explode(' ', $keyClass, 2);
- /** @var class-string $className */
return match ($modifier) {
'new' => new Factory($className),
'autowire' => new Autowire($className),
diff --git a/tests/AutowireTest.php b/tests/AutowireTest.php
index 4782942..2c201bb 100644
--- a/tests/AutowireTest.php
+++ b/tests/AutowireTest.php
@@ -340,67 +340,3 @@ private static function parseIni(string $ini): array
return $result;
}
}
-
-class AutowireConsumer
-{
- public function __construct(public DateTime $date)
- {
- }
-}
-
-class AutowireWithBuiltin
-{
- public function __construct(public string $name)
- {
- }
-}
-
-class AutowireDependency
-{
- public function __construct(public string $value = 'default')
- {
- }
-}
-
-class AutowireMultiParam
-{
- public function __construct(public DateTime $date, public AutowireDependency $dep)
- {
- }
-}
-
-class AutowireOptionalDep
-{
- public function __construct(public DateTime $date, public AutowireDependency|null $dep = null)
- {
- }
-}
-
-class AutowireTypedConsumer
-{
- public function __construct(public AutowireDependency $dep)
- {
- }
-}
-
-class AutowireAllOptional
-{
- public function __construct(public DateTime|null $a = null, public DateTime|null $b = null)
- {
- }
-}
-
-class AutowireWithArray
-{
- /** @param array $paths */
- public function __construct(public array $paths)
- {
- }
-}
-
-class AutowireWrapper
-{
- public function __construct(public mixed $inner)
- {
- }
-}
diff --git a/tests/ContainerTest.php b/tests/ContainerTest.php
index 0bd0ff2..63a7a90 100644
--- a/tests/ContainerTest.php
+++ b/tests/ContainerTest.php
@@ -328,19 +328,19 @@ public function testClosureWithIniLoad(): void
public function testLazyLoadinessOnMultipleConfigLevels(): void
{
- $GLOBALS['_SHIT_'] = false;
+ $GLOBALS['_SIDE_EFFECT_'] = false;
$ini = <<<'INI'
-[foo Respect\Config\WheneverIBornIPopulateAGlobalCalled_SHIT_]
+[foo Respect\Config\SideEffectOnConstruct]
child = ""
-[bar Respect\Config\WheneverIBornIPopulateAGlobalCalled_SHIT_]
+[bar Respect\Config\SideEffectOnConstruct]
child = [foo]
-[baz Respect\Config\WheneverIBornIPopulateAGlobalCalled_SHIT_]
+[baz Respect\Config\SideEffectOnConstruct]
child = [bar]
INI;
$c = new Container();
(new IniLoader($c))->fromArray(self::parseIni($ini));
- $this->assertFalse($GLOBALS['_SHIT_']);
- $GLOBALS['_SHIT_'] = false;
+ $this->assertFalse($GLOBALS['_SIDE_EFFECT_']);
+ $GLOBALS['_SIDE_EFFECT_'] = false;
}
public function testSequencesConstructingLazy(): void
@@ -362,7 +362,7 @@ public function testPascutti(): void
$this->markTestSkipped('SQLite PDO driver not available');
}
- $GLOBALS['_SHIT_'] = false;
+ $GLOBALS['_SIDE_EFFECT_'] = false;
$ini = <<<'INI'
[pdo StdClass]
@@ -378,7 +378,6 @@ public function testPascutti(): void
public function testPascuttiTypeHintIssue40(): void
{
- $GLOBALS['_MERD_'] = false;
$ini = <<<'INI'
[now DateTime]
@@ -724,70 +723,3 @@ private static function parseIni(string $ini): array
return $result;
}
}
-
-class Bar
-{
-}
-
-class Foo
-{
- public mixed $bar = null;
-
- public static function hey(DateTime $date): DateTime
- {
- return $date;
- }
-
- public function hello(mixed $some, Bar $bar): void
- {
- $this->bar = $bar;
- }
-}
-
-class WheneverIBornIPopulateAGlobalCalled_SHIT_
-{
- public function __construct()
- {
- $GLOBALS['_SHIT_'] = true;
- }
-}
-
-class DatabaseWow
-{
- public mixed $c;
-
- public function __construct(mixed $con)
- {
- $this->c = $con;
- }
-}
-
-class TypeHintWowMuchType
-{
- public DateTime $d;
-
- public function __construct(DateTime $date)
- {
- $this->d = $date;
- }
-}
-
-class TestConstant
-{
- public const string CONS_TEST = 'XPTO';
-}
-
-class WheneverWithAProperty
-{
- public mixed $test = null;
-}
-
-class PrivateConstructorClass
-{
- public string $value = '';
-
- private function __construct(string $x)
- {
- $this->value = $x;
- }
-}
diff --git a/tests/IniLoaderTest.php b/tests/IniLoaderTest.php
index c5f626c..08cf839 100644
--- a/tests/IniLoaderTest.php
+++ b/tests/IniLoaderTest.php
@@ -412,8 +412,3 @@ private static function parseIni(string $ini): array
return $result;
}
}
-
-class IniLoaderTestConstant
-{
- public const string VALUE = 'XPTO';
-}
diff --git a/tests/InstantiatorTest.php b/tests/InstantiatorTest.php
index 7e72e9c..76cd219 100644
--- a/tests/InstantiatorTest.php
+++ b/tests/InstantiatorTest.php
@@ -11,7 +11,6 @@
use stdClass;
use function date_default_timezone_set;
-use function func_num_args;
use function get_class;
#[CoversClass(Instantiator::class)]
@@ -217,67 +216,3 @@ public function testStaticMethodReturningNonObject(): void
$this->assertTrue($s->ready);
}
}
-
-class StaticNonObjectReturn
-{
- public bool $ready = true;
-
- public static function init(): string
- {
- return 'not_an_object';
- }
-}
-
-class TestClass
-{
- public bool $ok = false;
-
- public bool $myPropertyUsed = false;
-
- public string $myProperty = 'foo';
-
- public function __construct(mixed $foo = null, public mixed $bar = null, public mixed $baz = null)
- {
- if (!$foo) {
- return;
- }
-
- $this->ok = true;
- }
-
- public function usingProperty(): void
- {
- if ($this->myProperty !== 'bar') {
- return;
- }
-
- $this->myPropertyUsed = true;
- }
-
- public function noParams(): void
- {
- if (func_num_args() !== 0) {
- return;
- }
-
- $this->ok = true;
- }
-
- public function oneParam(mixed $ok): void
- {
- if (!$ok) {
- return;
- }
-
- $this->ok = true;
- }
-
- public function twoParams(mixed $ok, mixed $ok2): void
- {
- if (!$ok || !$ok2) {
- return;
- }
-
- $this->ok = true;
- }
-}
diff --git a/tests/LazyLoadTest.php b/tests/LazyLoadTest.php
index b2b19cc..000ec8c 100644
--- a/tests/LazyLoadTest.php
+++ b/tests/LazyLoadTest.php
@@ -54,30 +54,3 @@ public function testLazyLoadedInstance(): void
$this->assertEquals($expected, (string) $container->getItem('hello'));
}
}
-
-class MyLazyLoadedHelloWorldConsumer
-{
- protected string $string;
-
- public function __construct(mixed $hello)
- {
- $this->string = $hello;
- }
-
- public function __toString(): string
- {
- return $this->string;
- }
-}
-
-class MyLazyLoadedHelloWorld
-{
- public function __construct(protected string $string)
- {
- }
-
- public function __toString(): string
- {
- return $this->string;
- }
-}
diff --git a/tests/StaticFactoryTest.php b/tests/StaticFactoryTest.php
index 6111ab9..349c8bf 100644
--- a/tests/StaticFactoryTest.php
+++ b/tests/StaticFactoryTest.php
@@ -16,7 +16,7 @@ final class StaticFactoryTest extends TestCase
{
public function testInstance(): void
{
- $i = new Instantiator(__NAMESPACE__ . '\\StaticTest');
+ $i = new Instantiator(__NAMESPACE__ . '\\StaticFactoryStub');
$i->setParam('factory', [[]]);
$ref = new ReflectionObject($i);
$prop = $ref->getProperty('staticMethodCalls');
@@ -24,15 +24,3 @@ public function testInstance(): void
$this->assertInstanceOf(DateTime::class, $i->getInstance());
}
}
-
-class StaticTest
-{
- private function __construct()
- {
- }
-
- public static function factory(): DateTime
- {
- return new DateTime();
- }
-}
diff --git a/tests/Stubs/AutowireAllOptional.php b/tests/Stubs/AutowireAllOptional.php
new file mode 100644
index 0000000..da4906f
--- /dev/null
+++ b/tests/Stubs/AutowireAllOptional.php
@@ -0,0 +1,14 @@
+ $paths */
+ public function __construct(public array $paths)
+ {
+ }
+}
diff --git a/tests/Stubs/AutowireWithBuiltin.php b/tests/Stubs/AutowireWithBuiltin.php
new file mode 100644
index 0000000..078bab1
--- /dev/null
+++ b/tests/Stubs/AutowireWithBuiltin.php
@@ -0,0 +1,12 @@
+c = $con;
+ }
+}
diff --git a/tests/Stubs/Foo.php b/tests/Stubs/Foo.php
new file mode 100644
index 0000000..20ee380
--- /dev/null
+++ b/tests/Stubs/Foo.php
@@ -0,0 +1,22 @@
+bar = $bar;
+ }
+}
diff --git a/tests/Stubs/IniLoaderTestConstant.php b/tests/Stubs/IniLoaderTestConstant.php
new file mode 100644
index 0000000..87d0e69
--- /dev/null
+++ b/tests/Stubs/IniLoaderTestConstant.php
@@ -0,0 +1,10 @@
+string;
+ }
+}
diff --git a/tests/Stubs/MyLazyLoadedHelloWorldConsumer.php b/tests/Stubs/MyLazyLoadedHelloWorldConsumer.php
new file mode 100644
index 0000000..296083b
--- /dev/null
+++ b/tests/Stubs/MyLazyLoadedHelloWorldConsumer.php
@@ -0,0 +1,20 @@
+string = $hello;
+ }
+
+ public function __toString(): string
+ {
+ return $this->string;
+ }
+}
diff --git a/tests/Stubs/PrivateConstructorClass.php b/tests/Stubs/PrivateConstructorClass.php
new file mode 100644
index 0000000..8df3279
--- /dev/null
+++ b/tests/Stubs/PrivateConstructorClass.php
@@ -0,0 +1,15 @@
+value = $x;
+ }
+}
diff --git a/tests/Stubs/SideEffectOnConstruct.php b/tests/Stubs/SideEffectOnConstruct.php
new file mode 100644
index 0000000..8d51999
--- /dev/null
+++ b/tests/Stubs/SideEffectOnConstruct.php
@@ -0,0 +1,13 @@
+ok = true;
+ }
+
+ public function usingProperty(): void
+ {
+ if ($this->myProperty !== 'bar') {
+ return;
+ }
+
+ $this->myPropertyUsed = true;
+ }
+
+ public function noParams(): void
+ {
+ if (func_num_args() !== 0) {
+ return;
+ }
+
+ $this->ok = true;
+ }
+
+ public function oneParam(mixed $ok): void
+ {
+ if (!$ok) {
+ return;
+ }
+
+ $this->ok = true;
+ }
+
+ public function twoParams(mixed $ok, mixed $ok2): void
+ {
+ if (!$ok || !$ok2) {
+ return;
+ }
+
+ $this->ok = true;
+ }
+}
diff --git a/tests/Stubs/TestConstant.php b/tests/Stubs/TestConstant.php
new file mode 100644
index 0000000..833db93
--- /dev/null
+++ b/tests/Stubs/TestConstant.php
@@ -0,0 +1,10 @@
+d = $date;
+ }
+}
diff --git a/tests/Stubs/WheneverWithAProperty.php b/tests/Stubs/WheneverWithAProperty.php
new file mode 100644
index 0000000..4c1525c
--- /dev/null
+++ b/tests/Stubs/WheneverWithAProperty.php
@@ -0,0 +1,10 @@
+