Skip to content

Commit

Permalink
Extend mocked functions so that we can modify headers_sent()
Browse files Browse the repository at this point in the history
Allow headers_sent() to be customized. By default we want to pretend
headers have been sent, as changing session configuration at runtime
emits errors in PHP7.2. However there are specific tests that we need to
pretend that headers have not been set.
  • Loading branch information
markstory committed Nov 29, 2017
1 parent 9016d7f commit e2dfdd2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
17 changes: 17 additions & 0 deletions tests/TestCase/Http/ResponseEmitterTest.php
Expand Up @@ -28,13 +28,30 @@ class ResponseEmitterTest extends TestCase
{
protected $emitter;

/**
* setup
*
* @return void
*/
public function setUp()
{
parent::setUp();
$GLOBALS['mockedHeadersSent'] = false;
$GLOBALS['mockedHeaders'] = $GLOBALS['mockedCookies'] = [];
$this->emitter = new ResponseEmitter();
}

/**
* teardown
*
* @return void
*/
public function tearDown()
{
parent::tearDown();
unset($GLOBALS['mockedHeadersSent']);
}

/**
* Test emitting simple responses.
*
Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase/Http/ResponseTest.php
Expand Up @@ -46,6 +46,7 @@ public function setUp()
{
parent::setUp();
$this->server = $_SERVER;
$GLOBALS['mockedHeadersSent'] = false;
}

/**
Expand All @@ -57,6 +58,7 @@ public function tearDown()
{
parent::tearDown();
$_SERVER = $this->server;
unset($GLOBALS['mockedHeadersSent']);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase/Http/ServerTest.php
Expand Up @@ -42,6 +42,7 @@ public function setUp()
$this->server = $_SERVER;
$this->config = dirname(dirname(__DIR__));
$GLOBALS['mockedHeaders'] = [];
$GLOBALS['mockedHeadersSent'] = false;
}

/**
Expand All @@ -53,6 +54,7 @@ public function tearDown()
{
parent::tearDown();
$_SERVER = $this->server;
unset($GLOBALS['mockedHeadersSent']);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Http/server_mocks.php
Expand Up @@ -6,7 +6,7 @@

function headers_sent()
{
return false;
return isset($GLOBALS['mockedHeadersSent']) ? $GLOBALS['mockedHeadersSent'] : true;
}

function header($header)
Expand Down

0 comments on commit e2dfdd2

Please sign in to comment.