ソースを参照

EventManager::dispatch() returns event not result.

ADmad 12 年 前
コミット
7c3a7c16cb
2 ファイル変更26 行追加18 行削除
  1. 15 15
      src/Controller/Controller.php
  2. 11 3
      tests/TestCase/Controller/ControllerTest.php

+ 15 - 15
src/Controller/Controller.php

@@ -514,13 +514,13 @@ class Controller implements EventListener {
  * @return void|\Cake\Network\Response
  */
 	public function startupProcess() {
-		$result = $this->getEventManager()->dispatch(new Event('Controller.initialize', $this));
-		if ($result instanceof Response) {
-			return $result;
+		$event = $this->getEventManager()->dispatch(new Event('Controller.initialize', $this));
+		if ($event->result instanceof Response) {
+			return $event->result;
 		}
-		$result = $this->getEventManager()->dispatch(new Event('Controller.startup', $this));
-		if ($result instanceof Response) {
-			return $result;
+		$event = $this->getEventManager()->dispatch(new Event('Controller.startup', $this));
+		if ($event->result instanceof Response) {
+			return $event->result;
 		}
 	}
 
@@ -534,9 +534,9 @@ class Controller implements EventListener {
  * @return void|\Cake\Network\Response
  */
 	public function shutdownProcess() {
-		$result = $this->getEventManager()->dispatch(new Event('Controller.shutdown', $this));
-		if ($result instanceof Response) {
-			return $result;
+		$event = $this->getEventManager()->dispatch(new Event('Controller.shutdown', $this));
+		if ($event->result instanceof Response) {
+			return $event->result;
 		}
 	}
 
@@ -559,9 +559,9 @@ class Controller implements EventListener {
 		}
 
 		$event = new Event('Controller.beforeRedirect', $this, [$response, $url, $status]);
-		$result = $this->getEventManager()->dispatch($event);
-		if ($result instanceof Response) {
-			return $response;
+		$event = $this->getEventManager()->dispatch($event);
+		if ($event->result instanceof Response) {
+			return $event->result;
 		}
 		if ($event->isStopped()) {
 			return;
@@ -606,10 +606,10 @@ class Controller implements EventListener {
  */
 	public function render($view = null, $layout = null) {
 		$event = new Event('Controller.beforeRender', $this);
-		$result = $this->getEventManager()->dispatch($event);
-		if ($result instanceof Response) {
+		$event = $this->getEventManager()->dispatch($event);
+		if ($event->result instanceof Response) {
 			$this->autoRender = false;
-			return $result;
+			return $event->result;
 		}
 		if ($event->isStopped()) {
 			$this->autoRender = false;

+ 11 - 3
tests/TestCase/Controller/ControllerTest.php

@@ -632,7 +632,9 @@ class ControllerTest extends TestCase {
 					$this->attributeEqualTo('_name', 'Controller.initialize'),
 					$this->attributeEqualTo('_subject', $Controller)
 				)
-			);
+			)
+			->will($this->returnValue($this->getMock('Cake\Event\Event', null, [], '', false)));
+
 		$eventManager->expects($this->at(1))->method('dispatch')
 			->with(
 				$this->logicalAnd(
@@ -640,9 +642,12 @@ class ControllerTest extends TestCase {
 					$this->attributeEqualTo('_name', 'Controller.startup'),
 					$this->attributeEqualTo('_subject', $Controller)
 				)
-			);
+			)
+			->will($this->returnValue($this->getMock('Cake\Event\Event', null, [], '', false)));
+
 		$Controller->expects($this->exactly(2))->method('getEventManager')
 			->will($this->returnValue($eventManager));
+
 		$Controller->startupProcess();
 	}
 
@@ -662,9 +667,12 @@ class ControllerTest extends TestCase {
 					$this->attributeEqualTo('_name', 'Controller.shutdown'),
 					$this->attributeEqualTo('_subject', $Controller)
 				)
-			);
+			)
+			->will($this->returnValue($this->getMock('Cake\Event\Event', null, [], '', false)));
+
 		$Controller->expects($this->once())->method('getEventManager')
 			->will($this->returnValue($eventManager));
+
 		$Controller->shutdownProcess();
 	}