File tree 4 files changed +59
-0
lines changed
src/Symfony/Component/DependencyInjection/Tests
4 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 38
38
use Symfony \Component \DependencyInjection \ServiceLocator ;
39
39
use Symfony \Component \DependencyInjection \Tests \Fixtures \CaseSensitiveClass ;
40
40
use Symfony \Component \DependencyInjection \Tests \Fixtures \CustomDefinition ;
41
+ use Symfony \Component \DependencyInjection \Tests \Fixtures \ScalarFactory ;
41
42
use Symfony \Component \DependencyInjection \Tests \Fixtures \SimilarArgumentsDummy ;
42
43
use Symfony \Component \DependencyInjection \TypedReference ;
43
44
use Symfony \Component \ExpressionLanguage \Expression ;
@@ -1532,6 +1533,20 @@ public function testDecoratedSelfReferenceInvolvingPrivateServices()
1532
1533
1533
1534
$ this ->assertSame (['service_container ' ], array_keys ($ container ->getDefinitions ()));
1534
1535
}
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
+ }
1535
1550
}
1536
1551
1537
1552
class FooClass
Original file line number Diff line number Diff line change @@ -386,6 +386,16 @@ public function testLegacyHas()
386
386
$ this ->assertTrue ($ sc ->has ('foo \\baz ' ), '->has() returns true if a get*Method() is defined ' );
387
387
}
388
388
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
+
389
399
public function testInitialized ()
390
400
{
391
401
$ sc = new ProjectServiceContainer ();
Original file line number Diff line number Diff line change 30
30
use Symfony \Component \DependencyInjection \Reference ;
31
31
use Symfony \Component \DependencyInjection \ServiceLocator ;
32
32
use Symfony \Component \DependencyInjection \Tests \Fixtures \CustomDefinition ;
33
+ use Symfony \Component \DependencyInjection \Tests \Fixtures \ScalarFactory ;
33
34
use Symfony \Component \DependencyInjection \Tests \Fixtures \StubbedTranslator ;
34
35
use Symfony \Component \DependencyInjection \Tests \Fixtures \TestServiceSubscriber ;
35
36
use Symfony \Component \DependencyInjection \TypedReference ;
@@ -1115,6 +1116,25 @@ public function testReferenceWithLowerCaseId()
1115
1116
1116
1117
$ this ->assertEquals ((object ) ['foo ' => (object ) []], $ container ->get ('Bar ' ));
1117
1118
}
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
+ }
1118
1138
}
1119
1139
1120
1140
class 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