Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Add test for multiple resolving service bounded as singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
jedrzejchalubek committed May 22, 2017
1 parent 5676e0e commit 3bd7e0d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/Gin/Foundation/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public function get($key, array $parameters = [])
// Otherwise, look for service
// in services collection.
if (isset($this->services[$key])) {

// Resolve service jf we don't have
// a deposit for this service.
if (! isset($this->deposit[$key])) {
Expand Down
25 changes: 25 additions & 0 deletions tests/Gin/Foundation/ThemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,23 @@ public function it_should_return_same_object_on_factory_binding()
$this->assertNotSame($theme->get('factory'), $theme->get('factory'));
}

/**
* @test
*/
public function it_should_create_service_only_once_on_multiple_resolving()
{
$theme = Theme::getInstance();
$mock = Mockery::mock(new Stub);

$theme->bind('service', function () use ($mock) { return $mock->action(); });

$mock->shouldReceive('action')->once()->andReturn('value');

$theme->get('service');
$theme->get('service');
$theme->get('service');
}

/**
* @test
*/
Expand All @@ -128,4 +145,12 @@ public function it_should_throw_exception_on_resolving_nonexisting_binding()

$theme->get('nonexsiting.binding');
}
}

class Stub
{
function action()
{
//
}
}

0 comments on commit 3bd7e0d

Please sign in to comment.