-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[11.x] fix: allows injection using multiple interfaces with the same …
…concrete implementation (#53275) * fix: allows injection of multiple interfaces with the same implementation * fix: ensure interfaces are only resolved once * fix: allows injection using multiple interfaces with the same concrete implementation * wip: working but ugly * test: ensure all tests pass * chore: fix code style issues * chore: fix code style issues * remove forgotten dd * wip * test: add test to ensure multiple interfaces with the same implementation can be injected in controllers * chore: remove unused imports * chore: adhere to style guidelines * formatting * formatting * formatting * formatting * formatting --------- Co-authored-by: Taylor Otwell <[email protected]>
- Loading branch information
1 parent
83c3855
commit a306193
Showing
2 changed files
with
111 additions
and
5 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,52 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Routing; | ||
|
||
use Illuminate\Container\Container; | ||
use Illuminate\Contracts\Routing\Registrar; | ||
use Illuminate\Events\Dispatcher; | ||
use Illuminate\Routing\Controller; | ||
use Illuminate\Routing\Router; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class RouteDependencyInjectionTest extends TestCase | ||
{ | ||
public function test_it_can_resolve_multiple_interfaces_with_the_same_implementation() | ||
{ | ||
$container = new Container; | ||
$router = new Router(new Dispatcher, $container); | ||
$container->instance(Registrar::class, $router); | ||
|
||
$container->bind(TestDependencyInterfaceA::class, TestDependencyImplementation::class); | ||
$container->bind(TestDependencyInterfaceB::class, TestDependencyImplementation::class); | ||
|
||
$controller = new TestDependencyController(); | ||
$result = $controller->index( | ||
$container->make(TestDependencyInterfaceA::class), | ||
$container->make(TestDependencyInterfaceB::class) | ||
); | ||
|
||
$this->assertInstanceOf(TestDependencyImplementation::class, $result[0]); | ||
$this->assertInstanceOf(TestDependencyImplementation::class, $result[1]); | ||
} | ||
} | ||
|
||
interface TestDependencyInterfaceA | ||
{ | ||
} | ||
|
||
interface TestDependencyInterfaceB | ||
{ | ||
} | ||
|
||
class TestDependencyImplementation implements TestDependencyInterfaceA, TestDependencyInterfaceB | ||
{ | ||
} | ||
|
||
class TestDependencyController extends Controller | ||
{ | ||
public function index(TestDependencyInterfaceA $a, TestDependencyInterfaceB $b) | ||
{ | ||
return [$a, $b]; | ||
} | ||
} |