Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Detach InjectViewModelListener before forwarding. #258

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions src/Controller/Plugin/Forward.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,11 @@ protected function detachProblemListeners(SharedEvents $sharedEvents)
foreach ($events as $priority => $currentPriorityEvents) {
foreach ($currentPriorityEvents as $currentEvent) {
$currentCallback = $currentEvent;

// If we have an array, grab the object
if (is_array($currentCallback)) {
$currentCallback = array_shift($currentCallback);
}

// This routine is only valid for object callbacks
if (! is_object($currentCallback)) {
continue;
foreach ($classArray as $class) {
if (isset($currentCallback[0]) && $currentCallback[0] instanceof $class) {
$sharedEvents->detach($currentEvent);
$results[$id][$eventName][$priority] = $currentCallback;
}
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions test/Controller/Plugin/ForwardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,25 @@ function ($e) {}
$this->assertEquals(['content' => 'ZendTest\Mvc\Controller\TestAsset\ForwardController::testAction'], $result);
}

public function testDetachmentOfInjectViewModelListener()
{
$services = $this->services;
$events = $services->get('EventManager');
$sharedEvents = $this->createMock(SharedEventManagerInterface::class);
$callback = [$this->createMock('Zend\Mvc\View\Http\InjectViewModelListener'), 'injectViewModel'];
$sharedEvents->expects($this->any())->method('getListeners')->will($this->returnValue([
[$callback]
]));
$sharedEvents->expects($this->once())->method('detach')->with($this->equalTo($callback));
$events = $this->createEventManager($sharedEvents);
$application = $this->createMock(ApplicationInterface::class);
$application->expects($this->any())->method('getEventManager')->will($this->returnValue($events));
$event = $this->controller->getEvent();
$event->setApplication($application);

$result = $this->plugin->dispatch('forward');
}

public function testDispatchWillSeedRouteMatchWithPassedParameters()
{
$result = $this->plugin->dispatch('forward', [
Expand Down