Added tests to cover the possibility of having scalars as services.
This commit is contained in:
parent
ddaf1becf3
commit
60939d988d
@ -38,6 +38,7 @@ use Symfony\Component\DependencyInjection\Reference;
|
|||||||
use Symfony\Component\DependencyInjection\ServiceLocator;
|
use Symfony\Component\DependencyInjection\ServiceLocator;
|
||||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
|
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
|
||||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition;
|
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\Tests\Fixtures\SimilarArgumentsDummy;
|
||||||
use Symfony\Component\DependencyInjection\TypedReference;
|
use Symfony\Component\DependencyInjection\TypedReference;
|
||||||
use Symfony\Component\ExpressionLanguage\Expression;
|
use Symfony\Component\ExpressionLanguage\Expression;
|
||||||
@ -1532,6 +1533,20 @@ class ContainerBuilderTest extends TestCase
|
|||||||
|
|
||||||
$this->assertSame(['service_container'], array_keys($container->getDefinitions()));
|
$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
|
class FooClass
|
||||||
|
@ -386,6 +386,16 @@ class ContainerTest extends TestCase
|
|||||||
$this->assertTrue($sc->has('foo\\baz'), '->has() returns true if a get*Method() is defined');
|
$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()
|
public function testInitialized()
|
||||||
{
|
{
|
||||||
$sc = new ProjectServiceContainer();
|
$sc = new ProjectServiceContainer();
|
||||||
|
@ -30,6 +30,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
|||||||
use Symfony\Component\DependencyInjection\Reference;
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
use Symfony\Component\DependencyInjection\ServiceLocator;
|
use Symfony\Component\DependencyInjection\ServiceLocator;
|
||||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition;
|
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\StubbedTranslator;
|
||||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber;
|
use Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber;
|
||||||
use Symfony\Component\DependencyInjection\TypedReference;
|
use Symfony\Component\DependencyInjection\TypedReference;
|
||||||
@ -1115,6 +1116,25 @@ class PhpDumperTest extends TestCase
|
|||||||
|
|
||||||
$this->assertEquals((object) ['foo' => (object) []], $container->get('Bar'));
|
$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
|
class Rot13EnvVarProcessor implements EnvVarProcessorInterface
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
|
||||||
|
|
||||||
|
final class ScalarFactory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function getSomeValue()
|
||||||
|
{
|
||||||
|
return 'some value';
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user