Skip to content

Commit

Permalink
remove unneded SendResponseListener detach
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Jan 4, 2019
1 parent 98741f9 commit 87826af
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 39 deletions.
33 changes: 0 additions & 33 deletions spec/Listener/ForceHttpsSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Zend\Http\PhpEnvironment\Response;
use Zend\Mvc\Application;
use Zend\Mvc\MvcEvent;
use Zend\Mvc\SendResponseListener;
use Zend\Router\RouteMatch;
use Zend\Uri\Uri;

Expand Down Expand Up @@ -76,8 +75,6 @@

beforeEach(function () {
$this->mvcEvent = Double::instance(['extends' => MvcEvent::class, 'methods' => '__construct']);
$this->application = Double::instance(['extends' => Application::class, 'methods' => '__construct']);
$this->sendResponseListener = Double::instance(['extends' => SendResponseListener::class, 'methods' => '__construct']);
$this->response = Double::instance(['extends' => Response::class]);
$this->request = Double::instance(['extends' => Request::class]);
$this->uri = Double::instance(['extends' => Uri::class]);
Expand Down Expand Up @@ -157,12 +154,6 @@
allow($this->response)->toReceive('getHeaders', 'addHeaderLine')->with('Location', 'https://example.com/about');
allow($this->response)->toReceive('send');

allow($this->mvcEvent)->toReceive('getApplication')->andReturn($this->application);
allow($this->application)->toReceive('getEventManager')->andReturn($this->eventManager);
allow($this->application)->toReceive('getServiceManager', 'get')
->with('SendResponseListener')
->andReturn($this->sendResponseListener);

$closure = function () use ($listener) {
$listener->forceHttpsScheme($this->mvcEvent);
};
Expand Down Expand Up @@ -198,12 +189,6 @@
allow($this->response)->toReceive('getHeaders', 'addHeaderLine')->with('Location', 'https://example.com/about');
allow($this->response)->toReceive('send');

allow($this->mvcEvent)->toReceive('getApplication')->andReturn($this->application);
allow($this->application)->toReceive('getEventManager')->andReturn($this->eventManager);
allow($this->application)->toReceive('getServiceManager', 'get')
->with('SendResponseListener')
->andReturn($this->sendResponseListener);

$closure = function () use ($listener) {
$listener->forceHttpsScheme($this->mvcEvent);
};
Expand Down Expand Up @@ -237,12 +222,6 @@
allow($this->response)->toReceive('getHeaders', 'addHeaderLine')->with('Location', 'https://example.com/about');
allow($this->response)->toReceive('send');

allow($this->mvcEvent)->toReceive('getApplication')->andReturn($this->application);
allow($this->application)->toReceive('getEventManager')->andReturn($this->eventManager);
allow($this->application)->toReceive('getServiceManager', 'get')
->with('SendResponseListener')
->andReturn($this->sendResponseListener);

$closure = function () use ($listener) {
$listener->forceHttpsScheme($this->mvcEvent);
};
Expand Down Expand Up @@ -278,12 +257,6 @@
allow($this->response)->toReceive('getHeaders', 'addHeaderLine')->with('Location', 'https://example.com/about');
allow($this->response)->toReceive('send');

allow($this->mvcEvent)->toReceive('getApplication')->andReturn($this->application);
allow($this->application)->toReceive('getEventManager')->andReturn($this->eventManager);
allow($this->application)->toReceive('getServiceManager', 'get')
->with('SendResponseListener')
->andReturn($this->sendResponseListener);

$closure = function () use ($listener) {
$listener->forceHttpsScheme($this->mvcEvent);
};
Expand Down Expand Up @@ -321,12 +294,6 @@
->with('Location', 'https://example.com/about')
->andReturn($this->response);

allow($this->mvcEvent)->toReceive('getApplication')->andReturn($this->application);
allow($this->application)->toReceive('getEventManager')->andReturn($this->eventManager);
allow($this->application)->toReceive('getServiceManager', 'get')
->with('SendResponseListener')
->andReturn($this->sendResponseListener);

allow($this->response)->toReceive('setStatusCode')->with(308)->andReturn($this->response);
allow($this->response)->toReceive('send');

Expand Down
6 changes: 0 additions & 6 deletions src/Listener/ForceHttps.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,6 @@ public function forceHttpsScheme(MvcEvent $e) : void
$httpsRequestUri = $this->getFinalhttpsRequestUri($uriString);
}

$application = $e->getApplication();
$events = $application->getEventManager();
$serviceManager = $application->getServiceManager();
$serviceManager->get('SendResponseListener')
->detach($events);

// 308 keeps headers, request method, and request body
$response->setStatusCode(308);
$response->getHeaders()
Expand Down

0 comments on commit 87826af

Please sign in to comment.