-
-
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.
Merge pull request #8 from SergiX44/fix_delegate
Fix delegate
- Loading branch information
Showing
4 changed files
with
75 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
use SergiX44\Container\Container; | ||
use SergiX44\Container\Tests\Fixtures\Resolve\AbstractClass; | ||
use SergiX44\Container\Tests\Fixtures\Resolve\AnotherConcreteClass; | ||
use SergiX44\Container\Tests\Fixtures\Resolve\ConcreteClass; | ||
use SergiX44\Container\Tests\Fixtures\Resolve\SimpleClass; | ||
use SergiX44\Container\Tests\Fixtures\Resolve\SimpleInterface; | ||
|
||
it('can resolve a simple definition via delegator', function () { | ||
$di = new \DI\ContainerBuilder(); | ||
$di->addDefinitions([ | ||
SimpleInterface::class => \DI\create(SimpleClass::class), | ||
]); | ||
$delegator = $di->build(); | ||
|
||
expect($delegator->has(SimpleInterface::class))->toBeTrue(); | ||
|
||
$container = new Container(); | ||
|
||
expect($container->has(SimpleInterface::class))->toBeFalse(); | ||
|
||
$container->delegate($delegator); | ||
|
||
expect($container->has(SimpleInterface::class))->toBeTrue() | ||
->and($container->get(SimpleInterface::class))->toBeInstanceOf(SimpleClass::class); | ||
}); | ||
|
||
it('can resolve a simple definition via himself as delegator', function () { | ||
$delegator = new Container(); | ||
$delegator->bind(SimpleInterface::class, SimpleClass::class); | ||
|
||
expect($delegator->has(SimpleInterface::class))->toBeTrue(); | ||
|
||
$container = new Container(); | ||
|
||
expect($container->has(SimpleInterface::class))->toBeFalse(); | ||
|
||
$container->delegate($delegator); | ||
|
||
expect($container->has(SimpleInterface::class))->toBeTrue() | ||
->and($container->get(SimpleInterface::class))->toBeInstanceOf(SimpleClass::class); | ||
}); | ||
|
||
it('returns his definition instead of the delegator', function () { | ||
$delegator = new Container(); | ||
$delegator->bind(AbstractClass::class, ConcreteClass::class); | ||
|
||
expect($delegator->has(AbstractClass::class))->toBeTrue(); | ||
|
||
$container = new Container(); | ||
$container->bind(AbstractClass::class, AnotherConcreteClass::class); | ||
|
||
expect($container->has(AbstractClass::class))->toBeTrue(); | ||
|
||
$container->delegate($delegator); | ||
|
||
expect($container->has(AbstractClass::class))->toBeTrue() | ||
->and($container->get(AbstractClass::class))->toBeInstanceOf(AnotherConcreteClass::class); | ||
}); |
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,7 @@ | ||
<?php | ||
|
||
namespace SergiX44\Container\Tests\Fixtures\Resolve; | ||
|
||
class AnotherConcreteClass extends AbstractClass | ||
{ | ||
} |