web/lib/Zend/Test/PHPUnit/Constraint/ResponseHeader.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Test
    16  * @package    Zend_Test
    17  * @subpackage PHPUnit
    17  * @subpackage PHPUnit
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    20  * @version    $Id: ResponseHeader.php 20096 2010-01-06 02:05:09Z bkarwin $
    20  * @version    $Id: ResponseHeader.php 25205 2013-01-10 11:23:25Z frosch $
    21  */
    21  */
    22 
    22 
    23 /** @see PHPUnit_Framework_Constraint */
    23 /** @see PHPUnit_Framework_Constraint */
    24 require_once 'PHPUnit/Framework/Constraint.php';
    24 require_once 'PHPUnit/Framework/Constraint.php';
    25 
    25 
    28  *
    28  *
    29  * @uses       PHPUnit_Framework_Constraint
    29  * @uses       PHPUnit_Framework_Constraint
    30  * @category   Zend
    30  * @category   Zend
    31  * @package    Zend_Test
    31  * @package    Zend_Test
    32  * @subpackage PHPUnit
    32  * @subpackage PHPUnit
    33  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    33  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    34  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    34  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    35  */
    35  */
    36 class Zend_Test_PHPUnit_Constraint_ResponseHeader extends PHPUnit_Framework_Constraint
    36 class Zend_Test_PHPUnit_Constraint_ResponseHeader extends PHPUnit_Framework_Constraint
    37 {
    37 {
    38     /**#@+
    38     /**#@+
    63 
    63 
    64     /**
    64     /**
    65      * @var int Response code
    65      * @var int Response code
    66      */
    66      */
    67     protected $_code              = 200;
    67     protected $_code              = 200;
       
    68     
       
    69     /**
       
    70      * @var int Actual response code
       
    71      */
       
    72     protected $_actualCode        = null;
    68 
    73 
    69     /**
    74     /**
    70      * @var string Header
    75      * @var string Header
    71      */
    76      */
    72     protected $_header            = null;
    77     protected $_header            = null;
   195                 $failure = 'Failed asserting response code "%s"';
   200                 $failure = 'Failed asserting response code "%s"';
   196                 if ($this->_negate) {
   201                 if ($this->_negate) {
   197                     $failure = 'Failed asserting response code IS NOT "%s"';
   202                     $failure = 'Failed asserting response code IS NOT "%s"';
   198                 }
   203                 }
   199                 $failure = sprintf($failure, $this->_code);
   204                 $failure = sprintf($failure, $this->_code);
       
   205                 if (!$this->_negate && $this->_actualCode) {
       
   206                     $failure .= sprintf(PHP_EOL . 'Was "%s"', $this->_actualCode);
       
   207                 }
   200                 break;
   208                 break;
   201             case self::ASSERT_HEADER:
   209             case self::ASSERT_HEADER:
   202                 $failure = 'Failed asserting response header "%s" found';
   210                 $failure = 'Failed asserting response header "%s" found';
   203                 if ($this->_negate) {
   211                 if ($this->_negate) {
   204                     $failure = 'Failed asserting response response header "%s" WAS NOT found';
   212                     $failure = 'Failed asserting response response header "%s" WAS NOT found';
   248      * @return bool
   256      * @return bool
   249      */
   257      */
   250     protected function _code(Zend_Controller_Response_Abstract $response, $code)
   258     protected function _code(Zend_Controller_Response_Abstract $response, $code)
   251     {
   259     {
   252         $test = $this->_getCode($response);
   260         $test = $this->_getCode($response);
       
   261         $this->_actualCode = $test;
   253         return ($test == $code);
   262         return ($test == $code);
   254     }
   263     }
   255 
   264 
   256     /**
   265     /**
   257      * Compare response code for negative match
   266      * Compare response code for negative match
   336             return false;
   345             return false;
   337         }
   346         }
   338 
   347 
   339         $contents = str_replace($header . ': ', '', $fullHeader);
   348         $contents = str_replace($header . ': ', '', $fullHeader);
   340 
   349 
   341         return (strstr($contents, $match));
   350         return (strstr($contents, $match) !== false);
   342     }
   351     }
   343 
   352 
   344     /**
   353     /**
   345      * Negative check for header contents matching pattern
   354      * Negative check for header contents matching pattern
   346      *
   355      *
   355             return true;
   364             return true;
   356         }
   365         }
   357 
   366 
   358         $contents = str_replace($header . ': ', '', $fullHeader);
   367         $contents = str_replace($header . ': ', '', $fullHeader);
   359 
   368 
   360         return (!strstr($contents, $match));
   369         return (strstr($contents, $match) === false);
   361     }
   370     }
   362 
   371 
   363     /**
   372     /**
   364      * Positive check for header contents matching regex
   373      * Positive check for header contents matching regex
   365      *
   374      *