Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.6] Add additional Container tests #22716

Merged
merged 1 commit into from
Jan 9, 2018
Merged
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
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