Skip to content

Commit 04cec2b

Browse files
committed
fix: CallableDispatcher binding in tests
1 parent c5cf7b7 commit 04cec2b

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

tests/Routing/AttributeRoutingTest.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
use Illuminate\Routing\Attributes\Post;
1414
use Illuminate\Routing\Router;
1515
use Illuminate\Routing\UrlGenerator;
16-
use Illuminate\Support\Facades\Facade;
17-
use Illuminate\Support\Facades\Route;
1816
use Mockery as m;
1917
use PHPUnit\Framework\TestCase;
2018

@@ -33,6 +31,7 @@ public function post()
3331
return 'post success';
3432
}
3533
}
34+
3635
#[Group(prefix: 'group', name: 'group.')]
3736
class GroupController implements AttributeRouteController
3837
{
@@ -59,16 +58,18 @@ protected function setUp(): void
5958
$this->router = new Router(new Dispatcher, $this->container);
6059
$this->container->instance('router', $this->router);
6160

62-
Facade::setFacadeApplication($this->container);
63-
6461
$request = Request::create('http://example.com');
6562
$this->container->instance('url', new UrlGenerator(
6663
$this->router->getRoutes(), $request
6764
));
6865

6966
$appMock = m::mock(Application::class);
7067
$appMock->shouldReceive('basePath')->andReturn('');
71-
$this->container->instance(Application::class, $appMock);
68+
69+
$this->container->bind(
70+
\Illuminate\Routing\Contracts\CallableDispatcher::class,
71+
\Illuminate\Routing\CallableDispatcher::class
72+
);
7273

7374
$this->registrar = new AttributeRouteRegistrar($appMock, $this->router);
7475

@@ -81,9 +82,6 @@ protected function setUp(): void
8182
protected function tearDown(): void
8283
{
8384
m::close();
84-
Facade::clearResolvedInstances();
85-
Container::setInstance(null);
86-
parent::tearDown();
8785
}
8886

8987
public function test_it_registers_and_accesses_a_basic_get_route(): void
@@ -104,7 +102,7 @@ public function test_it_registers_a_basic_post_route(): void
104102

105103
public function test_it_applies_a_name_to_a_route(): void
106104
{
107-
$this->assertTrue(Route::has('get'));
105+
$this->assertTrue($this->router->has('get'));
108106
$this->assertEquals('http://example.com/get', route('get'));
109107
}
110108

@@ -118,7 +116,7 @@ public function test_it_applies_group_prefix(): void
118116

119117
public function test_it_applies_group_name_prefix(): void
120118
{
121-
$this->assertTrue(Route::has('group.route'));
119+
$this->assertTrue($this->router->has('group.route'));
122120
$this->assertEquals('http://example.com/group/route', route('group.route'));
123121
}
124122
}

0 commit comments

Comments
 (0)