Skip to content

Commit

Permalink
Add tests for the $scopedBindings property of ServiceProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
freerkminnema authored Aug 14, 2024
1 parent cc31ca2 commit b0fd414
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/Foundation/FoundationApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,34 @@ public function testClassesAreBoundWhenServiceProviderIsRegistered()
$this->assertNotSame($instance, $app->make(AbstractClass::class));
}

public function testScopedBindingsAreCreatedWhenServiceProviderIsRegistered()
{
$app = new Application;
$app->register($provider = new class($app) extends ServiceProvider
{
public $scopedBindings = [
NonContractBackedClass::class,
AbstractClass::class => ConcreteClass::class,
];
});

$this->assertArrayHasKey(get_class($provider), $app->getLoadedProviders());

$instance = $app->make(AbstractClass::class);

$this->assertInstanceOf(ConcreteClass::class, $instance);
$this->assertSame($instance, $app->make(AbstractClass::class));
$app->forgetScopedInstances();
$this->assertNotSame($instance, $app->make(AbstractClass::class));

$instance = $app->make(NonContractBackedClass::class);

$this->assertInstanceOf(NonContractBackedClass::class, $instance);
$this->assertSame($instance, $app->make(NonContractBackedClass::class));
$app->forgetScopedInstances();
$this->assertNotSame($instance, $app->make(AbstractClass::class));
}

public function testSingletonsAreCreatedWhenServiceProviderIsRegistered()
{
$app = new Application;
Expand Down

0 comments on commit b0fd414

Please sign in to comment.