Ejemplo n.º 1
0
 public function testGetHttpStatusString()
 {
     $sProtocol = 'HTTP/1.1';
     $iStatus = HttpResponseType::ACCEPTED;
     $FullStatus = $sProtocol . ' ' . HttpResponseType::getStatus($iStatus);
     $this->assertEquals($FullStatus, HttpResponseA_underTest_getHttpStatusString::getHttpStatusString($sProtocol, $iStatus));
 }
Ejemplo n.º 2
0
 public function testBasicGetList()
 {
     $Mirror = new \ReflectionClass(HttpResponseType::class);
     $MirrorProperty = $Mirror->getProperty('aStatusList');
     $MirrorProperty->setAccessible(\ReflectionProperty::IS_PUBLIC);
     $aStatuses = $MirrorProperty->getValue();
     $this->assertEquals($aStatuses, HttpResponseType::getList());
 }
Ejemplo n.º 3
0
 public function providerForHttpStatuses()
 {
     $aStatuses = HttpResponseType::getList();
     $return = array();
     foreach ($aStatuses as $iStatus => $sStatus) {
         $return[] = [$iStatus];
     }
     return $return;
 }
Ejemplo n.º 4
0
 public function providerForTestBasicGetRedirectCode()
 {
     $aStatuses = HttpResponseType::getList();
     $return = array();
     foreach ($aStatuses as $iStatus => $sStatus) {
         $return[] = [$iStatus];
     }
     return $return;
 }
Ejemplo n.º 5
0
 public function testBasicIsValidStatus()
 {
     $Mirror = new \ReflectionClass(HttpResponseType::class);
     $MirrorProperty = $Mirror->getProperty('aStatusList');
     $MirrorProperty->setAccessible(\ReflectionProperty::IS_PUBLIC);
     $aStatuses = $MirrorProperty->getValue();
     for ($i = 0; $i < 600; $i++) {
         if (array_key_exists($i, $aStatuses)) {
             $this->assertTrue(HttpResponseType::isValidStatus($i));
         } else {
             $this->assertFalse(HttpResponseType::isValidStatus($i));
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * @param string $sProtocol
  * @param int $iStatus
  * @return string
  */
 public static function getHttpStatusString($sProtocol, $iStatus)
 {
     return $sProtocol . ' ' . HttpResponseType::getStatus($iStatus);
 }
Ejemplo n.º 7
0
 /**
  * @dataProvider providerForTestGetStatus
  * @param $iStatus
  * @param $sStatusText
  */
 public function testGetStatus($iStatus, $sStatusText)
 {
     $this->assertEquals($sStatusText, HttpResponseType::getStatus($iStatus));
 }
Ejemplo n.º 8
0
 /**
  * @param int $iStatus
  */
 public function setResponseStatus($iStatus)
 {
     if (HttpResponseType::isValidStatus($iStatus)) {
         $this->iHttpStatus = $iStatus;
     }
 }
Ejemplo n.º 9
0
 /**
  * @param \Exception $e
  * @param HttpRequestA $oRequest
  * @return HttpResponseA
  * @throws ExceptionPath
  * @throws ExceptionResponse
  */
 public function getErrorResponse(\Exception $e, $oRequest = null)
 {
     $oResponse = vsc::getEnv()->getHttpResponse();
     $oProcessor = new ErrorProcessor($e);
     /* @var ControllerMap $oMyMap */
     $oMyMap = $this->getMap();
     $oMyMap->setMainTemplatePath(VSC_RES_PATH . 'templates');
     $oMyMap->setMainTemplate('main.php');
     if (!HttpRequestA::isValid($oRequest)) {
         $oRequest = vsc::getEnv()->getHttpRequest();
     }
     /** @var ErrorModel $oModel */
     $oModel = $oProcessor->handleRequest($oRequest);
     $iCode = $oModel->getHttpStatus();
     if (HttpResponseType::isValidStatus($iCode)) {
         $oResponse->setStatus($iCode);
     } else {
         $oResponse->setStatus(500);
     }
     // we didn't set any special view
     // this means that the developer needs to provide his own views
     $oView = $this->getView();
     /* @var ProcessorMap $oMap */
     $oMap = $oProcessor->getMap();
     $oMap->merge($oMyMap);
     $oProcessorResponse = $oMap->getResponse();
     if (HttpResponseA::isValid($oProcessorResponse)) {
         $oResponse = $oProcessorResponse;
     }
     // setting the processor map
     $oView->setMap($oMap);
     if (ControllerMap::isValid($oMyMap)) {
         $oView->setMainTemplate($oMyMap->getMainTemplatePath() . DIRECTORY_SEPARATOR . $oView->getViewFolder() . DIRECTORY_SEPARATOR . $oMyMap->getMainTemplate());
     }
     $oView->setModel($oModel);
     $oResponse->setView($oView);
     $aHeaders = $oMap->getHeaders();
     if (count($aHeaders) > 0) {
         foreach ($aHeaders as $sName => $sHeader) {
             $oResponse->addHeader($sName, $sHeader);
         }
     }
     return $oResponse;
 }