This repository has been archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
237 additions
and
8 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
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,86 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_Console | ||
*/ | ||
|
||
namespace ZendTest\Console; | ||
|
||
use Zend\Console\Console; | ||
use Zend\Console\Adapter; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_Console | ||
* @subpackage UnitTests | ||
* @group Zend_Console | ||
*/ | ||
class ConsoleTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function setUp() | ||
{ | ||
Console::overrideIsConsole(null); | ||
Console::resetInstance(); | ||
} | ||
|
||
public function testCanTestIsConsole() | ||
{ | ||
$this->assertTrue(Console::isConsole()); | ||
$className = Console::detectBestAdapter(); | ||
$adpater = new $className; | ||
$this->assertTrue($adpater instanceof Adapter\AdapterInterface); | ||
|
||
Console::overrideIsConsole(false); | ||
|
||
$this->assertFalse(Console::isConsole()); | ||
$this->assertEquals(null, Console::detectBestAdapter()); | ||
} | ||
|
||
public function testCanOverrideIsConsole() | ||
{ | ||
$this->assertEquals(true, Console::isConsole()); | ||
|
||
Console::overrideIsConsole(true); | ||
$this->assertEquals(true, Console::isConsole()); | ||
|
||
Console::overrideIsConsole(false); | ||
$this->assertEquals(false, Console::isConsole()); | ||
|
||
Console::overrideIsConsole(1); | ||
$this->assertEquals(true, Console::isConsole()); | ||
|
||
Console::overrideIsConsole('false'); | ||
$this->assertEquals(true, Console::isConsole()); | ||
} | ||
|
||
public function testCanGetInstance() | ||
{ | ||
$console = Console::getInstance(); | ||
$this->assertTrue($console instanceof Adapter\AdapterInterface); | ||
} | ||
|
||
public function testCanNotGetInstanceInNoConsoleMode() | ||
{ | ||
Console::overrideIsConsole(false); | ||
$this->setExpectedException('Zend\Console\Exception\RuntimeException'); | ||
Console::getInstance(); | ||
} | ||
|
||
public function testCanForceInstance() | ||
{ | ||
$console = Console::getInstance('Posix'); | ||
$this->assertTrue($console instanceof Adapter\AdapterInterface); | ||
$this->assertTrue($console instanceof Adapter\Posix); | ||
|
||
Console::overrideIsConsole(null); | ||
Console::resetInstance(); | ||
|
||
$console = Console::getInstance('Windows'); | ||
$this->assertTrue($console instanceof Adapter\AdapterInterface); | ||
$this->assertTrue($console instanceof Adapter\Windows); | ||
} | ||
} |
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,46 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_Console | ||
*/ | ||
|
||
namespace ZendTest\Console; | ||
|
||
use Zend\Console\Request; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_Console | ||
* @subpackage UnitTests | ||
* @group Zend_Console | ||
*/ | ||
class RequestTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function setUp() | ||
{ | ||
if (ini_get('register_argc_argv') == false) { | ||
$this->markTestSkipped("Cannot Test Zend\\Console\\Getopt without 'register_argc_argv' ini option true."); | ||
} | ||
} | ||
|
||
public function testCanConstructRequestAndGetParams() | ||
{ | ||
$_SERVER['argv'] = array('foo.php', 'foo' => 'baz', 'bar'); | ||
$_ENV["FOO_VAR"] = "bar"; | ||
|
||
$request = new Request(); | ||
$params = $request->getParams(); | ||
|
||
$this->assertEquals(2, count($params)); | ||
$this->assertEquals($params->toArray(), array('foo' => 'baz', 'bar')); | ||
$this->assertEquals($request->getParam('foo'), 'baz'); | ||
$this->assertEquals($request->getScriptName(), 'foo.php'); | ||
$this->assertEquals(1, count($request->env())); | ||
$this->assertEquals($request->env()->get('FOO_VAR'), 'bar'); | ||
$this->assertEquals($request->getEnv('FOO_VAR'), 'bar'); | ||
} | ||
} |
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,78 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_Console | ||
*/ | ||
|
||
namespace ZendTest\Console; | ||
|
||
use Zend\Console\Response; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_Console | ||
* @subpackage UnitTests | ||
* @group Zend_Console | ||
*/ | ||
class ResponseTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var Response | ||
*/ | ||
protected $response; | ||
|
||
public function setUp() | ||
{ | ||
$this->response = new Response(); | ||
} | ||
|
||
public function testInitialisation() | ||
{ | ||
$this->assertEquals(false, $this->response->contentSent()); | ||
$this->assertEquals(0, $this->response->getErrorLevel()); | ||
} | ||
|
||
public function testSetContent() | ||
{ | ||
$this->response->setContent('foo, bar'); | ||
$this->assertEquals(false, $this->response->contentSent()); | ||
ob_start(); | ||
$this->response->sendContent(); | ||
$content = ob_get_clean(); | ||
$this->assertEquals('foo, bar', $content); | ||
$this->assertEquals(true, $this->response->contentSent()); | ||
$this->assertEquals($this->response, $this->response->sendContent()); | ||
} | ||
|
||
/* | ||
public function testSetContentWithExit() | ||
{ | ||
if (!function_exists('set_exit_overload')) { | ||
$this->markTestSkipped("Install ext/test_helpers to test method with exit : https://github.com/sebastianbergmann/php-test-helpers."); | ||
} | ||
$self = $this; | ||
set_exit_overload( | ||
function($param = null) use ($self) { | ||
if ($param) { | ||
$self->assertEquals($param, 1); | ||
} | ||
return false; | ||
} | ||
); | ||
$this->response->setErrorLevel(1); | ||
$this->response->setContent('foo, bar'); | ||
ob_start(); | ||
$this->response->send(); | ||
$content = ob_get_clean(); | ||
$this->assertEquals('foo, bar', $content); | ||
unset_exit_overload(); | ||
} | ||
*/ | ||
} |