Passed
Pull Request — master (#1065)
by Maxim
23:05
created
src/Core/tests/Scope/UseCaseTest.php 1 patch
Braces   +44 added lines, -22 removed lines patch added patch discarded remove patch
@@ -30,7 +30,8 @@  discard block
 block discarded – undo
30 30
         $root = new Container();
31 31
         $root->bind('foo', SampleClass::class);
32 32
 
33
-        $root->runScoped(function (ContainerInterface $c1) {
33
+        $root->runScoped(function (ContainerInterface $c1)
34
+        {
34 35
             $c1->get('foo');
35 36
         }, bindings: ['foo' => SampleClass::class]);
36 37
 
@@ -63,7 +64,8 @@  discard block
 block discarded – undo
63 64
     {
64 65
         $root = new Container();
65 66
 
66
-        $root->runScoped(function (ContainerInterface $c1) use ($theSame, $alias) {
67
+        $root->runScoped(function (ContainerInterface $c1) use ($theSame, $alias)
68
+        {
67 69
             $obj1 = $c1->get($alias);
68 70
             $obj2 = $c1->get($alias);
69 71
 
@@ -88,14 +90,16 @@  discard block
 block discarded – undo
88 90
     {
89 91
         $root = new Container();
90 92
 
91
-        $root->runScoped(function (ContainerInterface $c1) use ($root) {
93
+        $root->runScoped(function (ContainerInterface $c1) use ($root)
94
+        {
92 95
             $obj1 = $c1->get('foo');
93 96
             $this->weakMap->offsetSet($obj1, true);
94 97
 
95 98
             self::assertNotSame($root, $c1);
96 99
             self::assertInstanceOf(stdClass::class, $obj1);
97 100
 
98
-            $c1->runScoped(function (ContainerInterface $c2) use ($root, $c1, $obj1) {
101
+            $c1->runScoped(function (ContainerInterface $c2) use ($root, $c1, $obj1)
102
+            {
99 103
                 $obj2 = $c2->get('foo');
100 104
                 $this->weakMap->offsetSet($obj2, true);
101 105
 
@@ -124,14 +128,16 @@  discard block
 block discarded – undo
124 128
         $root->bindSingleton('bar', [Factory::class, 'makeStdClass']);
125 129
         $root->bind(stdClass::class, new stdClass());
126 130
 
127
-        $root->runScoped(function (ContainerInterface $c1) use ($root) {
131
+        $root->runScoped(function (ContainerInterface $c1) use ($root)
132
+        {
128 133
             $obj1 = $c1->get('foo');
129 134
             $this->weakMap->offsetSet($obj1, true);
130 135
 
131 136
             self::assertInstanceOf(stdClass::class, $obj1);
132 137
             // Singleton must be the same
133 138
             self::assertSame($c1->get('bar'), $root->get('bar'));
134
-            $c1->runScoped(function (ContainerInterface $c2) use ($root, $obj1) {
139
+            $c1->runScoped(function (ContainerInterface $c2) use ($root, $obj1)
140
+            {
135 141
                 $obj2 = $c2->get('foo');
136 142
 
137 143
                 self::assertInstanceOf(stdClass::class, $obj2);
@@ -264,7 +270,8 @@  discard block
 block discarded – undo
264 270
     {
265 271
         $root = new Container();
266 272
 
267
-        $root->invoke(static function () use ($root) {
273
+        $root->invoke(static function () use ($root)
274
+        {
268 275
             self::assertNotNull(\Spiral\Core\ContainerScope::getContainer());
269 276
             self::assertSame($root, \Spiral\Core\ContainerScope::getContainer());
270 277
         });
@@ -273,7 +280,8 @@  discard block
 block discarded – undo
273 280
     public function testRegisterContainerOnGet(): void
274 281
     {
275 282
         $root = new Container();
276
-        $root->bind('foo', function () use ($root) {
283
+        $root->bind('foo', function () use ($root)
284
+        {
277 285
             self::assertNotNull(\Spiral\Core\ContainerScope::getContainer());
278 286
             self::assertSame($root, \Spiral\Core\ContainerScope::getContainer());
279 287
         });
@@ -284,7 +292,8 @@  discard block
 block discarded – undo
284 292
     public function testRegisterContainerOnMake(): void
285 293
     {
286 294
         $root = new Container();
287
-        $root->bind('foo', function () use ($root) {
295
+        $root->bind('foo', function () use ($root)
296
+        {
288 297
             self::assertNotNull(\Spiral\Core\ContainerScope::getContainer());
289 298
             self::assertSame($root, \Spiral\Core\ContainerScope::getContainer());
290 299
         });
@@ -297,20 +306,25 @@  discard block
 block discarded – undo
297 306
         $root = new Container();
298 307
         $root->bindSingleton('sampleClass', SampleClass::class);
299 308
 
300
-        $root->runScope(new Scope('foo'), function (Container $container) {
309
+        $root->runScope(new Scope('foo'), function (Container $container)
310
+        {
301 311
             $this->assertTrue($container->has('sampleClass'));
302 312
         });
303 313
 
304
-        $root->runScope(new Scope('foo'), function (Container $container) {
305
-            $container->runScope(new Scope('bar'), function (Container $container) {
314
+        $root->runScope(new Scope('foo'), function (Container $container)
315
+        {
316
+            $container->runScope(new Scope('bar'), function (Container $container)
317
+            {
306 318
                 $this->assertTrue($container->has('sampleClass'));
307 319
             });
308 320
         });
309 321
 
310
-        $root->runScope(new Scope('foo'), function (Container $container) {
322
+        $root->runScope(new Scope('foo'), function (Container $container)
323
+        {
311 324
             $container->bindSingleton('otherClass', SampleClass::class);
312 325
 
313
-            $container->runScope(new Scope('bar'), function (Container $container) {
326
+            $container->runScope(new Scope('bar'), function (Container $container)
327
+            {
314 328
                 $this->assertTrue($container->has('sampleClass'));
315 329
                 $this->assertTrue($container->has('otherClass'));
316 330
             });
@@ -322,33 +336,41 @@  discard block
 block discarded – undo
322 336
         $root = new Container();
323 337
         $root->getBinder('foo')->bindSingleton('sampleClass', AttrScopeFoo::class);
324 338
 
325
-        $root->runScope(new Scope('foo'), function (Container $container) {
339
+        $root->runScope(new Scope('foo'), function (Container $container)
340
+        {
326 341
             $this->assertTrue($container->has('sampleClass'));
327 342
         });
328 343
 
329
-        $root->runScope(new Scope('bar'), function (Container $container) {
344
+        $root->runScope(new Scope('bar'), function (Container $container)
345
+        {
330 346
             $this->assertFalse($container->has('sampleClass'));
331 347
         });
332 348
 
333
-        $root->runScope(new Scope('foo'), function (Container $container) {
334
-            $container->runScope(new Scope('bar'), function (Container $container) {
349
+        $root->runScope(new Scope('foo'), function (Container $container)
350
+        {
351
+            $container->runScope(new Scope('bar'), function (Container $container)
352
+            {
335 353
                 $this->assertTrue($container->has('sampleClass'));
336 354
             });
337 355
         });
338 356
 
339
-        $root->runScope(new Scope('foo'), function (Container $container) {
357
+        $root->runScope(new Scope('foo'), function (Container $container)
358
+        {
340 359
             $container->bindSingleton('otherClass', AttrScopeFoo::class);
341 360
 
342
-            $container->runScope(new Scope('bar'), function (Container $container) {
361
+            $container->runScope(new Scope('bar'), function (Container $container)
362
+            {
343 363
                 $this->assertTrue($container->has('sampleClass'));
344 364
                 $this->assertTrue($container->has('otherClass'));
345 365
             });
346 366
         });
347 367
 
348
-        $root->runScope(new Scope('baz'), function (Container $container) {
368
+        $root->runScope(new Scope('baz'), function (Container $container)
369
+        {
349 370
             $container->getBinder('foo')->bindSingleton('otherClass', AttrScopeFoo::class);
350 371
 
351
-            $container->runScope(new Scope('bar'), function (Container $container) {
372
+            $container->runScope(new Scope('bar'), function (Container $container)
373
+            {
352 374
                 $this->assertFalse($container->has('sampleClass'));
353 375
                 $this->assertFalse($container->has('otherClass'));
354 376
             });
Please login to merge, or discard this patch.
src/Core/src/Internal/Container.php 1 patch
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -51,7 +51,8 @@  discard block
 block discarded – undo
51 51
      */
52 52
     public function get(string|Autowire $id, \Stringable|string|null $context = null): mixed
53 53
     {
54
-        if ($id instanceof Autowire) {
54
+        if ($id instanceof Autowire)
55
+        {
55 56
             return $id->resolve($this->factory);
56 57
         }
57 58
 
@@ -61,7 +62,8 @@  discard block
 block discarded – undo
61 62
 
62 63
     public function has(string $id): bool
63 64
     {
64
-        if (\array_key_exists($id, $this->state->bindings) || \array_key_exists($id, $this->state->singletons)) {
65
+        if (\array_key_exists($id, $this->state->bindings) || \array_key_exists($id, $this->state->singletons))
66
+        {
65 67
             return true;
66 68
         }
67 69
 
Please login to merge, or discard this patch.