-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
806292c
commit dd1f47f
Showing
14 changed files
with
303 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace PrinsFrank\Container\Tests\Unit\Definition; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\TestCase; | ||
use PrinsFrank\Container\Container; | ||
use PrinsFrank\Container\Definition\DefinitionSet; | ||
use PrinsFrank\Container\Resolver\ParameterResolver; | ||
|
||
#[CoversClass(DefinitionSet::class)] | ||
class DefinitionSetTest extends TestCase { | ||
public function testConstruct(): void { | ||
$definitionSet = new DefinitionSet($container = new Container(), $parameterResolver = new ParameterResolver($container)); | ||
|
||
static::assertSame($container, $definitionSet->forContainer); | ||
static::assertSame($parameterResolver, $definitionSet->parameterResolver); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace PrinsFrank\Container\Tests\Unit\Definition\Item; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\TestCase; | ||
use PrinsFrank\Container\Container; | ||
use PrinsFrank\Container\Definition\Item\AbstractConcrete; | ||
use PrinsFrank\Container\Exception\InvalidArgumentException; | ||
use PrinsFrank\Container\Exception\InvalidMethodException; | ||
use PrinsFrank\Container\Exception\InvalidServiceProviderException; | ||
use PrinsFrank\Container\Exception\MissingDefinitionException; | ||
use PrinsFrank\Container\Exception\UnresolvableException; | ||
use PrinsFrank\Container\Resolver\ParameterResolver; | ||
use PrinsFrank\Container\Tests\Fixtures\AbstractBImplementsInterfaceA; | ||
use PrinsFrank\Container\Tests\Fixtures\ConcreteCExtendsAbstractBImplementsInterfaceA; | ||
use PrinsFrank\Container\Tests\Fixtures\InterfaceA; | ||
use stdClass; | ||
|
||
#[CoversClass(AbstractConcrete::class)] | ||
class AbstractConcreteTest extends TestCase { | ||
/** @throws InvalidArgumentException */ | ||
public function testIsForThrowsExceptionOnNonAbstractClass(): void { | ||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage('Argument $identifier is expected to be a class-string for an interface or abstract class'); | ||
new AbstractConcrete(ConcreteCExtendsAbstractBImplementsInterfaceA::class, fn () => null); | ||
} | ||
|
||
/** @throws InvalidArgumentException */ | ||
public function testIsFor(): void { | ||
$abstractConcrete = new AbstractConcrete(InterfaceA::class, fn () => null); | ||
|
||
static::assertTrue($abstractConcrete->isFor(InterfaceA::class)); | ||
static::assertFalse($abstractConcrete->isFor(AbstractBImplementsInterfaceA::class)); | ||
static::assertFalse($abstractConcrete->isFor(ConcreteCExtendsAbstractBImplementsInterfaceA::class)); | ||
} | ||
|
||
/** @throws InvalidServiceProviderException|MissingDefinitionException|UnresolvableException|InvalidMethodException|InvalidArgumentException */ | ||
public function testResolveThrowsExceptionWhenClosureReturnsInvalidType(): void { | ||
/** @phpstan-ignore argument.type */ | ||
$abstractConcrete = new AbstractConcrete(InterfaceA::class, fn () => 42); | ||
|
||
$this->expectException(InvalidServiceProviderException::class); | ||
$this->expectExceptionMessage('Closure returned type "integer" instead of concrete for "' . InterfaceA::class . '"'); | ||
$abstractConcrete->get($container = new Container(), new ParameterResolver($container)); | ||
} | ||
|
||
/** @throws InvalidServiceProviderException|MissingDefinitionException|UnresolvableException|InvalidMethodException|InvalidArgumentException */ | ||
public function testResolveThrowsExceptionWhenClosureReturnsInvalidClassType(): void { | ||
$abstractConcrete = new AbstractConcrete(InterfaceA::class, fn () => new stdClass()); | ||
|
||
$this->expectException(InvalidServiceProviderException::class); | ||
$this->expectExceptionMessage('Closure returned type "stdClass" instead of concrete for "' . InterfaceA::class . '"'); | ||
$abstractConcrete->get($container = new Container(), new ParameterResolver($container)); | ||
} | ||
|
||
/** @throws InvalidServiceProviderException|MissingDefinitionException|UnresolvableException|InvalidMethodException|InvalidArgumentException */ | ||
public function testResolve(): void { | ||
$concrete = new ConcreteCExtendsAbstractBImplementsInterfaceA(); | ||
$abstractConcrete = new AbstractConcrete(InterfaceA::class, fn () => $concrete); | ||
|
||
static::assertSame( | ||
$concrete, | ||
$abstractConcrete->get($container = new Container(), new ParameterResolver($container)), | ||
); | ||
} | ||
|
||
/** @throws InvalidServiceProviderException|MissingDefinitionException|UnresolvableException|InvalidMethodException|InvalidArgumentException */ | ||
public function testResolveAllowsNullValue(): void { | ||
$abstractConcrete = new AbstractConcrete(InterfaceA::class, fn () => null); | ||
|
||
static::assertNull($abstractConcrete->get($container = new Container(), new ParameterResolver($container))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace PrinsFrank\Container\Tests\Unit\Definition\Item; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\TestCase; | ||
use PrinsFrank\Container\Container; | ||
use PrinsFrank\Container\Definition\Item\Concrete; | ||
use PrinsFrank\Container\Exception\InvalidArgumentException; | ||
use PrinsFrank\Container\Exception\InvalidMethodException; | ||
use PrinsFrank\Container\Exception\InvalidServiceProviderException; | ||
use PrinsFrank\Container\Exception\MissingDefinitionException; | ||
use PrinsFrank\Container\Exception\UnresolvableException; | ||
use PrinsFrank\Container\Resolver\ParameterResolver; | ||
use PrinsFrank\Container\Tests\Fixtures\AbstractBImplementsInterfaceA; | ||
use PrinsFrank\Container\Tests\Fixtures\ConcreteCExtendsAbstractBImplementsInterfaceA; | ||
use PrinsFrank\Container\Tests\Fixtures\InterfaceA; | ||
use stdClass; | ||
|
||
#[CoversClass(Concrete::class)] | ||
class ConcreteTest extends TestCase { | ||
/** @throws InvalidArgumentException */ | ||
public function testIsForThrowsExceptionOnAbstractClass(): void { | ||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage('Argument $identifier is expected to be a class-string for a concrete class'); | ||
new Concrete(AbstractBImplementsInterfaceA::class, fn () => null); | ||
} | ||
|
||
/** @throws InvalidArgumentException */ | ||
public function testIsForThrowsExceptionOnInterface(): void { | ||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage('Argument $identifier is expected to be a class-string for a concrete class'); | ||
new Concrete(InterfaceA::class, fn () => null); | ||
} | ||
|
||
/** @throws InvalidArgumentException */ | ||
public function testIsFor(): void { | ||
$abstractConcrete = new Concrete(ConcreteCExtendsAbstractBImplementsInterfaceA::class, fn () => null); | ||
|
||
static::assertFalse($abstractConcrete->isFor(InterfaceA::class)); | ||
static::assertFalse($abstractConcrete->isFor(AbstractBImplementsInterfaceA::class)); | ||
static::assertTrue($abstractConcrete->isFor(ConcreteCExtendsAbstractBImplementsInterfaceA::class)); | ||
} | ||
|
||
/** @throws InvalidServiceProviderException|MissingDefinitionException|UnresolvableException|InvalidMethodException|InvalidArgumentException */ | ||
public function testResolveThrowsExceptionWhenClosureReturnsInvalidType(): void { | ||
/** @phpstan-ignore argument.type */ | ||
$abstractConcrete = new Concrete(ConcreteCExtendsAbstractBImplementsInterfaceA::class, fn () => 42); | ||
|
||
$this->expectException(InvalidServiceProviderException::class); | ||
$this->expectExceptionMessage('Closure returned type "integer" instead of "' . ConcreteCExtendsAbstractBImplementsInterfaceA::class . '"'); | ||
$abstractConcrete->get($container = new Container(), new ParameterResolver($container)); | ||
} | ||
|
||
/** @throws InvalidServiceProviderException|MissingDefinitionException|UnresolvableException|InvalidMethodException|InvalidArgumentException */ | ||
public function testResolveThrowsExceptionWhenClosureReturnsInvalidClassType(): void { | ||
$abstractConcrete = new Concrete(ConcreteCExtendsAbstractBImplementsInterfaceA::class, fn () => new stdClass()); | ||
|
||
$this->expectException(InvalidServiceProviderException::class); | ||
$this->expectExceptionMessage('Closure returned type "stdClass" instead of "' . ConcreteCExtendsAbstractBImplementsInterfaceA::class . '"'); | ||
$abstractConcrete->get($container = new Container(), new ParameterResolver($container)); | ||
} | ||
|
||
/** @throws InvalidServiceProviderException|MissingDefinitionException|UnresolvableException|InvalidMethodException|InvalidArgumentException */ | ||
public function testResolve(): void { | ||
$concrete = new ConcreteCExtendsAbstractBImplementsInterfaceA(); | ||
$abstractConcrete = new Concrete(ConcreteCExtendsAbstractBImplementsInterfaceA::class, fn () => $concrete); | ||
|
||
static::assertSame( | ||
$concrete, | ||
$abstractConcrete->get($container = new Container(), new ParameterResolver($container)), | ||
); | ||
} | ||
|
||
/** @throws InvalidServiceProviderException|MissingDefinitionException|UnresolvableException|InvalidMethodException|InvalidArgumentException */ | ||
public function testResolveAllowsNullValue(): void { | ||
$abstractConcrete = new Concrete(ConcreteCExtendsAbstractBImplementsInterfaceA::class, fn () => null); | ||
|
||
static::assertNull($abstractConcrete->get($container = new Container(), new ParameterResolver($container))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace PrinsFrank\Container\Tests\Unit\Definition\Item; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\TestCase; | ||
use PrinsFrank\Container\Container; | ||
use PrinsFrank\Container\Definition\Item\Singleton; | ||
use PrinsFrank\Container\Exception\InvalidArgumentException; | ||
use PrinsFrank\Container\Exception\InvalidMethodException; | ||
use PrinsFrank\Container\Exception\InvalidServiceProviderException; | ||
use PrinsFrank\Container\Exception\MissingDefinitionException; | ||
use PrinsFrank\Container\Exception\UnresolvableException; | ||
use PrinsFrank\Container\Resolver\ParameterResolver; | ||
use PrinsFrank\Container\Tests\Fixtures\AbstractBImplementsInterfaceA; | ||
use PrinsFrank\Container\Tests\Fixtures\ConcreteCExtendsAbstractBImplementsInterfaceA; | ||
use PrinsFrank\Container\Tests\Fixtures\InterfaceA; | ||
use stdClass; | ||
|
||
#[CoversClass(Singleton::class)] | ||
class SingletonTest extends TestCase { | ||
/** @throws InvalidArgumentException */ | ||
public function testIsForThrowsExceptionOnAbstractClass(): void { | ||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage('Argument $identifier is expected to be a class-string for a concrete class'); | ||
new Singleton(AbstractBImplementsInterfaceA::class, fn () => null); | ||
} | ||
|
||
/** @throws InvalidArgumentException */ | ||
public function testIsForThrowsExceptionOnInterface(): void { | ||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage('Argument $identifier is expected to be a class-string for a concrete class'); | ||
new Singleton(InterfaceA::class, fn () => null); | ||
} | ||
|
||
/** @throws InvalidArgumentException */ | ||
public function testIsFor(): void { | ||
$abstractConcrete = new Singleton(ConcreteCExtendsAbstractBImplementsInterfaceA::class, fn () => null); | ||
|
||
static::assertFalse($abstractConcrete->isFor(InterfaceA::class)); | ||
static::assertFalse($abstractConcrete->isFor(AbstractBImplementsInterfaceA::class)); | ||
static::assertTrue($abstractConcrete->isFor(ConcreteCExtendsAbstractBImplementsInterfaceA::class)); | ||
} | ||
|
||
/** @throws InvalidServiceProviderException|MissingDefinitionException|UnresolvableException|InvalidMethodException|InvalidArgumentException */ | ||
public function testResolveThrowsExceptionWhenClosureReturnsInvalidType(): void { | ||
/** @phpstan-ignore argument.type */ | ||
$abstractConcrete = new Singleton(ConcreteCExtendsAbstractBImplementsInterfaceA::class, fn () => 42); | ||
|
||
$this->expectException(InvalidServiceProviderException::class); | ||
$this->expectExceptionMessage('Closure returned type "integer" instead of "' . ConcreteCExtendsAbstractBImplementsInterfaceA::class . '"'); | ||
$abstractConcrete->get($container = new Container(), new ParameterResolver($container)); | ||
} | ||
|
||
/** @throws InvalidServiceProviderException|MissingDefinitionException|UnresolvableException|InvalidMethodException|InvalidArgumentException */ | ||
public function testResolveThrowsExceptionWhenClosureReturnsInvalidClassType(): void { | ||
$abstractConcrete = new Singleton(ConcreteCExtendsAbstractBImplementsInterfaceA::class, fn () => new stdClass()); | ||
|
||
$this->expectException(InvalidServiceProviderException::class); | ||
$this->expectExceptionMessage('Closure returned type "stdClass" instead of "' . ConcreteCExtendsAbstractBImplementsInterfaceA::class . '"'); | ||
$abstractConcrete->get($container = new Container(), new ParameterResolver($container)); | ||
} | ||
|
||
/** @throws InvalidServiceProviderException|MissingDefinitionException|UnresolvableException|InvalidMethodException|InvalidArgumentException */ | ||
public function testResolve(): void { | ||
$concrete = new ConcreteCExtendsAbstractBImplementsInterfaceA(); | ||
$abstractConcrete = new Singleton(ConcreteCExtendsAbstractBImplementsInterfaceA::class, fn () => $concrete); | ||
|
||
static::assertSame( | ||
$concrete, | ||
$abstractConcrete->get($container = new Container(), new ParameterResolver($container)), | ||
); | ||
} | ||
|
||
/** @throws InvalidServiceProviderException|MissingDefinitionException|UnresolvableException|InvalidMethodException|InvalidArgumentException */ | ||
public function testResolveAllowsNullValue(): void { | ||
$abstractConcrete = new Singleton(ConcreteCExtendsAbstractBImplementsInterfaceA::class, fn () => null); | ||
|
||
static::assertNull($abstractConcrete->get($container = new Container(), new ParameterResolver($container))); | ||
} | ||
} |
Oops, something went wrong.