-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1312 from jim-parry/enhance/testing
Add headerEmited (or not) assertions to CIUnitTestCase
- Loading branch information
Showing
10 changed files
with
302 additions
and
73 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
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 |
---|---|---|
@@ -1,33 +1,32 @@ | ||
<?php | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| ERROR DISPLAY | ||
|-------------------------------------------------------------------------- | ||
| In development, we want to show as many errors as possible to help | ||
| make sure they don't make it to production. And save us hours of | ||
| painful debugging. | ||
*/ | ||
|-------------------------------------------------------------------------- | ||
| ERROR DISPLAY | ||
|-------------------------------------------------------------------------- | ||
| In development, we want to show as many errors as possible to help | ||
| make sure they don't make it to production. And save us hours of | ||
| painful debugging. | ||
*/ | ||
error_reporting(-1); | ||
ini_set('display_errors', 1); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| DEBUG BACKTRACES | ||
|-------------------------------------------------------------------------- | ||
| If true, this constant will tell the error screens to display debug | ||
| backtraces along with the other error information. If you would | ||
| prefer to not see this, set this value to false. | ||
*/ | ||
define('SHOW_DEBUG_BACKTRACE', true); | ||
|-------------------------------------------------------------------------- | ||
| DEBUG BACKTRACES | ||
|-------------------------------------------------------------------------- | ||
| If true, this constant will tell the error screens to display debug | ||
| backtraces along with the other error information. If you would | ||
| prefer to not see this, set this value to false. | ||
*/ | ||
defined('SHOW_DEBUG_BACKTRACE') || define('SHOW_DEBUG_BACKTRACE', true); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| DEBUG MODE | ||
|-------------------------------------------------------------------------- | ||
| Debug mode is an experimental flag that can allow changes throughout | ||
| the system. This will control whether Kint is loaded, and a few other | ||
| items. It can always be used within your own application too. | ||
*/ | ||
|-------------------------------------------------------------------------- | ||
| DEBUG MODE | ||
|-------------------------------------------------------------------------- | ||
| Debug mode is an experimental flag that can allow changes throughout | ||
| the system. This will control whether Kint is loaded, and a few other | ||
| items. It can always be used within your own application too. | ||
*/ | ||
|
||
define('CI_DEBUG', 1); | ||
defined('CI_DEBUG') || define('CI_DEBUG', 1); |
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 |
---|---|---|
@@ -1,22 +1,22 @@ | ||
<?php | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| ERROR DISPLAY | ||
|-------------------------------------------------------------------------- | ||
| Don't show ANY in production environments. Instead, let the system catch | ||
| it and display a generic error message. | ||
*/ | ||
|-------------------------------------------------------------------------- | ||
| ERROR DISPLAY | ||
|-------------------------------------------------------------------------- | ||
| Don't show ANY in production environments. Instead, let the system catch | ||
| it and display a generic error message. | ||
*/ | ||
ini_set('display_errors', 0); | ||
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| DEBUG MODE | ||
|-------------------------------------------------------------------------- | ||
| Debug mode is an experimental flag that can allow changes throughout | ||
| the system. It's not widely used currently, and may not survive | ||
| release of the framework. | ||
*/ | ||
|-------------------------------------------------------------------------- | ||
| DEBUG MODE | ||
|-------------------------------------------------------------------------- | ||
| Debug mode is an experimental flag that can allow changes throughout | ||
| the system. It's not widely used currently, and may not survive | ||
| release of the framework. | ||
*/ | ||
|
||
define('CI_DEBUG', 0); | ||
defined('CI_DEBUG') || define('CI_DEBUG', 0); |
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 |
---|---|---|
@@ -1,33 +1,33 @@ | ||
<?php | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| ERROR DISPLAY | ||
|-------------------------------------------------------------------------- | ||
| In development, we want to show as many errors as possible to help | ||
| make sure they don't make it to production. And save us hours of | ||
| painful debugging. | ||
*/ | ||
|-------------------------------------------------------------------------- | ||
| ERROR DISPLAY | ||
|-------------------------------------------------------------------------- | ||
| In development, we want to show as many errors as possible to help | ||
| make sure they don't make it to production. And save us hours of | ||
| painful debugging. | ||
*/ | ||
error_reporting(-1); | ||
ini_set('display_errors', 1); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| DEBUG BACKTRACES | ||
|-------------------------------------------------------------------------- | ||
| If true, this constant will tell the error screens to display debug | ||
| backtraces along with the other error information. If you would | ||
| prefer to not see this, set this value to false. | ||
*/ | ||
define('SHOW_DEBUG_BACKTRACE', true); | ||
|-------------------------------------------------------------------------- | ||
| DEBUG BACKTRACES | ||
|-------------------------------------------------------------------------- | ||
| If true, this constant will tell the error screens to display debug | ||
| backtraces along with the other error information. If you would | ||
| prefer to not see this, set this value to false. | ||
*/ | ||
defined('SHOW_DEBUG_BACKTRACE') || define('SHOW_DEBUG_BACKTRACE', true); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| DEBUG MODE | ||
|-------------------------------------------------------------------------- | ||
| Debug mode is an experimental flag that can allow changes throughout | ||
| the system. It's not widely used currently, and may not survive | ||
| release of the framework. | ||
*/ | ||
|-------------------------------------------------------------------------- | ||
| DEBUG MODE | ||
|-------------------------------------------------------------------------- | ||
| Debug mode is an experimental flag that can allow changes throughout | ||
| the system. It's not widely used currently, and may not survive | ||
| release of the framework. | ||
*/ | ||
|
||
define('CI_DEBUG', 1); | ||
defined('CI_DEBUG') || define('CI_DEBUG', 1); |
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
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,99 @@ | ||
<?php | ||
namespace CodeIgniter\Test; | ||
|
||
use CodeIgniter\HTTP\Response; | ||
use CodeIgniter\HTTP\Exceptions\HTTPException; | ||
use Config\App; | ||
|
||
/** | ||
* This test suite has been created separately from | ||
* TestCaseTest because it messes with output | ||
* buffering from PHPUnit, and the individual | ||
* test cases need to be run as separate processes. | ||
*/ | ||
class TestCaseEmissionsTest extends \CIUnitTestCase | ||
{ | ||
|
||
//-------------------------------------------------------------------- | ||
/** | ||
* This needs to be run as a separate process, since phpunit | ||
* has already captured the "normal" output, and we will get | ||
* a "Cannot modify headers" message if we try to change | ||
* headers or cookies now. | ||
* | ||
* Furthermore, this test needs to flush the output buffering | ||
* that might be in progress, and start our own output buffer | ||
* capture. | ||
* | ||
* This test includes a basic sanity check, to make sure that | ||
* the body we thought would be sent actually was. | ||
* | ||
* @runInSeparateProcess | ||
* @preserveGlobalState disabled | ||
*/ | ||
public function testHeadersEmitted() | ||
{ | ||
|
||
$response = new Response(new App()); | ||
$response->pretend(FALSE); | ||
|
||
$body = 'Hello'; | ||
$response->setBody($body); | ||
|
||
$response->setCookie('foo', 'bar'); | ||
$this->assertTrue($response->hasCookie('foo')); | ||
$this->assertTrue($response->hasCookie('foo', 'bar')); | ||
|
||
// send it | ||
ob_start(); | ||
$response->send(); | ||
|
||
$buffer = ob_clean(); | ||
if (ob_get_level() > 0) | ||
ob_end_clean(); | ||
|
||
// and what actually got sent?; test both ways | ||
$this->assertHeaderEmitted("Set-Cookie: foo=bar;"); | ||
$this->assertHeaderEmitted("set-cookie: FOO=bar", true); | ||
} | ||
|
||
/** | ||
* This needs to be run as a separate process, since phpunit | ||
* has already captured the "normal" output, and we will get | ||
* a "Cannot modify headers" message if we try to change | ||
* headers or cookies now. | ||
* | ||
* Furthermore, this test needs to flush the output buffering | ||
* that might be in progress, and start our own output buffer | ||
* capture. | ||
* | ||
* This test includes a basic sanity check, to make sure that | ||
* the body we thought would be sent actually was. | ||
* | ||
* @runInSeparateProcess | ||
* @preserveGlobalState disabled | ||
*/ | ||
public function testHeadersNotEmitted() | ||
{ | ||
$response = new Response(new App()); | ||
$response->pretend(FALSE); | ||
|
||
$body = 'Hello'; | ||
$response->setBody($body); | ||
|
||
// what do we think we're about to send? | ||
$response->setCookie('foo', 'bar'); | ||
$this->assertTrue($response->hasCookie('foo')); | ||
$this->assertTrue($response->hasCookie('foo', 'bar')); | ||
|
||
// send it | ||
ob_start(); | ||
$response->send(); | ||
$output = ob_clean(); // what really was sent | ||
if (ob_get_level() > 0) | ||
ob_end_clean(); | ||
|
||
$this->assertHeaderNotEmitted("Set-Cookie: pop=corn", true); | ||
} | ||
|
||
} |
Oops, something went wrong.