Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Aesthetic changes (code formatting) #68

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

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
Next Next commit
[DependencyInjection] Test coverage improvements and corrections on C…
…ontainer.
  • Loading branch information
yclian committed Feb 19, 2011
commit d9028db4ddae33f49b2a01bad2473a805d2d868f
45 changes: 42 additions & 3 deletions 45 tests/Symfony/Tests/Component/DependencyInjection/ContainerTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testConstructor()
/**
* @covers Symfony\Component\DependencyInjection\Container::compile
*/
public function testcompile()
public function testCompile()
{
$sc = new Container(new ParameterBag(array('foo' => 'bar')));
$sc->compile();
Expand Down Expand Up @@ -98,7 +98,7 @@ public function testGetServiceIds()
$this->assertEquals(array('service_container', 'foo', 'bar'), $sc->getServiceIds(), '->getServiceIds() returns all defined service ids');

$sc = new ProjectServiceContainer();
$this->assertEquals(array('scoped', 'scoped_foo', 'bar', 'foo_bar', 'foo.baz', 'service_container'), $sc->getServiceIds(), '->getServiceIds() returns defined service ids by getXXXService() methods');
$this->assertEquals(array('scoped', 'scoped_foo', 'bar', 'foo_bar', 'foo.baz', 'circular', 'service_container'), $sc->getServiceIds(), '->getServiceIds() returns defined service ids by getXXXService() methods');
}

/**
Expand Down Expand Up @@ -155,7 +155,7 @@ public function testGet()
$this->assertEquals($sc->__foo_baz, $sc->get('foo.baz'), '->get() returns the service if a get*Method() is defined');

$sc->set('bar', $bar = new \stdClass());
$this->assertSame($sc->get('bar'), $bar, '->getServiceIds() prefers to return a service defined with a getXXXService() method than one defined with set()');
$this->assertEquals($bar, $sc->get('bar'), '->get() prefers to return a service defined with set() than one defined with a getXXXMethod()');

try {
$sc->get('');
Expand All @@ -167,6 +167,19 @@ public function testGet()
$this->assertNull($sc->get('', ContainerInterface::NULL_ON_INVALID_REFERENCE));
}

public function testGetCircularReference()
{

$sc = new ProjectServiceContainer();
try {
$sc->get('circular');
$this->fail('->get() throws a \LogicException if it contains circular reference');
} catch (\Exception $e) {
$this->assertInstanceOf('\LogicException', $e, '->get() throws a \LogicException if it contains circular reference');
$this->assertStringStartsWith('Circular reference detected for service "circular"', $e->getMessage(), '->get() throws a \LogicException if it contains circular reference');
}
}

/**
* @covers Symfony\Component\DependencyInjection\Container::has
*/
Expand Down Expand Up @@ -237,6 +250,28 @@ public function testEnterLeaveScopeWithChildScopes()
$this->assertFalse($container->has('a'));
}

public function testLeaveScopeNotActive()
{
$container = new Container();
$container->addScope(new Scope('foo'));

try {
$container->leaveScope('foo');
$this->fail('->leaveScope() throws a \LogicException if the scope is not active yet');
} catch (\Exception $e) {
$this->assertInstanceOf('\LogicException', $e, '->leaveScope() throws a \LogicException if the scope is not active yet');
$this->assertEquals('The scope "foo" is not active.', $e->getMessage(), '->leaveScope() throws a \LogicException if the scope is not active yet');
}

try {
$container->leaveScope('bar');
$this->fail('->leaveScope() throws a \LogicException if the scope does not exist');
} catch (\Exception $e) {
$this->assertInstanceOf('\LogicException', $e, '->leaveScope() throws a \LogicException if the scope does not exist');
$this->assertEquals('The scope "bar" is not active.', $e->getMessage(), '->leaveScope() throws a \LogicException if the scope does not exist');
}
}

/**
* @expectedException \InvalidArgumentException
* @dataProvider getBuiltInScopes
Expand Down Expand Up @@ -372,4 +407,8 @@ protected function getFoo_BazService()
{
return $this->__foo_baz;
}

protected function getCircularService(){
return $this->get('circular');
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.