Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gave body assertions proper constraints
- Loading branch information
1 parent
0738fe0
commit e2f581b
Showing
10 changed files
with
415 additions
and
26 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,69 @@ | ||
<?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 Cake\Http\Response; | ||
|
||
/** | ||
* BodyContains | ||
* | ||
* @internal | ||
*/ | ||
class BodyContains extends ResponseBase | ||
{ | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
protected $ignoreCase; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param Response $response Response | ||
* @param bool $ignoreCase Ignore case | ||
*/ | ||
public function __construct(Response $response, $ignoreCase = false) | ||
{ | ||
parent::__construct($response); | ||
|
||
$this->ignoreCase = $ignoreCase; | ||
} | ||
|
||
/** | ||
* Checks assertion | ||
* | ||
* @param mixed $other Expected type | ||
* @return bool | ||
*/ | ||
public function matches($other) | ||
{ | ||
$method = 'mb_strpos'; | ||
if ($this->ignoreCase) { | ||
$method = 'mb_stripos'; | ||
} | ||
|
||
return $method($this->_getBodyAsString(), $other) !== false; | ||
} | ||
|
||
/** | ||
* Assertion message | ||
* | ||
* @return string | ||
*/ | ||
public function toString() | ||
{ | ||
return 'is in response body'; | ||
} | ||
} |
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,55 @@ | ||
<?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; | ||
|
||
/** | ||
* BodyEmpty | ||
* | ||
* @internal | ||
*/ | ||
class BodyEmpty extends ResponseBase | ||
{ | ||
|
||
/** | ||
* Checks assertion | ||
* | ||
* @param mixed $other Expected type | ||
* @return bool | ||
*/ | ||
public function matches($other) | ||
{ | ||
return empty($this->_getBodyAsString()); | ||
} | ||
|
||
/** | ||
* Assertion message | ||
* | ||
* @return string | ||
*/ | ||
public function toString() | ||
{ | ||
return 'response body is empty'; | ||
} | ||
|
||
/** | ||
* Overwrites the descriptions so we can remove the automatic "expected" message | ||
* | ||
* @param mixed $other Value | ||
* @return string | ||
*/ | ||
protected function failureDescription($other) | ||
{ | ||
return $this->toString(); | ||
} | ||
} |
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,44 @@ | ||
<?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; | ||
|
||
/** | ||
* BodyEquals | ||
* | ||
* @internal | ||
*/ | ||
class BodyEquals extends ResponseBase | ||
{ | ||
|
||
/** | ||
* Checks assertion | ||
* | ||
* @param mixed $other Expected type | ||
* @return bool | ||
*/ | ||
public function matches($other) | ||
{ | ||
return $this->_getBodyAsString() === $other; | ||
} | ||
|
||
/** | ||
* Assertion message | ||
* | ||
* @return string | ||
*/ | ||
public function toString() | ||
{ | ||
return 'matches response body'; | ||
} | ||
} |
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,44 @@ | ||
<?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; | ||
|
||
/** | ||
* BodyContains | ||
* | ||
* @internal | ||
*/ | ||
class BodyNotContains extends BodyContains | ||
{ | ||
|
||
/** | ||
* Checks assertion | ||
* | ||
* @param mixed $other Expected type | ||
* @return bool | ||
*/ | ||
public function matches($other) | ||
{ | ||
return parent::matches($other) === false; | ||
} | ||
|
||
/** | ||
* Assertion message | ||
* | ||
* @return string | ||
*/ | ||
public function toString() | ||
{ | ||
return 'is not in response body'; | ||
} | ||
} |
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,44 @@ | ||
<?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; | ||
|
||
/** | ||
* BodyNotEmpty | ||
* | ||
* @internal | ||
*/ | ||
class BodyNotEmpty extends BodyEmpty | ||
{ | ||
|
||
/** | ||
* Checks assertion | ||
* | ||
* @param mixed $other Expected type | ||
* @return bool | ||
*/ | ||
public function matches($other) | ||
{ | ||
return parent::matches($other) === false; | ||
} | ||
|
||
/** | ||
* Assertion message | ||
* | ||
* @return string | ||
*/ | ||
public function toString() | ||
{ | ||
return 'response body is not empty'; | ||
} | ||
} |
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,44 @@ | ||
<?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; | ||
|
||
/** | ||
* BodyNotEquals | ||
* | ||
* @internal | ||
*/ | ||
class BodyNotEquals extends BodyEquals | ||
{ | ||
|
||
/** | ||
* Checks assertion | ||
* | ||
* @param mixed $other Expected type | ||
* @return bool | ||
*/ | ||
public function matches($other) | ||
{ | ||
return parent::matches($other) === false; | ||
} | ||
|
||
/** | ||
* Assertion message | ||
* | ||
* @return string | ||
*/ | ||
public function toString() | ||
{ | ||
return 'does not match response body'; | ||
} | ||
} |
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,44 @@ | ||
<?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; | ||
|
||
/** | ||
* BodyNotRegExp | ||
* | ||
* @internal | ||
*/ | ||
class BodyNotRegExp extends ResponseBase | ||
{ | ||
|
||
/** | ||
* Checks assertion | ||
* | ||
* @param mixed $other Expected pattern | ||
* @return bool | ||
*/ | ||
public function matches($other) | ||
{ | ||
return parent::matches($other) === false; | ||
} | ||
|
||
/** | ||
* Assertion message | ||
* | ||
* @return string | ||
*/ | ||
public function toString() | ||
{ | ||
return 'PCRE pattern not found in response body'; | ||
} | ||
} |
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,44 @@ | ||
<?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; | ||
|
||
/** | ||
* BodyRegExp | ||
* | ||
* @internal | ||
*/ | ||
class BodyRegExp extends ResponseBase | ||
{ | ||
|
||
/** | ||
* Checks assertion | ||
* | ||
* @param mixed $other Expected pattern | ||
* @return bool | ||
*/ | ||
public function matches($other) | ||
{ | ||
return preg_match($other, $this->_getBodyAsString()) > 0; | ||
} | ||
|
||
/** | ||
* Assertion message | ||
* | ||
* @return string | ||
*/ | ||
public function toString() | ||
{ | ||
return 'PCRE pattern found in response body'; | ||
} | ||
} |
Oops, something went wrong.