Passed
Push — master ( d2fe62...2ff31f )
by butschster
08:14
created
src/Core/tests/Scope/FibersTest.php 1 patch
Braces   +47 added lines, -22 removed lines patch added patch discarded remove patch
@@ -30,7 +30,8 @@  discard block
 block discarded – undo
30 30
 
31 31
         self::runInFiber(
32 32
             self::functionScopedTestDataIterator(),
33
-            static function (mixed $suspendValue) {
33
+            static function (mixed $suspendValue)
34
+            {
34 35
                 self::assertNull(ContainerScope::getContainer());
35 36
                 self::assertTrue(\in_array($suspendValue, self::TEST_DATA, true));
36 37
             },
@@ -63,7 +64,8 @@  discard block
 block discarded – undo
63 64
         );
64 65
 
65 66
         self::assertCount(5, $result);
66
-        foreach ($result as $suspendValue) {
67
+        foreach ($result as $suspendValue)
68
+        {
67 69
             self::assertSame(self::TEST_DATA, $suspendValue);
68 70
         }
69 71
     }
@@ -81,7 +83,8 @@  discard block
 block discarded – undo
81 83
         );
82 84
 
83 85
         self::assertCount(2, $result);
84
-        foreach ($result as $suspendValue) {
86
+        foreach ($result as $suspendValue)
87
+        {
85 88
             self::assertSame(self::TEST_DATA, $suspendValue);
86 89
         }
87 90
     }
@@ -92,7 +95,8 @@  discard block
 block discarded – undo
92 95
         $this->expectExceptionMessage('test');
93 96
 
