Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,8 @@ public function register($provider, $force = false)

if (property_exists($provider, 'singletons')) {
foreach ($provider->singletons as $key => $value) {
$key = is_int($key) ? $value : $key;

$this->singleton($key, $value);
}
}
Expand Down
11 changes: 11 additions & 0 deletions tests/Foundation/FoundationApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function testSingletonsAreCreatedWhenServiceProviderIsRegistered()
$app->register($provider = new class($app) extends ServiceProvider
{
public $singletons = [
NonContractBackedClass::class,
AbstractClass::class => ConcreteClass::class,
];
});
Expand All @@ -77,6 +78,11 @@ public function testSingletonsAreCreatedWhenServiceProviderIsRegistered()

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

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

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

public function testServiceProvidersAreCorrectlyRegisteredWhenRegisterMethodIsNotFilled()
Expand Down Expand Up @@ -613,6 +619,11 @@ class ConcreteClass extends AbstractClass
//
}

class NonContractBackedClass
{
//
}

class ConcreteTerminator
{
public static $counter = 0;
Expand Down