Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added constraints for header, content type
- Loading branch information
1 parent
028800a
commit e1bde25
Showing
5 changed files
with
171 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/** | ||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice | ||
* | ||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* @since 3.7.0 | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace Cake\TestSuite\Constraint\Response; | ||
|
||
/** | ||
* ContentType | ||
*/ | ||
class ContentType extends ResponseBase | ||
{ | ||
|
||
/** | ||
* Checks assertion | ||
* | ||
* @param mixed $other Expected type | ||
* @return bool | ||
*/ | ||
public function matches($other) | ||
{ | ||
$alias = $this->response->getMimeType($other); | ||
if ($alias !== false) { | ||
$other = $alias; | ||
} | ||
|
||
return $other === $this->response->getType(); | ||
} | ||
|
||
/** | ||
* Assertion message | ||
* | ||
* @return string | ||
*/ | ||
public function toString() | ||
{ | ||
return 'was set as the Content-Type'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
/** | ||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice | ||
* | ||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* @since 3.7.0 | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace Cake\TestSuite\Constraint\Response; | ||
|
||
use PHPUnit\Framework\AssertionFailedError; | ||
|
||
/** | ||
* Header | ||
*/ | ||
class Header extends ResponseBase | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $headerName; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param \Cake\Http\Response $response Response | ||
* @param string $headerName Header name | ||
*/ | ||
public function __construct(\Cake\Http\Response $response, $headerName) | ||
{ | ||
parent::__construct($response); | ||
|
||
$this->headerName = $headerName; | ||
} | ||
|
||
/** | ||
* Checks assertion | ||
* | ||
* @param mixed $other Expected content | ||
* @return bool | ||
*/ | ||
public function matches($other) | ||
{ | ||
if (!$this->response->hasHeader($this->headerName)) { | ||
throw new AssertionFailedError(sprintf('Header `%s` was not set.', $this->headerName)); | ||
} | ||
|
||
return $this->response->getHeaderLine($this->headerName) === $other; | ||
} | ||
|
||
/** | ||
* Assertion message | ||
* | ||
* @return string | ||
*/ | ||
public function toString() | ||
{ | ||
return sprintf('has header `%s`', $this->headerName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice | ||
* | ||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* @since 3.7.0 | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace Cake\TestSuite\Constraint\Response; | ||
|
||
use PHPUnit\Framework\AssertionFailedError; | ||
|
||
/** | ||
* HeaderContains | ||
*/ | ||
class HeaderContains extends Header | ||
{ | ||
|
||
/** | ||
* Checks assertion | ||
* | ||
* @param mixed $other Expected content | ||
* @return bool | ||
*/ | ||
public function matches($other) | ||
{ | ||
if (!$this->response->hasHeader($this->headerName)) { | ||
throw new AssertionFailedError(sprintf('Header `%s` was not set.', $this->headerName)); | ||
} | ||
|
||
return mb_strpos($this->response->getHeaderLine($this->headerName), $other) !== false; | ||
} | ||
|
||
/** | ||
* Assertion message | ||
* | ||
* @return string | ||
*/ | ||
public function toString() | ||
{ | ||
return sprintf('is in header `%s`', $this->headerName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters