Skip to content

Commit

Permalink
Merge pull request #10351 from cakephp/fix-tests-locally
Browse files Browse the repository at this point in the history
Fix tests failing due to environment pollution.
  • Loading branch information
lorenzo committed Mar 5, 2017
2 parents 33e22ce + 1563b6f commit 4957e10
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 15 deletions.
2 changes: 1 addition & 1 deletion tests/TestCase/Controller/Component/AuthComponentTest.php
Expand Up @@ -1191,7 +1191,7 @@ public function testStatelessAuthWorksWithUser()

$result = $this->Auth->user('username');
$this->assertEquals('mariano', $result);
$this->assertFalse(isset($_SESSION));
$this->assertFalse(isset($_SESSION['Auth']), 'No user data in session');
}

/**
Expand Down
Expand Up @@ -44,6 +44,13 @@ class RequestHandlerComponentTest extends TestCase
*/
public $RequestHandler;

/**
* Backup of $_SERVER
*
* @var array
*/
protected $server = [];

/**
* setUp method
*
Expand All @@ -52,6 +59,7 @@ class RequestHandlerComponentTest extends TestCase
public function setUp()
{
parent::setUp();
$this->server = $_SERVER;
Configure::write('App.namespace', 'TestApp');
DispatcherFactory::add('Routing');
DispatcherFactory::add('ControllerFactory');
Expand Down Expand Up @@ -90,6 +98,7 @@ public function tearDown()
DispatcherFactory::clear();
Router::reload();
Router::$initialized = false;
$_SERVER = $this->server;
unset($this->RequestHandler, $this->Controller);
}

Expand Down
8 changes: 8 additions & 0 deletions tests/TestCase/Controller/Component/SecurityComponentTest.php
Expand Up @@ -125,6 +125,12 @@ public function header($status)
*/
class SecurityComponentTest extends TestCase
{
/**
* SERVER variable backup.
*
* @var array
*/
protected $server = [];

/**
* Controller property
Expand All @@ -151,6 +157,7 @@ public function setUp()
{
parent::setUp();

$this->server = $_SERVER;
$session = new Session();
$request = $this->getMockBuilder('Cake\Network\Request')
->setMethods(['here'])
Expand Down Expand Up @@ -180,6 +187,7 @@ public function setUp()
public function tearDown()
{
parent::tearDown();
$_SERVER = $this->server;
$this->Security->session->delete('_Token');
unset($this->Controller->Security);
unset($this->Controller->Component);
Expand Down
24 changes: 10 additions & 14 deletions tests/TestCase/Http/ServerRequestTest.php
Expand Up @@ -24,10 +24,16 @@
use Zend\Diactoros\Uri;

/**
* TestRequest
* ServerRequest Test
*/
class ServerRequestTest extends TestCase
{
/**
* SERVER variable backup.
*
* @var array
*/
protected $server = [];

/**
* Setup callback
Expand All @@ -37,26 +43,16 @@ class ServerRequestTest extends TestCase
public function setUp()
{
parent::setUp();
$this->_case = null;
if (isset($_GET['case'])) {
$this->_case = $_GET['case'];
unset($_GET['case']);
}
$this->server = $_SERVER;

Configure::write('App.baseUrl', false);
}

/**
* TearDown
*
* @return void
*/
public function tearDown()
{
parent::tearDown();
if (!empty($this->_case)) {
$_GET['case'] = $this->_case;
}

$_SERVER = $this->server;
}

/**
Expand Down
29 changes: 29 additions & 0 deletions tests/TestCase/Network/ResponseTest.php
Expand Up @@ -27,6 +27,35 @@
*/
class ResponseTest extends TestCase
{
/**
* SERVER variable backup.
*
* @var array
*/
protected $server = [];

/**
* setup
*
* @return void
*/
public function setUp()
{
parent::setUp();
$this->server = $_SERVER;
}

/**
* teardown
*
* @return void
*/
public function tearDown()
{
parent::tearDown();
$_SERVER = $this->server;
}

/**
* Tests the request object constructor
*
Expand Down

0 comments on commit 4957e10

Please sign in to comment.