/** * @return void */ protected function execute() { try { $this->cacheInvalidator->flush(); } catch (ExceptionCollection $exceptions) { foreach ($exceptions as $exception) { if ($exception instanceof ProxyResponseException) { $this->systemLogger->log(sprintf('Error calling Varnish with BAN request (cannot connect to the caching proxy). Error %s', $exception->getMessage()), LOG_ERR); } elseif ($exception instanceof ProxyUnreachableException) { $this->systemLogger->log(sprintf('Error calling Varnish with BAN request (caching proxy returned an error response). Error %s', $exception->getMessage()), LOG_ERR); } else { $this->systemLogger->log(sprintf('Error calling Varnish with BAN request. Error %s', $exception->getMessage()), LOG_ERR); } } } }
/** * @expectedException \FOS\HttpCache\Exception\ExceptionCollection */ public function testProxyClientExceptionsAreLogged() { $unreachableException = ProxyUnreachableException::proxyUnreachable('http://127.0.0.1', 'Couldn\'t connect to host'); $responseException = ProxyResponseException::proxyResponse('http://127.0.0.1', 403, 'Forbidden'); $exceptions = new ExceptionCollection(); $exceptions->add($unreachableException)->add($responseException); $proxyClient = \Mockery::mock('\FOS\HttpCache\ProxyClient\ProxyClientInterface') ->shouldReceive('flush')->once()->andThrow($exceptions) ->getMock(); $cacheInvalidator = new CacheInvalidator($proxyClient); $logger = \Mockery::mock('\Psr\Log\LoggerInterface') ->shouldReceive('log')->once() ->with( 'critical', 'Request to caching proxy at http://127.0.0.1 failed with message "Couldn\'t connect to host"', array( 'exception' => $unreachableException ) ) ->shouldReceive('log')->once() ->with('critical', '403 error response "Forbidden" from caching proxy at http://127.0.0.1', array('exception' => $responseException)) ->getMock(); $cacheInvalidator->addSubscriber(new LogSubscriber($logger)); $cacheInvalidator ->flush() ; }