Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit526fd90

Browse files
[DI] Added tests for env expression language function
1 parent401a026 commit526fd90

File tree

2 files changed

+63
-3
lines changed

2 files changed

+63
-3
lines changed

‎src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,14 +442,18 @@ public function testCreateSyntheticService()
442442

443443
publicfunctiontestCreateServiceWithExpression()
444444
{
445+
putenv('SYMFONY_TEST_ENVIRONMENT_VAR=quux');
446+
445447
$builder =newContainerBuilder();
446448
$builder->setParameter('bar','bar');
447449
$builder->register('bar','BarClass');
448-
$builder->register('foo','Bar\FooClass')->addArgument(array('foo' =>newExpression('service("bar").foo ~ parameter("bar")')));
450+
$builder->register('foo','Bar\FooClass')->addArgument(array('foo' =>newExpression('service("bar").foo ~ parameter("bar") ~ env("SYMFONY_TEST_ENVIRONMENT_VAR")')));
449451

450452
$builder->compile();
451453

452-
$this->assertEquals('foobar',$builder->get('foo')->arguments['foo']);
454+
$this->assertEquals('foobarquux',$builder->get('foo')->arguments['foo']);
455+
456+
putenv('SYMFONY_TEST_ENVIRONMENT_VAR');
453457
}
454458

455459
publicfunctiontestResolveServices()

‎src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php‎

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function testGetServiceIds()
126126

127127
$sc =newProjectServiceContainer();
128128
$sc->set('foo',$obj =new \stdClass());
129-
$this->assertEquals(array('internal','bar','foo_bar','foo.baz','circular','throw_exception','throws_exception_on_service_configuration','service_container','foo'),$sc->getServiceIds(),'->getServiceIds() returns defined service ids by getXXXService() methods, followed by service ids defined by set()');
129+
$this->assertEquals(array('internal','bar','foo_bar','foo.baz','env_dependent_one','env_dependent_two','circular','throw_exception','throws_exception_on_service_configuration','service_container','foo'),$sc->getServiceIds(),'->getServiceIds() returns defined service ids by getXXXService() methods, followed by service ids defined by set()');
130130
}
131131

132132
publicfunctiontestSet()
@@ -308,6 +308,52 @@ public function testThatCloningIsNotSupported()
308308
$this->assertTrue($clone->isPrivate());
309309
}
310310

311+
publicfunctiontestEnvironmentVariablesFromGetenv()
312+
{
313+
$c =newProjectServiceContainer();
314+
315+
unset($_ENV['SYMFONY_TEST_FOO_ONE']);
316+
putenv('SYMFONY_TEST_FOO_ONE=foo');
317+
318+
$this->assertSame('foo',$c->get('env_dependent_one'));
319+
putenv('SYMFONY_TEST_FOO_ONE');
320+
}
321+
322+
publicfunctiontestEnvironmentVariablesFromEnvGlobal()
323+
{
324+
$c =newProjectServiceContainer();
325+
326+
putenv('SYMFONY_TEST_FOO_ONE');
327+
$_ENV['SYMFONY_TEST_FOO_ONE'] ='bar';
328+
329+
$this->assertSame('bar',$c->get('env_dependent_one'));
330+
unset($_ENV['SYMFONY_TEST_FOO_ONE']);
331+
}
332+
333+
/**
334+
* @expectedException Symfony\Component\DependencyInjection\Exception\EnvironmentVariableNotFoundException
335+
* @expectedExceptionMessage You have requested a non-existent environment variable "SYMFONY_TEST_FOO_ONE".
336+
*/
337+
publicfunctiontestEnvironmentVariablesThrowsWhenNotSetWithoutDefault()
338+
{
339+
$c =newProjectServiceContainer();
340+
341+
unset($_ENV['SYMFONY_TEST_FOO_ONE']);
342+
putenv('SYMFONY_TEST_FOO_ONE');
343+
344+
$c->get('env_dependent_one');
345+
}
346+
347+
publicfunctiontestEnvironmentVariablesReturnsDefaultWhenNotSet()
348+
{
349+
$c =newProjectServiceContainer();
350+
351+
unset($_ENV['SYMFONY_TEST_FOO_TWO']);
352+
putenv('SYMFONY_TEST_FOO_TWO');
353+
354+
$this->assertSame('xyzzy',$c->get('env_dependent_two'));
355+
}
356+
311357
/**
312358
* @group legacy
313359
* @requires function Symfony\Bridge\PhpUnit\ErrorAssert::assertDeprecationsAreTriggered
@@ -412,6 +458,16 @@ protected function getFoo_BazService()
412458
return$this->__foo_baz;
413459
}
414460

461+
protectedfunctiongetEnvDependentOneService()
462+
{
463+
return$this->getEnvironmentVariable('SYMFONY_TEST_FOO_ONE');
464+
}
465+
466+
protectedfunctiongetEnvDependentTwoService()
467+
{
468+
return$this->getEnvironmentVariable('SYMFONY_TEST_FOO_TWO','xyzzy');
469+
}
470+
415471
protectedfunctiongetCircularService()
416472
{
417473
return$this->get('circular');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp