diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index b3bea30b74..46074a67a5 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -38,6 +38,7 @@ use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ServiceLocator; use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass; use Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition; +use Symfony\Component\DependencyInjection\Tests\Fixtures\ScalarFactory; use Symfony\Component\DependencyInjection\Tests\Fixtures\SimilarArgumentsDummy; use Symfony\Component\DependencyInjection\TypedReference; use Symfony\Component\ExpressionLanguage\Expression; @@ -1532,6 +1533,20 @@ class ContainerBuilderTest extends TestCase $this->assertSame(['service_container'], array_keys($container->getDefinitions())); } + + public function testScalarService() + { + $c = new ContainerBuilder(); + $c->register('foo', 'string') + ->setPublic(true) + ->setFactory([ScalarFactory::class, 'getSomeValue']) + ; + + $c->compile(); + + $this->assertTrue($c->has('foo')); + $this->assertSame('some value', $c->get('foo')); + } } class FooClass diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php index d2616a34ba..5dbec886e6 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php @@ -386,6 +386,16 @@ class ContainerTest extends TestCase $this->assertTrue($sc->has('foo\\baz'), '->has() returns true if a get*Method() is defined'); } + public function testScalarService() + { + $c = new Container(); + + $c->set('foo', 'some value'); + + $this->assertTrue($c->has('foo')); + $this->assertSame('some value', $c->get('foo')); + } + public function testInitialized() { $sc = new ProjectServiceContainer(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php index a1ccb52b60..926933bb0e 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php @@ -30,6 +30,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ServiceLocator; use Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition; +use Symfony\Component\DependencyInjection\Tests\Fixtures\ScalarFactory; use Symfony\Component\DependencyInjection\Tests\Fixtures\StubbedTranslator; use Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber; use Symfony\Component\DependencyInjection\TypedReference; @@ -1115,6 +1116,25 @@ class PhpDumperTest extends TestCase $this->assertEquals((object) ['foo' => (object) []], $container->get('Bar')); } + + public function testScalarService() + { + $container = new ContainerBuilder(); + $container->register('foo', 'string') + ->setPublic(true) + ->setFactory([ScalarFactory::class, 'getSomeValue']) + ; + + $container->compile(); + + $dumper = new PhpDumper($container); + eval('?>'.$dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_Scalar_Service'])); + + $container = new \Symfony_DI_PhpDumper_Test_Scalar_Service(); + + $this->assertTrue($container->has('foo')); + $this->assertSame('some value', $container->get('foo')); + } } class Rot13EnvVarProcessor implements EnvVarProcessorInterface diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/ScalarFactory.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/ScalarFactory.php new file mode 100644 index 0000000000..15646a8d0c --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/ScalarFactory.php @@ -0,0 +1,14 @@ +