File tree Expand file tree Collapse file tree 4 files changed +59
-0
lines changed
Expand file tree Collapse file tree 4 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 3838use Symfony \Component \DependencyInjection \ServiceLocator ;
3939use Symfony \Component \DependencyInjection \Tests \Fixtures \CaseSensitiveClass ;
4040use Symfony \Component \DependencyInjection \Tests \Fixtures \CustomDefinition ;
41+ use Symfony \Component \DependencyInjection \Tests \Fixtures \ScalarFactory ;
4142use Symfony \Component \DependencyInjection \Tests \Fixtures \SimilarArgumentsDummy ;
4243use Symfony \Component \DependencyInjection \TypedReference ;
4344use Symfony \Component \ExpressionLanguage \Expression ;
@@ -1532,6 +1533,20 @@ public function testDecoratedSelfReferenceInvolvingPrivateServices()
15321533
15331534 $ this ->assertSame (['service_container ' ], array_keys ($ container ->getDefinitions ()));
15341535 }
1536+
1537+ public function testScalarService ()
1538+ {
1539+ $ c = new ContainerBuilder ();
1540+ $ c ->register ('foo ' , 'string ' )
1541+ ->setPublic (true )
1542+ ->setFactory ([ScalarFactory::class, 'getSomeValue ' ])
1543+ ;
1544+
1545+ $ c ->compile ();
1546+
1547+ $ this ->assertTrue ($ c ->has ('foo ' ));
1548+ $ this ->assertSame ('some value ' , $ c ->get ('foo ' ));
1549+ }
15351550}
15361551
15371552class FooClass
Original file line number Diff line number Diff line change @@ -386,6 +386,16 @@ public function testLegacyHas()
386386 $ this ->assertTrue ($ sc ->has ('foo \\baz ' ), '->has() returns true if a get*Method() is defined ' );
387387 }
388388
389+ public function testScalarService ()
390+ {
391+ $ c = new Container ();
392+
393+ $ c ->set ('foo ' , 'some value ' );
394+
395+ $ this ->assertTrue ($ c ->has ('foo ' ));
396+ $ this ->assertSame ('some value ' , $ c ->get ('foo ' ));
397+ }
398+
389399 public function testInitialized ()
390400 {
391401 $ sc = new ProjectServiceContainer ();
Original file line number Diff line number Diff line change 3030use Symfony \Component \DependencyInjection \Reference ;
3131use Symfony \Component \DependencyInjection \ServiceLocator ;
3232use Symfony \Component \DependencyInjection \Tests \Fixtures \CustomDefinition ;
33+ use Symfony \Component \DependencyInjection \Tests \Fixtures \ScalarFactory ;
3334use Symfony \Component \DependencyInjection \Tests \Fixtures \StubbedTranslator ;
3435use Symfony \Component \DependencyInjection \Tests \Fixtures \TestServiceSubscriber ;
3536use Symfony \Component \DependencyInjection \TypedReference ;
@@ -1115,6 +1116,25 @@ public function testReferenceWithLowerCaseId()
11151116
11161117 $ this ->assertEquals ((object ) ['foo ' => (object ) []], $ container ->get ('Bar ' ));
11171118 }
1119+
1120+ public function testScalarService ()
1121+ {
1122+ $ container = new ContainerBuilder ();
1123+ $ container ->register ('foo ' , 'string ' )
1124+ ->setPublic (true )
1125+ ->setFactory ([ScalarFactory::class, 'getSomeValue ' ])
1126+ ;
1127+
1128+ $ container ->compile ();
1129+
1130+ $ dumper = new PhpDumper ($ container );
1131+ eval ('?> ' .$ dumper ->dump (['class ' => 'Symfony_DI_PhpDumper_Test_Scalar_Service ' ]));
1132+
1133+ $ container = new \Symfony_DI_PhpDumper_Test_Scalar_Service ();
1134+
1135+ $ this ->assertTrue ($ container ->has ('foo ' ));
1136+ $ this ->assertSame ('some value ' , $ container ->get ('foo ' ));
1137+ }
11181138}
11191139
11201140class Rot13EnvVarProcessor implements EnvVarProcessorInterface
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Symfony \Component \DependencyInjection \Tests \Fixtures ;
4+
5+ final class ScalarFactory
6+ {
7+ /**
8+ * @return string
9+ */
10+ public static function getSomeValue ()
11+ {
12+ return 'some value ' ;
13+ }
14+ }
You can’t perform that action at this time.
0 commit comments