diff --git a/src/Http/FakeHttp.php b/src/Http/FakeHttp.php index 3c5eeb1..4e6d767 100644 --- a/src/Http/FakeHttp.php +++ b/src/Http/FakeHttp.php @@ -138,6 +138,7 @@ public function withMiddleware(string ...$middleware): self public function withoutMiddleware(string ...$middleware): self { foreach ($middleware as $name) { + $this->container->removeBinding($name); $this->container->bindSingleton( $name, new class implements MiddlewareInterface { diff --git a/src/TestCase.php b/src/TestCase.php index b6fb29c..22227e6 100644 --- a/src/TestCase.php +++ b/src/TestCase.php @@ -128,6 +128,7 @@ public function makeApp(array $env = []): AbstractKernel $environment = new Environment($env); $app = $this->createAppInstance(); + $app->getContainer()->removeBinding(EnvironmentInterface::class); $app->getContainer()->bindSingleton(EnvironmentInterface::class, $environment); foreach ($this->beforeInit as $callback) { diff --git a/src/Traits/InteractsWithCore.php b/src/Traits/InteractsWithCore.php index 3639f19..68268a2 100644 --- a/src/Traits/InteractsWithCore.php +++ b/src/Traits/InteractsWithCore.php @@ -131,6 +131,8 @@ public function getRegisteredBootloaders(): array */ public function mockContainer(string $alias, ?string $interface = null): \Mockery\MockInterface { + $this->getContainer()->removeBinding($alias); + $this->getContainer()->bindSingleton( $alias, $mock = \Mockery::mock($interface ?? $alias) @@ -152,6 +154,7 @@ public function withEnvironment(array $env): self array_merge($current, $env) ); + $this->getContainer()->removeBinding(EnvironmentInterface::class); $this->getContainer()->bind(EnvironmentInterface::class, $this->environment); return $this; diff --git a/src/Traits/InteractsWithEvents.php b/src/Traits/InteractsWithEvents.php index 661133b..2b6d33d 100644 --- a/src/Traits/InteractsWithEvents.php +++ b/src/Traits/InteractsWithEvents.php @@ -11,6 +11,7 @@ trait InteractsWithEvents { public function fakeEventDispatcher(array $eventsToFake = []): FakeEventDispatcher { + $this->getContainer()->removeBinding(EventDispatcherInterface::class); $this->getContainer()->bindSingleton( EventDispatcherInterface::class, $dispatcher = $this->getContainer()->make( diff --git a/src/Traits/InteractsWithExceptions.php b/src/Traits/InteractsWithExceptions.php index 9b7f299..0ef17ea 100644 --- a/src/Traits/InteractsWithExceptions.php +++ b/src/Traits/InteractsWithExceptions.php @@ -13,6 +13,7 @@ trait InteractsWithExceptions { protected function withoutExceptionHandling(): void { + $this->getContainer()->removeBinding(ExceptionHandlerInterface::class); $this->getContainer()->bind( ExceptionHandlerInterface::class, new class implements ExceptionHandlerInterface { diff --git a/src/Traits/InteractsWithMailer.php b/src/Traits/InteractsWithMailer.php index 62dc5f3..6a870d1 100644 --- a/src/Traits/InteractsWithMailer.php +++ b/src/Traits/InteractsWithMailer.php @@ -19,6 +19,7 @@ public function fakeMailer(): FakeMailer } } + $container->removeBinding(MailerInterface::class); $container->bindSingleton( MailerInterface::class, $mailer = new FakeMailer() diff --git a/src/Traits/InteractsWithQueue.php b/src/Traits/InteractsWithQueue.php index 6a15452..c998461 100644 --- a/src/Traits/InteractsWithQueue.php +++ b/src/Traits/InteractsWithQueue.php @@ -19,6 +19,7 @@ public function fakeQueue(): FakeQueueManager } } + $container->removeBinding(QueueConnectionProviderInterface::class); $container->bindSingleton( QueueConnectionProviderInterface::class, $manager = $container->get(FakeQueueManager::class) diff --git a/src/Traits/InteractsWithScaffolder.php b/src/Traits/InteractsWithScaffolder.php index cca4482..6775775 100644 --- a/src/Traits/InteractsWithScaffolder.php +++ b/src/Traits/InteractsWithScaffolder.php @@ -79,9 +79,10 @@ public function mockScaffolder(string $command, array $args, \Closure $expected) $this->getConsole()->run($command, new ArrayInput($args), $output = new BufferedOutput()); - $originalFiles !== null - ? $this->getContainer()->bind(FilesInterface::class, $originalFiles) - : $this->getContainer()->removeBinding(FilesInterface::class); + $this->getContainer()->removeBinding(FilesInterface::class); + if ($originalFiles !== null) { + $this->getContainer()->bind(FilesInterface::class, $originalFiles); + } return $output->fetch(); }