Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/66'
Browse files Browse the repository at this point in the history
Close #66
Fixes #61
  • Loading branch information
Xerkus committed Apr 10, 2018
2 parents 4509519 + f1e7a35 commit ba4059c
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -22,7 +22,8 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#66](https://github.com/zendframework/zend-test/pull/66) Fixes globals not
cleared for controller tests

## 3.2.0 - 2018-04-07

Expand Down
8 changes: 8 additions & 0 deletions src/PHPUnit/Controller/AbstractConsoleControllerTestCase.php
Expand Up @@ -19,6 +19,14 @@ abstract class AbstractConsoleControllerTestCase extends AbstractControllerTestC
*/
protected $useConsoleRequest = true;

protected function setUp()
{
parent::setUp();

$_SERVER['args'] = 0;
$_SERVER['argv'] = [];
}

/**
* Assert console output contain content (insensible case)
*
Expand Down
31 changes: 31 additions & 0 deletions src/PHPUnit/Controller/AbstractControllerTestCase.php
Expand Up @@ -50,11 +50,34 @@ abstract class AbstractControllerTestCase extends TestCase
*/
protected $traceError = true;

/**
* Original environemnt
*
* @var array
*/
protected $originalEnvironment;

/**
* Reset the application for isolation
*/
protected function setUp()
{
$this->originalEnvironment = [
'post' => $_POST,
'get' => $_GET,
'cookie' => $_COOKIE,
'server' => $_SERVER,
'env' => $_ENV,
'files' => $_FILES,
];

$_POST = [];
$_GET = [];
$_COOKIE = [];
$_SERVER = [];
$_ENV = [];
$_FILES = [];

$this->usedConsoleBackup = Console::isConsole();
$this->reset();
}
Expand All @@ -65,6 +88,14 @@ protected function setUp()
protected function tearDown()
{
Console::overrideIsConsole($this->usedConsoleBackup);

// Restore the original environment
$_POST = $this->originalEnvironment['post'];
$_GET = $this->originalEnvironment['get'];
$_COOKIE = $this->originalEnvironment['cookie'];
$_SERVER = $this->originalEnvironment['server'];
$_ENV = $this->originalEnvironment['env'];
$_FILES = $this->originalEnvironment['files'];
}

/**
Expand Down
21 changes: 21 additions & 0 deletions test/PHPUnit/Controller/AbstractControllerTestCaseTest.php
Expand Up @@ -8,6 +8,7 @@
*/
namespace ZendTest\Test\PHPUnit\Controller;

use Generator;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamWrapper;
use PHPUnit\Framework\ExpectationFailedException;
Expand Down Expand Up @@ -514,4 +515,24 @@ public function testQueryParamsDelete()
$this->dispatch('/tests', 'DELETE', ['foo' => 'bar']);
$this->assertEquals('foo=bar', $this->getRequest()->getQuery()->toString());
}

/**
* @return Generator
*/
public function routeParam()
{
yield 'phpunit' => ['phpunit'];
yield 'param' => ['param'];
}

/**
* @dataProvider routeParam
*
* @param string $param
*/
public function testRequestWithRouteParam($param)
{
$this->dispatch(sprintf('/with-param/%s', $param));
$this->assertResponseStatusCode(200);
}
}
10 changes: 10 additions & 0 deletions test/_files/Baz/config/module.config.php
Expand Up @@ -121,6 +121,16 @@
],
],
],
'parametrized' => [
'type' => 'segment',
'options' => [
'route' => '/with-param/:param',
'defaults' => [
'controller' => 'baz_index',
'action' => 'unittests',
],
],
],
],
],
'controllers' => [
Expand Down

0 comments on commit ba4059c

Please sign in to comment.