Пример #1
0
 /**
  * @inherit
  */
 public function handleError(\R3H6\Error404page\Domain\Model\Error $error)
 {
     if ($this->httpService->isOwnRequest()) {
         $this->getLogger()->debug("Throw exception 1475311053");
         throw new \Exception("Error processing request", 1475311053);
     }
     if ($this->extensionConfiguration->is('enableErrorLog')) {
         $this->errorRepository->log($error);
     }
     $cacheIdentifier = $this->errorHandlerCache->calculateCacheIdentifier($error);
     $errorHandler = $this->errorHandlerCache->get($cacheIdentifier);
     if ($errorHandler === null) {
         foreach ($this->getErrorHandlers() as $errorHandler) {
             try {
                 $this->getLogger()->debug('Try handle error with ' . get_class($errorHandler));
                 if ($errorHandler->handleError($error)) {
                     $this->errorHandlerCache->set($cacheIdentifier, $errorHandler);
                     break;
                 }
             } catch (\Exception $exception) {
                 $this->getLogger()->debug('Could not handle error in ' . get_class($errorHandler) . ': ' . $exception->getMessage());
             }
         }
     }
     $this->getLogger()->debug('Get error handler output of ' . get_class($errorHandler));
     return $errorHandler->getOutput($error);
 }
 /**
  * @test
  */
 public function calculateCacheIdentifierRespectsCurrentUrlForForbiddenErrors()
 {
     /** @var \R3H6\Error404page\Domain\Model\Error $errorFixture */
     $errorFixture = new Error();
     $errorFixture->setStatusCode(Error::STATUS_CODE_FORBIDDEN);
     $cacheIdentifier1 = $this->subject->calculateCacheIdentifier($errorFixture);
     $errorFixture->setCurrentUrl('page/not/found.html');
     $cacheIdentifier2 = $this->subject->calculateCacheIdentifier($errorFixture);
     $this->assertNotEquals($cacheIdentifier1, $cacheIdentifier2);
 }
Пример #3
0
 /**
  * @test
  */
 public function setAndGet()
 {
     $expected = uniqid();
     /** @var \R3H6\Error404page\Domain\Handler\ErrorHandlerInterface $errorHandlerFixture */
     $errorHandlerFixture = new ErrorHandlerFixture($expected);
     $cacheIdentifierFixture = sha1(uniqid());
     $this->subject->set($cacheIdentifierFixture, $errorHandlerFixture);
     $this->assertSame(1, $this->getDatabaseConnection()->exec_SELECTcountRows('*', 'cf_cache_pages'));
     $this->assertSame(2, $this->getDatabaseConnection()->exec_SELECTcountRows('*', 'cf_cache_pages_tags'));
     $errorHandler = $this->subject->get($cacheIdentifierFixture);
     $this->assertNotSame($errorHandlerFixture, $errorHandler, 'Object from cache is not a new instance');
     $this->assertInstanceOf('R3H6\\Error404page\\Tests\\Functional\\Fixtures\\ErrorHandlerFixture', $errorHandler);
     $this->assertSame($expected, $errorHandler->getCachingData());
 }
 /**
  * @test
  */
 public function handleErrorGetsOutputFromCache()
 {
     $expected = 'TYPO3';
     /** @var \R3H6\Error404page\Domain\Model\Error $errorFixture */
     $errorFixture = new Error();
     $cacheIdentifierFixture = sha1(uniqid());
     $errorHandlerMock = $this->getMock('R3H6\\Error404page\\Domain\\Handler\\ErrorHandlerInterface');
     $errorHandlerMock->expects($this->once())->method('getOutput')->will($this->returnValue($expected));
     $this->errorHandlerCacheMock->expects($this->once())->method('calculateCacheIdentifier')->with($errorFixture)->will($this->returnValue($cacheIdentifierFixture));
     $this->errorHandlerCacheMock->expects($this->once())->method('get')->with($cacheIdentifierFixture)->will($this->returnValue($errorHandlerMock));
     $this->assertSame($expected, $this->subject->handleError($errorFixture));
 }