Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"autoload-dev": {
"psr-4": {
"Respect\\Config\\": "tests/"
}
},
"classmap": ["tests/Stubs/"]
},
"scripts": {
"coverage": "vendor/bin/phpunit --coverage-text",
Expand Down
27 changes: 0 additions & 27 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,4 @@
<file>tests/</file>

<rule ref="Respect" />

<!-- Instantiator dynamically invokes methods with loosely-typed INI data;
strict_types conflicts with call_user_func coercion requirements -->
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing">
<exclude-pattern>src/Instantiator.php</exclude-pattern>
</rule>

<!-- @var class-string narrowing for PHPStan on dynamic class names from INI -->
<rule ref="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable">
<exclude-pattern>src/</exclude-pattern>
</rule>

<!-- Test files contain inline fixture classes required by the DI container tests -->
<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
<exclude-pattern>tests/</exclude-pattern>
</rule>
<rule ref="Squiz.Classes.ClassFileName.NoMatch">
<exclude-pattern>tests/</exclude-pattern>
</rule>
<rule ref="Squiz.Classes.ValidClassName.NotPascalCase">
<exclude-pattern>tests/</exclude-pattern>
</rule>

<!-- Test fixture properties use snake_case to match INI config keys -->
<rule ref="Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps">
<exclude-pattern>tests/</exclude-pattern>
</rule>
</ruleset>
4 changes: 2 additions & 2 deletions src/IniLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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),
Expand Down
64 changes: 0 additions & 64 deletions tests/AutowireTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> $paths */
public function __construct(public array $paths)
{
}
}

class AutowireWrapper
{
public function __construct(public mixed $inner)
{
}
}
82 changes: 7 additions & 75 deletions tests/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]

Expand All @@ -378,7 +378,6 @@ public function testPascutti(): void

public function testPascuttiTypeHintIssue40(): void
{
$GLOBALS['_MERD_'] = false;
$ini = <<<'INI'
[now DateTime]

Expand Down Expand Up @@ -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;
}
}
5 changes: 0 additions & 5 deletions tests/IniLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,3 @@ private static function parseIni(string $ini): array
return $result;
}
}

class IniLoaderTestConstant
{
public const string VALUE = 'XPTO';
}
65 changes: 0 additions & 65 deletions tests/InstantiatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use stdClass;

use function date_default_timezone_set;
use function func_num_args;
use function get_class;

#[CoversClass(Instantiator::class)]
Expand Down Expand Up @@ -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;
}
}
27 changes: 0 additions & 27 deletions tests/LazyLoadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
14 changes: 1 addition & 13 deletions tests/StaticFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,11 @@ 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');
$this->assertNotEmpty($prop->getValue($i));
$this->assertInstanceOf(DateTime::class, $i->getInstance());
}
}

class StaticTest
{
private function __construct()
{
}

public static function factory(): DateTime
{
return new DateTime();
}
}
Loading
Loading