Skip to content

Commit

Permalink
Merge pull request #413 from bearsunday/spike
Browse files Browse the repository at this point in the history
Fix primary_router binding
  • Loading branch information
koriym authored Jan 6, 2023
2 parents bb208ed + ff15534 commit 087bb44
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/Provide/Router/RouterCollectionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
namespace BEAR\Package\Provide\Router;

use BEAR\Sunday\Extension\Router\RouterInterface;
use Ray\Di\Di\Inject;
use Ray\Di\Di\Named;
use Ray\Di\ProviderInterface;

/** @implements ProviderInterface<RouterCollection> */
class RouterCollectionProvider implements ProviderInterface
{
#[Inject]
public function __construct(
#[Named('router')] private RouterInterface $primaryRouter,
#[Named('primary_router')] private RouterInterface $primaryRouter,
private WebRouterInterface $webRouter,
) {
}
Expand Down
1 change: 1 addition & 0 deletions tests/Fake/fake-app/src/Module/AppModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ protected function configure()
[NullInterceptor::class]
);
$this->bind(FakeFoo::class);
$this->bind(FakeDep::class);
$this->bind(Auth::class)->toProvider(AuthProvider::class);
}
}
33 changes: 33 additions & 0 deletions tests/Provide/Router/RouterCollectionProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace BEAR\Package\Provide\Router;

use BEAR\Package\FakeWebRouter;
use BEAR\Package\PackageModule;
use BEAR\Sunday\Extension\Router\RouterInterface;
use PHPUnit\Framework\TestCase;
use Ray\Di\AbstractModule;
use Ray\Di\Injector;

class RouterCollectionProviderTest extends TestCase
{
public function testPrimaryRouter(): void
{
$module = new class extends AbstractModule
{
protected function configure(): void
{
$this->install(new PackageModule());
$this->bind(RouterInterface::class)->annotatedWith('primary_router')->toInstance(new FakeWebRouter('page://self', new HttpMethodParams()));
$this->bind(WebRouterInterface::class)->to(WebRouter::class);
$this->bind(RouterInterface::class)->toProvider(RouterCollectionProvider::class);
}
};
$i = new Injector();
$injector = new Injector($module);
$router = $injector->getInstance(RouterInterface::class);
$this->assertInstanceOf(RouterInterface::class, $router);
}
}

0 comments on commit 087bb44

Please sign in to comment.