ソースを参照

fixed reading data property on tests

thinkingmedia 9 年 前
コミット
61fe5cedc6

+ 1 - 1
src/Event/Event.php

@@ -24,7 +24,7 @@ namespace Cake\Event;
  * @property mixed $result Property used to retain the result value of the event listeners
  * @property array $data Custom data for the method that receives the event
  */
-class Event implements EventInterface
+class Event
 {
 
     /**

+ 0 - 82
src/Event/EventInterface.php

@@ -1,82 +0,0 @@
-<?php
-/**
- * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
- * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- *
- * Licensed under The MIT License
- * For full copyright and license information, please see the LICENSE.txt
- * Redistributions of files must retain the above copyright notice.
- *
- * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
- * @link          http://cakephp.org CakePHP(tm) Project
- * @since         3.3.2
- * @license       http://www.opensource.org/licenses/mit-license.php MIT License
- */
-namespace Cake\Event;
-
-/**
- * Represents the transport interface for events across the system.
- */
-interface EventInterface
-{
-    /**
-     * Access the event data/payload.
-     *
-     * @param string|null $key The string identifier for the data payload, or if null all of the payload is returned.
-     * @return array|null The data payload if $key is null, or the data value for the given $key. If the $key does not
-     * exist a null value should be returned.
-     */
-    public function data($key = null);
-
-    /**
-     * Check if the event is stopped
-     *
-     * @return bool True if the event is stopped
-     */
-    public function isStopped();
-
-    /**
-     * Returns the name of this event. This is usually used as the event identifier
-     *
-     * @return string
-     */
-    public function name();
-
-    /**
-     * The result value of the event listeners
-     *
-     * @return mixed
-     */
-    public function result();
-
-    /**
-     * Modify the event data/payload.
-     *
-     * @param array|string $key The string identifier to be modified, or an array to replace the payload.
-     * @param mixed $value The payload value to be modified if $key is a string, otherwise ignored.
-     * @return $this
-     */
-    public function setData($key, $value = null);
-
-    /**
-     * Assigns a result value for the event listener. If a result has already be assigned it will be overwritten.
-     *
-     * @param mixed $value
-     * @return $this
-     */
-    public function setResult($value = null);
-
-    /**
-     * Stops the event from being used anymore
-     *
-     * @return void
-     */
-    public function stopPropagation();
-
-    /**
-     * Returns the subject of this event
-     *
-     * @return object
-     */
-    public function subject();
-}

+ 3 - 3
src/Routing/Filter/ControllerFactoryFilter.php

@@ -44,9 +44,9 @@ class ControllerFactoryFilter extends DispatcherFilter
      */
     public function beforeDispatch(Event $event)
     {
-        $request = $event->data['request'];
-        $response = $event->data['response'];
-        $event->data['controller'] = $this->_getController($request, $response);
+        $request = $event->data('request');
+        $response = $event->data('response');
+        $event->setData('controller', $this->_getController($request, $response));
     }
 
     /**

+ 3 - 2
src/Routing/Filter/RoutingFilter.php

@@ -47,7 +47,7 @@ class RoutingFilter extends DispatcherFilter
      */
     public function beforeDispatch(Event $event)
     {
-        $request = $event->data['request'];
+        $request = $event->data('request');
         if (Router::getRequest(true) !== $request) {
             Router::setRequestInfo($request);
         }
@@ -57,9 +57,10 @@ class RoutingFilter extends DispatcherFilter
                 $params = Router::parse($request->url, $request->method());
                 $request->addParams($params);
             }
+            return null;
         } catch (RedirectException $e) {
             $event->stopPropagation();
-            $response = $event->data['response'];
+            $response = $event->data('response');
             $response->statusCode($e->getCode());
             $response->header('Location', $e->getMessage());
 

+ 4 - 4
tests/TestCase/Event/Decorator/ConditionDecoratorTest.php

@@ -38,7 +38,7 @@ class ConditionDecoratorTest extends TestCase
 
         $decorator = new ConditionDecorator($callable, [
             'if' => function (Event $event) {
-                return $event->data['canTrigger'];
+                return $event->data('canTrigger');
             }
         ]);
 
@@ -63,7 +63,7 @@ class ConditionDecoratorTest extends TestCase
     public function testCascadingEvents()
     {
         $callable = function (Event $event) {
-            $event->data['counter']++;
+            $event->setData('counter', $event->data('counter') + 1);
 
             return $event;
         };
@@ -75,7 +75,7 @@ class ConditionDecoratorTest extends TestCase
         ]);
 
         $listener2 = function (Event $event) {
-            $event->data['counter']++;
+            $event->setData('counter', $event->data('counter') + 1);
 
             return $event;
         };
@@ -88,7 +88,7 @@ class ConditionDecoratorTest extends TestCase
         ]);
 
         EventManager::instance()->dispatch($event);
-        $this->assertEquals(2, $event->data['counter']);
+        $this->assertEquals(2, $event->data('counter'));
     }
 
     /**

+ 1 - 1
tests/TestCase/Event/EventManagerTest.php

@@ -702,7 +702,7 @@ class EventManagerTest extends TestCase
         $manager = new EventManager();
         $event = new Event('my_event', $manager);
         $manager->dispatch($event);
-        $this->assertEquals('ok', $event->data['callback']);
+        $this->assertEquals('ok', $event->data('callback'));
     }
 
     /**

+ 1 - 1
tests/TestCase/Event/EventTest.php

@@ -78,7 +78,7 @@ class EventTest extends TestCase
     public function testEventData()
     {
         $event = new Event('fake.event', $this, ['some' => 'data']);
-        $this->assertEquals(['some' => 'data'], $event->data);
+        $this->assertEquals(['some' => 'data'], $event->data());
     }
 
     /**

+ 1 - 2
tests/test_app/TestApp/Routing/Filter/AppendFilter.php

@@ -2,14 +2,13 @@
 namespace TestApp\Routing\Filter;
 
 use Cake\Event\Event;
-use Cake\Network\Response;
 use Cake\Routing\DispatcherFilter;
 
 class AppendFilter extends DispatcherFilter
 {
     public function afterDispatch(Event $event)
     {
-        $response = $event->data['response'];
+        $response = $event->data('response');
         $response->body($response->body() . ' appended content');
     }
 }