Skip to content

Commit

Permalink
Add additional Container tests (#22716)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnabialek authored and taylorotwell committed Jan 9, 2018
1 parent ce88b25 commit 2154cc9
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/Container/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ public function testBindIfDoesntRegisterIfServiceAlreadyRegistered()
$this->assertEquals('Taylor', $container->make('name'));
}

public function testBindIfDoesRegisterIfServiceNotRegisteredYet()
{
$container = new Container;
$container->bind('surname', function () {
return 'Taylor';
});
$container->bindIf('name', function () {
return 'Dayle';
});

$this->assertEquals('Dayle', $container->make('name'));
}

public function testSharedClosureResolution()
{
$container = new Container;
Expand Down Expand Up @@ -820,6 +833,17 @@ public function testGetAlias()
$this->assertEquals($container->getAlias('foo'), 'ConcreteStub');
}

public function testItThrowsExceptionWhenAbstractIsSameAsAlias()
{
$container = new Container;
$container->alias('name', 'name');

$this->expectException('LogicException');
$this->expectExceptionMessage('[name] is aliased to itself.');

$container->getAlias('name');
}

public function testContainerCanInjectSimpleVariable()
{
$container = new Container;
Expand Down Expand Up @@ -1001,6 +1025,15 @@ public function testContainerCanBindAnyWord()
$this->assertInstanceOf(stdClass::class, $container->get('Taylor'));
}

public function testContainerCanDynamicallySetService()
{
$container = new Container;
$this->assertFalse(isset($container['name']));
$container['name'] = 'Taylor';
$this->assertTrue(isset($container['name']));
$this->assertSame('Taylor', $container['name']);
}

/**
* @expectedException \Illuminate\Container\EntryNotFoundException
* @expectedExceptionMessage
Expand Down

0 comments on commit 2154cc9

Please sign in to comment.