-
Notifications
You must be signed in to change notification settings - Fork 26
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 #405 from bearsunday/remove_module_cache
Remove module cache in getOverrideInstance
- Loading branch information
Showing
10 changed files
with
90 additions
and
17 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 |
---|---|---|
|
@@ -8,3 +8,4 @@ parameters: | |
- tests/tmp/* | ||
- tests/Fake/* | ||
- tests/script/* | ||
- tests/Injector/Fake/fake-app/var/tmp/* |
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace FakeVendor\HelloWorld; | ||
|
||
class FakeDep2 implements FakeDepInterface | ||
{ | ||
public function foo() | ||
{ | ||
} | ||
} |
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 FakeVendor\HelloWorld\Resource\Page; | ||
|
||
use BEAR\Resource\ResourceObject; | ||
use FakeVendor\HelloWorld\FakeDepInterface; | ||
use FooName\FooInterface; | ||
|
||
|
||
class Injection extends ResourceObject | ||
{ | ||
public FakeDepInterface $foo; | ||
public function __construct(FakeDepInterface $foo) | ||
{ | ||
$this->foo = $foo; | ||
} | ||
} |
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,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BEAR\Package\Injector; | ||
|
||
use BEAR\Package\Injector; | ||
use BEAR\Resource\ResourceInterface; | ||
use FakeVendor\HelloWorld\FakeDep; | ||
use FakeVendor\HelloWorld\FakeDep2; | ||
use FakeVendor\HelloWorld\FakeDepInterface; | ||
use FakeVendor\HelloWorld\Resource\Page\Injection; | ||
use PHPUnit\Framework\TestCase; | ||
use Ray\Di\AbstractModule; | ||
|
||
use function assert; | ||
use function dirname; | ||
|
||
class PackageInjectorTest extends TestCase | ||
{ | ||
public function testOriginalBind(): void | ||
{ | ||
$injector = Injector::getInstance('FakeVendor\HelloWorld', 'app', dirname(__DIR__) . '/Fake/fake-app'); | ||
$resource = $injector->getInstance(ResourceInterface::class); | ||
assert($resource instanceof ResourceInterface); | ||
$page = $resource->newInstance('page://self/injection'); | ||
assert($page instanceof Injection); | ||
$this->assertInstanceOf(FakeDep::class, $page->foo); | ||
} | ||
|
||
/** | ||
* @depends testOriginalBind | ||
*/ | ||
public function testGetOverrideInstance(): void | ||
{ | ||
$injector = Injector::getOverrideInstance('FakeVendor\HelloWorld', 'app', dirname(__DIR__) . '/Fake/fake-app', new class extends AbstractModule{ | ||
protected function configure() | ||
{ | ||
$this->bind(FakeDepInterface::class)->to(FakeDep2::class); | ||
} | ||
}); | ||
$resource = $injector->getInstance(ResourceInterface::class); | ||
assert($resource instanceof ResourceInterface); | ||
$page = $resource->newInstance('page://self/injection'); | ||
assert($page instanceof Injection); | ||
$this->assertInstanceOf(FakeDep2::class, $page->foo); | ||
} | ||
} |