94 97
         self::runInFiber(
95
-            static function () {
98
+            static function ()
99
+            {
96 100
                 return (new Container())->runScoped(
97 101
                     function (): string {
98 102
                         $result = '';
@@ -114,15 +118,19 @@  discard block
 block discarded – undo
114 118
     public function testCatchThrownException(): void
115 119
     {
116 120
         $result = self::runInFiber(
117
-            static function () {
121
+            static function ()
122
+            {
118 123
                 return (new Container())->runScoped(
119 124
                     function (): string {
120 125
                         $result = '';
121 126
                         $result .= Fiber::suspend('foo');
122 127
                         $result .= Fiber::suspend('bar');
123
-                        try {
128
+                        try
129
+                        {
124 130
                             $result .= Fiber::suspend('error');
125
-                        } catch (\Throwable $e) {
131
+                        }
132
+                        catch (\Throwable $e)
133
+                        {
126 134
                             $result .= $e->getMessage();
127 135
                         }
128 136
                         $result .= Fiber::suspend('baz');
@@ -160,20 +168,23 @@  discard block
 block discarded – undo
160 168
             $c1 = $container ?? new Container();
161 169
             $c1->bindSingleton('resource', new stdClass());
162 170
 
163
-            $result = $c1->runScoped(static function (Container $c2) use ($load) {
171
+            $result = $c1->runScoped(static function (Container $c2) use ($load)
172
+            {
164 173
                 // check local binding
165 174
                 self::assertTrue($c2->has('foo'));
166 175
                 self::assertInstanceOf(DateTime::class, $c2->get('foo'));
167 176
 
168 177
                 return $c2->runScoped(
169
-                    static function (ContainerInterface $c3) use ($load) {
178
+                    static function (ContainerInterface $c3) use ($load)
179
+                    {
170 180
                         // check local binding
171 181
                         self::assertTrue($c3->has('bar'));
172 182
 
173 183
                         $resource = $c3->get('resource');
174 184
                         self::assertInstanceOf(DateTimeImmutable::class, $c3->get('bar'));
175 185
                         self::assertInstanceOf(stdClass::class, $resource);
176
-                        foreach (self::TEST_DATA as $key => $value) {
186
+                        foreach (self::TEST_DATA as $key => $value)
187
+                        {
177 188
                             $resource->$key = $value;
178 189
                             $load === null or $load();
179 190
                             Fiber::suspend($value);
@@ -204,11 +215,16 @@  discard block
 block discarded – undo
204 215
     {
205 216
         $fiber = new Fiber($callable);
206 217
         $value = $fiber->start();
207
-        while (!$fiber->isTerminated()) {
208
-            if ($check !== null) {
209
-                try {
218
+        while (!$fiber->isTerminated())
219
+        {
220
+            if ($check !== null)
221
+            {
222
+                try
223
+                {
210 224
                     $value = $check($value);
211
-                } catch (\Throwable $e) {
225
+                }
226
+                catch (\Throwable $e)
227
+                {
212 228
                     $value = $fiber->throw($e);
213 229
                     continue;
214 230
                 }
@@ -232,14 +248,17 @@  discard block
 block discarded – undo
232 248
         /** Values that were suspended by the fiber. */
233 249
         $suspends = [];
234 250
         $results = [];
235
-        foreach ($callables as $key => $callable) {
236
-            $fiberGenerators[$key] = (static function () use ($callable) {
251
+        foreach ($callables as $key => $callable)
252
+        {
253
+            $fiberGenerators[$key] = (static function () use ($callable)
254
+            {
237 255
                 $fiber = new Fiber($callable);
238 256
                 // Get ready
239 257
                 yield null;
240 258
 
241 259
                 $value = yield $fiber->start();
242
-                while (!$fiber->isTerminated()) {
260
+                while (!$fiber->isTerminated())
261
+                {
243 262
                     $value = yield $fiber->resume($value);
244 263
                 }
245 264
                 return $fiber->getReturn();
@@ -249,15 +268,21 @@  discard block
 block discarded – undo
249 268
         }
250 269
 
251 270
 
252
-        while ($fiberGenerators !== []) {
253
-            foreach ($fiberGenerators as $key => $generator) {
254
-                try {
271
+        while ($fiberGenerators !== [])
272
+        {
273
+            foreach ($fiberGenerators as $key => $generator)
274
+            {
275
+                try
276
+                {
255 277
                     $suspends[$key] = $generator->send($suspends[$key]);
256
-                    if (!$generator->valid()) {
278
+                    if (!$generator->valid())
279
+                    {
257 280
                         $results[$key] = $generator->getReturn();
258 281
                         unset($fiberGenerators[$key]);
259 282
                     }
260
-                } catch (\Throwable $e) {
283
+                }
284
+                catch (\Throwable $e)
285
+                {
261 286
                     unset($fiberGenerators[$key]);
262 287
                     $results[$key] = $e;
263 288
                 }
Please login to merge, or discard this patch.
src/Core/tests/Scope/SideEffectTest.php 1 patch
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -22,10 +22,12 @@  discard block
 block discarded – undo
22 22
         $root = new Container();
23 23
         $root->bind(LoggerInterface::class, KVLogger::class);
24 24
 
25
-        $root->runScoped(static function (Container $c1) {
25
+        $root->runScoped(static function (Container $c1)
26
+        {
26 27
             $c1->bind(LoggerInterface::class, FileLogger::class);
27 28
 
28
-            $c1->runScoped(static function (LoggerCarrier $carrier, LoggerInterface $logger) {
29
+            $c1->runScoped(static function (LoggerCarrier $carrier, LoggerInterface $logger)
30
+            {
29 31
                 // from the $root container
30 32
                 self::assertInstanceOf(KVLogger::class, $carrier->logger);
31 33
                 // from the $c1 container
@@ -39,7 +41,8 @@  discard block
 block discarded – undo
39 41
         $root = new Container();
40 42
         $root->bind(LoggerInterface::class, KVLogger::class);
41 43
 
42
-        $root->runScoped(static function (Container $c1) {
44
+        $root->runScoped(static function (Container $c1)
45
+        {
43 46
             $c1->bind(LoggerInterface::class, FileLogger::class);
44 47
 
45 48
             self::assertInstanceOf(
Please login to merge, or discard this patch.
src/Core/tests/Scope/FinalizeAttributeTest.php 1 patch
Braces   +26 added lines, -12 removed lines patch added patch discarded remove patch
@@ -21,8 +21,10 @@  discard block
 block discarded – undo
21 21
     {
22 22
         $root = new Container();
23 23
 
24
-        $obj = $root->runScoped(static function (Container $c1) {
25
-            $obj = $c1->runScoped(static function (Container $c2) {
24
+        $obj = $root->runScoped(static function (Container $c1)
25
+        {
26
+            $obj = $c1->runScoped(static function (Container $c2)
27
+            {
26 28
                 $obj = $c2->get(AttrScopeFooFinalize::class);
27 29
 
28 30
                 self::assertFalse($obj->finalized);
@@ -46,8 +48,10 @@  discard block
 block discarded – undo
46 48
         $root->bindSingleton(LoggerInterface::class, FileLogger::class);
47 49
 
48 50
         $obj2 = null;
49
-        $obj = $root->runScoped(static function (Container $c1) use (&$obj2) {
50
-            $obj = $c1->runScoped(static function (Container $c2) use (&$obj2) {
51
+        $obj = $root->runScoped(static function (Container $c1) use (&$obj2)
52
+        {
53
+            $obj = $c1->runScoped(static function (Container $c2) use (&$obj2)
54
+            {
51 55
                 $obj = $c2->get(AttrScopeFooFinalize::class);
52 56
                 $obj2 = $c2->get(AttrScopeFooFinalize::class);
53 57
 
@@ -77,8 +81,10 @@  discard block
 block discarded – undo
77 81
         $root->bindSingleton(LoggerInterface::class, FileLogger::class);
78 82
 
79 83
         $obj2 = null;
80
-        $obj = $root->runScoped(static function (Container $c1) use (&$obj2) {
81
-            $obj = $c1->runScoped(static function (Container $c2) use (&$obj2) {
84
+        $obj = $root->runScoped(static function (Container $c1) use (&$obj2)
85
+        {
86
+            $obj = $c1->runScoped(static function (Container $c2) use (&$obj2)
87
+            {
82 88
                 $obj = $c2->get(AttrFinalize::class);
83 89
                 $obj2 = $c2->get(AttrFinalize::class);
84 90
 
@@ -124,12 +130,16 @@  discard block
 block discarded – undo
124 130
         self::expectException(FinalizersException::class);
125 131
         self::expectExceptionMessage('An exception has been thrown during finalization of the scope `foo`');
126 132
 
127
-        try {
128
-            $root->runScoped(static function (Container $c1) {
133
+        try
134
+        {
135
+            $root->runScoped(static function (Container $c1)
136
+            {
129 137
                 $obj = $c1->get(AttrScopeFooFinalize::class);
130 138
                 $obj->throwException = true;
131 139
             }, name: 'foo');
132
-        } catch (FinalizersException $e) {
140
+        }
141
+        catch (FinalizersException $e)
142
+        {
133 143
             self::assertSame('foo', $e->getScope());
134 144
             self::assertCount(1, $e->getExceptions());
135 145
             // Contains the message from the inner exception.
@@ -153,13 +163,17 @@  discard block
 block discarded – undo
153 163
         self::expectException(FinalizersException::class);
154 164
         self::expectExceptionMessage('3 exceptions have been thrown during finalization of the scope `foo`');
155 165
 
156
-        try {
157
-            $root->runScoped(static function (Container $c1) {
166
+        try
167
+        {
168
+            $root->runScoped(static function (Container $c1)
169
+            {
158 170
                 $c1->get(AttrScopeFooFinalize::class)->throwException = true;
159 171
                 $c1->get(AttrScopeFooFinalize::class)->throwException = true;
160 172
                 $c1->get(AttrScopeFooFinalize::class)->throwException = true;
161 173
             }, name: 'foo');
162
-        } catch (FinalizersException $e) {
174
+        }
175
+        catch (FinalizersException $e)
176
+        {
163 177
             self::assertSame('foo', $e->getScope());
164 178
             self::assertCount(3, $e->getExceptions());
165 179
             // Contains the message from the inner exception.
Please login to merge, or discard this patch.
src/Core/tests/Scope/ExceptionsTest.php 1 patch
Braces   +21 added lines, -9 removed lines patch added patch discarded remove patch
@@ -20,11 +20,15 @@  discard block
 block discarded – undo
20 20
 
21 21
         $container = new Container();
22 22
 
23
-        $container->runScoped(static function (Container $c1) {
24
-            try {
23
+        $container->runScoped(static function (Container $c1)
24
+        {
25
+            try
26
+            {
25 27
                 $c1->get(ExceptionConstructor::class);
26 28
                 self::fail('Exception should be thrown');
27
-            } catch (\Throwable $e) {
29
+            }
30
+            catch (\Throwable $e)
31
+            {
28 32
                 // self::assertInstanceOf(\InvalidArgumentException::class, $e);
29 33
                 throw $e;
30 34
             }
@@ -38,11 +42,15 @@  discard block
 block discarded – undo
38 42
 
39 43
         $container = new Container();
40 44
 
41
-        $container->runScoped(static function (Container $c1) {
42
-            try {
45
+        $container->runScoped(static function (Container $c1)
46
+        {
47
+            try
48
+            {
43 49
                 $c1->get(ExceptionConstructor::class);
44 50
                 self::fail('Exception should be thrown');
45
-            } catch (\Throwable $e) {
51
+            }
52
+            catch (\Throwable $e)
53
+            {
46 54
                 // self::assertInstanceOf(\InvalidArgumentException::class, $e);
47 55
                 throw $e;
48 56
             }
@@ -56,11 +64,15 @@  discard block
 block discarded – undo
56 64
 
57 65
         $container = new Container();
58 66
 
59
-        $container->runScoped(static function (Container $c1) {
60
-            try {
67
+        $container->runScoped(static function (Container $c1)
68
+        {
69
+            try
70
+            {
61 71
                 $c1->get(DatetimeCarrier::class);
62 72
                 self::fail('Exception should be thrown');
63
-            } catch (\Throwable $e) {
73
+            }
74
+            catch (\Throwable $e)
75
+            {
64 76
                 self::assertInstanceOf(NotFoundException::class, $e);
65 77
                 self::assertInstanceOf(NotFoundException::class, $e->getPrevious());
66 78
                 self::assertStringContainsString(
Please login to merge, or discard this patch.
src/Core/tests/Scope/UseCaseTest.php 1 patch
Braces   +12 added lines, -6 removed lines patch added patch discarded remove patch
@@ -23,7 +23,8 @@  discard block
 block discarded – undo
23 23
         $root = new Container();
24 24
         $root->bind('foo', SampleClass::class);
25 25
 
26
-        $root->runScoped(function (ContainerInterface $c1) {
26
+        $root->runScoped(function (ContainerInterface $c1)
27
+        {
27 28
             $c1->get('foo');
28 29
         }, bindings: ['foo' => SampleClass::class]);
29 30
 
@@ -54,7 +55,8 @@  discard block
 block discarded – undo
54 55
     {
55 56
         $root = new Container();
56 57
 
57
-        $root->runScoped(function (ContainerInterface $c1) use ($theSame, $alias) {
58
+        $root->runScoped(function (ContainerInterface $c1) use ($theSame, $alias)
59
+        {
58 60
             $obj1 = $c1->get($alias);
59 61
             $obj2 = $c1->get($alias);
60 62
 
@@ -79,14 +81,16 @@  discard block
 block discarded – undo
79 81
     {
80 82
         $root = new Container();
81 83
 
82
-        $root->runScoped(function (ContainerInterface $c1) use ($root) {
84
+        $root->runScoped(function (ContainerInterface $c1) use ($root)
85
+        {
83 86
             $obj1 = $c1->get('foo');
84 87
             $this->weakMap->offsetSet($obj1, true);
85 88
 
86 89
             self::assertNotSame($root, $c1);
87 90
             self::assertInstanceOf(stdClass::class, $obj1);
88 91
 
89
-            $c1->runScoped(function (ContainerInterface $c2) use ($root, $c1, $obj1) {
92
+            $c1->runScoped(function (ContainerInterface $c2) use ($root, $c1, $obj1)
93
+            {
90 94
                 $obj2 = $c2->get('foo');
91 95
                 $this->weakMap->offsetSet($obj2, true);
92 96
 
@@ -115,14 +119,16 @@  discard block
 block discarded – undo
115 119
         $root->bindSingleton('bar', [Factory::class, 'makeStdClass']);
116 120
         $root->bind(stdClass::class, new stdClass());
117 121
 
118
-        $root->runScoped(function (ContainerInterface $c1) use ($root) {
122
+        $root->runScoped(function (ContainerInterface $c1) use ($root)
123
+        {
119 124
             $obj1 = $c1->get('foo');
120 125
             $this->weakMap->offsetSet($obj1, true);
121 126
 
122 127
             self::assertInstanceOf(stdClass::class, $obj1);
123 128
             // Singleton must be the same
124 129
             self::assertSame($c1->get('bar'), $root->get('bar'));
125
-            $c1->runScoped(function (ContainerInterface $c2) use ($root, $obj1) {
130
+            $c1->runScoped(function (ContainerInterface $c2) use ($root, $obj1)
131
+            {
126 132
                 $obj2 = $c2->get('foo');
127 133
 
128 134
                 self::assertInstanceOf(stdClass::class, $obj2);
Please login to merge, or discard this patch.
src/Core/tests/Scope/ScopeAttributeTest.php 1 patch
Braces   +32 added lines, -15 removed lines patch added patch discarded remove patch
@@ -33,8 +33,10 @@  discard block
 block discarded – undo
33 33
     {
34 34
         $root = new Container();
35 35
 
36
-        $root->runScoped(static function (Container $c1) {
37
-            $c1->runScoped(static function (Container $c2) use ($c1) {
36
+        $root->runScoped(static function (Container $c1)
37
+        {
38
+            $c1->runScoped(static function (Container $c2) use ($c1)
39
+            {
38 40
                 $obj1 = $c1->get(AttrScopeFooSingleton::class);
39 41
                 $obj2 = $c2->get(AttrScopeFooSingleton::class);
40 42
 
@@ -56,8 +58,10 @@  discard block
 block discarded – undo
56 58
         $root = new Container();
57 59
         $root->bind('foo', self::makeFooScopeObject(...));
58 60
 
59
-        $root->runScoped(static function (Container $c1) {
60
-            $c1->runScoped(static function (Container $c2) {
61
+        $root->runScoped(static function (Container $c1)
62
+        {
63
+            $c1->runScoped(static function (Container $c2)
64
+            {
61 65
                 $c2->get('foo');
62 66
             }, name: 'foo');
63 67
         });
@@ -75,8 +79,10 @@  discard block
 block discarded – undo
75 79
         $root = new Container();
76 80
         $root->bind('foo', self::makeFooScopeObject(...));
77 81
 
78
-        $root->runScoped(static function (Container $c1) {
79
-            $c1->runScoped(static function (Container $c2) {
82
+        $root->runScoped(static function (Container $c1)
83
+        {
84
+            $c1->runScoped(static function (Container $c2)
85
+            {
80 86
                 $c2->get('foo');
81 87
             });
82 88
         });
@@ -94,15 +100,21 @@  discard block
 block discarded – undo
94 100
 
95 101
         $root = new Container();
96 102
 
97
-        try {
98
-            $root->runScoped(static function (Container $c1) {
99
-                $c1->runScoped(static function (Container $c2) {
100
-                    $c2->runScoped(static function (Container $c3) {
103
+        try
104
+        {
105
+            $root->runScoped(static function (Container $c1)
106
+            {
107
+                $c1->runScoped(static function (Container $c2)
108
+                {
109
+                    $c2->runScoped(static function (Container $c3)
110
+                    {
101 111
                         // do nothing
102 112
                     }, name: 'root');
103 113
                 });
104 114
             });
105
-        } catch (NamedScopeDuplicationException $e) {
115
+        }
116
+        catch (NamedScopeDuplicationException $e)
117
+        {
106 118
             self::assertSame('root', $e->getScope());
107 119
             throw $e;
108 120
         }
@@ -117,14 +129,19 @@  discard block
 block discarded – undo
117 129
     {
118 130
         self::expectException(BadScopeException::class);
119 131
 
120
-        try {
132
+        try
133
+        {
121 134
             $root = new Container();
122
-            $root->runScoped(static function (Container $c1) {
123
-                $c1->runScoped(static function (Container $c2) {
135
+            $root->runScoped(static function (Container $c1)
136
+            {
137
+                $c1->runScoped(static function (Container $c2)
138
+                {
124 139
                     $c2->get(AttrScopeFoo::class);
125 140
                 });
126 141
             }, name: 'bar');
127
-        } catch (BadScopeException $e) {
142
+        }
143
+        catch (BadScopeException $e)
144
+        {
128 145
             self::assertSame('foo', $e->getScope());
129 146
             throw $e;
130 147
         }
Please login to merge, or discard this patch.