diff --git a/tests/Container/ContainerTest.php b/tests/Container/ContainerTest.php index c8bb3896d7fd..5297ddd0bdd0 100755 --- a/tests/Container/ContainerTest.php +++ b/tests/Container/ContainerTest.php @@ -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; @@ -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; @@ -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