Browse Source

Use EventInterface::setResult() instead of returning value.

ADmad 2 years ago
parent
commit
220784c0ee

+ 4 - 4
src/Core/TestSuite/ContainerStubTrait.php

@@ -138,12 +138,12 @@ trait ContainerStubTrait
      *
      * @param \Cake\Event\EventInterface $event The event
      * @param \Cake\Core\ContainerInterface $container The container to wrap.
-     * @return \Cake\Core\ContainerInterface|null
+     * @return void
      */
-    public function modifyContainer(EventInterface $event, ContainerInterface $container): ?ContainerInterface
+    public function modifyContainer(EventInterface $event, ContainerInterface $container): void
     {
         if (empty($this->containerServices)) {
-            return null;
+            return;
         }
         foreach ($this->containerServices as $key => $factory) {
             if ($container->has($key)) {
@@ -157,7 +157,7 @@ trait ContainerStubTrait
             }
         }
 
-        return $container;
+        $event->setResult($container);
     }
 
     /**

+ 3 - 2
tests/TestCase/Http/BaseApplicationTest.php

@@ -21,6 +21,7 @@ use Cake\Core\BasePlugin;
 use Cake\Core\Configure;
 use Cake\Core\Container;
 use Cake\Core\ContainerInterface;
+use Cake\Event\EventInterface;
 use Cake\Http\BaseApplication;
 use Cake\Http\MiddlewareQueue;
 use Cake\Http\ServerRequest;
@@ -259,11 +260,11 @@ class BaseApplicationTest extends TestCase
     public function testBuildContainerEventReplaceContainer(): void
     {
         $app = $this->getMockForAbstractClass(BaseApplication::class, [$this->path]);
-        $app->getEventManager()->on('Application.buildContainer', function () {
+        $app->getEventManager()->on('Application.buildContainer', function (EventInterface $event) {
             $new = new Container();
             $new->add('testing', 'yes');
 
-            return $new;
+            $event->setResult($new);
         });
 
         $container = $app->getContainer();