From dd26a7d52b288099afbdf6ffe982d52f8d327f59 Mon Sep 17 00:00:00 2001 From: blanchonvincent Date: Sun, 24 Feb 2013 22:58:30 +0100 Subject: [PATCH 01/24] Add unit tests on Consoler AbstractAdapter --- test/Adapater/AbstractAdapterTest.php | 115 ++++++++++++++++++++++++++ test/TestAssets/ConsoleAdapter.php | 52 ++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 test/Adapater/AbstractAdapterTest.php create mode 100644 test/TestAssets/ConsoleAdapter.php diff --git a/test/Adapater/AbstractAdapterTest.php b/test/Adapater/AbstractAdapterTest.php new file mode 100644 index 0000000..3b684f7 --- /dev/null +++ b/test/Adapater/AbstractAdapterTest.php @@ -0,0 +1,115 @@ +adapter = new ConsoleAdapter(); + $this->adapter->stream = fopen('php://memory', 'w+'); + } + + public function tearDown() + { + fclose($this->adapter->stream); + } + + public function testWriteChar() + { + ob_start(); + $this->adapter->write('foo'); + $this->assertEquals('foo', ob_get_clean()); + } + + public function testWriteText() + { + ob_start(); + $this->adapter->writeText('foo'); + $this->assertEquals('foo', ob_get_clean()); + } + + public function testWriteLine() + { + ob_start(); + $this->adapter->writeLine('foo'); + $this->assertEquals("foo\n", ob_get_clean()); + + ob_start(); + $this->adapter->writeLine("foo\nbar"); + $this->assertEquals("foo\nbar\n", ob_get_clean()); + + ob_start(); + $this->adapter->writeLine("\rfoo\r"); + $this->assertEquals("foo\n", ob_get_clean()); + } + + public function testReadLine() + { + fwrite($this->adapter->stream, 'baz'); + + $line = $this->adapter->readLine(); + $this->assertEquals($line, 'baz'); + } + + public function testReadLineWithLimit() + { + fwrite($this->adapter->stream, 'baz, bar, foo'); + + $line = $this->adapter->readLine(6); + $this->assertEquals($line, 'baz, b'); + } + + public function testReadChar() + { + fwrite($this->adapter->stream, 'bar'); + + $char = $this->adapter->readChar(); + $this->assertEquals($char, 'b'); + } + + public function testReadCharWithMask() + { + fwrite($this->adapter->stream, 'bar'); + + $char = $this->adapter->readChar('ar'); + $this->assertEquals($char, 'a'); + } + + public function testReadCharWithMaskInsensitiveCase() + { + fwrite($this->adapter->stream, 'bAr'); + + $char = $this->adapter->readChar('ar'); + $this->assertEquals($char, 'A'); + } + + public function testReadCharWithNoReturn() + { + fwrite($this->adapter->stream, 'bar'); + + $char = $this->adapter->readChar('foo'); + $this->assertEquals($char, ''); + } +} diff --git a/test/TestAssets/ConsoleAdapter.php b/test/TestAssets/ConsoleAdapter.php new file mode 100644 index 0000000..479abe5 --- /dev/null +++ b/test/TestAssets/ConsoleAdapter.php @@ -0,0 +1,52 @@ +stream); + $line = stream_get_line($this->stream, $maxLength, PHP_EOL); + return rtrim($line,"\n\r"); + } + + /** + * Read a single character from the console input + * + * @param string|null $mask A list of allowed chars + * @return string + */ + public function readChar($mask = null) + { + rewind($this->stream); + do { + $char = fread($this->stream, 1); + } while ($mask !== null && "" !== $char && false === stristr($mask, $char)); + return $char; + } +} From 4f98cf29c10281ff7e1ad3067d210311d274be8e Mon Sep 17 00:00:00 2001 From: blanchonvincent Date: Sun, 24 Feb 2013 22:59:16 +0100 Subject: [PATCH 02/24] Fix loop with empty mask --- src/Adapter/AbstractAdapter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index ea1ddb8..4a406f9 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -601,7 +601,7 @@ public function readChar($mask = null) $f = fopen('php://stdin','r'); do { $char = fread($f,1); - } while ($mask === null || stristr($mask, $char)); + } while ($mask !== null && "" !== $char && false === stristr($mask, $char)); fclose($f); return $char; } From 4a716a0d6a42dfca7d595b46e5816c51d482cea6 Mon Sep 17 00:00:00 2001 From: blanchonvincent Date: Mon, 25 Feb 2013 08:50:24 +0100 Subject: [PATCH 03/24] Add tests to cover prompt/char --- test/Prompt/CharTest.php | 80 ++++++++++++++++++++++++++++++ test/TestAssets/ConsoleAdapter.php | 52 +++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 test/Prompt/CharTest.php create mode 100644 test/TestAssets/ConsoleAdapter.php diff --git a/test/Prompt/CharTest.php b/test/Prompt/CharTest.php new file mode 100644 index 0000000..25a6a0a --- /dev/null +++ b/test/Prompt/CharTest.php @@ -0,0 +1,80 @@ +adapter = new ConsoleAdapter(); + $this->adapter->stream = fopen('php://memory', 'w+'); + } + + public function tearDown() + { + fclose($this->adapter->stream); + } + + public function testCanPromptChar() + { + fwrite($this->adapter->stream, 'a'); + + $char = new Char(); + $char->setEcho(false); + $char->setConsole($this->adapter); + ob_start(); + $response = $char->show(); + $text = ob_get_clean(); + $this->assertEquals($text, "Please hit a key\n"); + $this->assertEquals('a', $response); + } + + public function testCanPromptCharWithCharNotInDefaultMask() + { + fwrite($this->adapter->stream, 'zywa'); + + $char = new Char(); + $char->setEcho(false); + $char->setConsole($this->adapter); + ob_start(); + $response = $char->show(); + $text = ob_get_clean(); + $this->assertEquals('z', $response); + } + + public function testCanPromptCharWithNewQuestionAndMask() + { + fwrite($this->adapter->stream, 'foo123'); + + $char = new Char("Give a number", '0123456789'); + $char->setEcho(false); + $char->setConsole($this->adapter); + ob_start(); + $response = $char->show(); + $text = ob_get_clean(); + $this->assertEquals($text, "Give a number\n"); + $this->assertEquals('1', $response); + } +} diff --git a/test/TestAssets/ConsoleAdapter.php b/test/TestAssets/ConsoleAdapter.php new file mode 100644 index 0000000..479abe5 --- /dev/null +++ b/test/TestAssets/ConsoleAdapter.php @@ -0,0 +1,52 @@ +stream); + $line = stream_get_line($this->stream, $maxLength, PHP_EOL); + return rtrim($line,"\n\r"); + } + + /** + * Read a single character from the console input + * + * @param string|null $mask A list of allowed chars + * @return string + */ + public function readChar($mask = null) + { + rewind($this->stream); + do { + $char = fread($this->stream, 1); + } while ($mask !== null && "" !== $char && false === stristr($mask, $char)); + return $char; + } +} From 766032fe2718c31cb82d7091c505648ccbe47f67 Mon Sep 17 00:00:00 2001 From: blanchonvincent Date: Mon, 25 Feb 2013 08:57:40 +0100 Subject: [PATCH 04/24] Add tests to cover prompt/line --- test/Prompt/CharTest.php | 2 +- test/Prompt/LineTest.php | 76 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 test/Prompt/LineTest.php diff --git a/test/Prompt/CharTest.php b/test/Prompt/CharTest.php index 25a6a0a..611e113 100644 --- a/test/Prompt/CharTest.php +++ b/test/Prompt/CharTest.php @@ -19,7 +19,7 @@ * @subpackage UnitTests * @group Zend_Console */ -class GetoptTest extends \PHPUnit_Framework_TestCase +class CharTest extends \PHPUnit_Framework_TestCase { /** * @var ConsoleAdapter diff --git a/test/Prompt/LineTest.php b/test/Prompt/LineTest.php new file mode 100644 index 0000000..62f0b2b --- /dev/null +++ b/test/Prompt/LineTest.php @@ -0,0 +1,76 @@ +adapter = new ConsoleAdapter(); + $this->adapter->stream = fopen('php://memory', 'w+'); + } + + public function tearDown() + { + fclose($this->adapter->stream); + } + + public function testCanReadLine() + { + fwrite($this->adapter->stream, 'Bryan is in the kitchen'); + + $line = new Line('Where is Bryan ?'); + $line->setConsole($this->adapter); + ob_start(); + $response = $line->show(); + $text = ob_get_clean(); + $this->assertEquals($text, "Where is Bryan ?"); + $this->assertEquals('Bryan is in the kitchen', $response); + } + + public function testCanReadLineWithMax() + { + fwrite($this->adapter->stream, 'Kitchen no ?'); + + $line = new Line('Where is Bryan ?', false, 7); + $line->setConsole($this->adapter); + ob_start(); + $response = $line->show(); + $text = ob_get_clean(); + $this->assertEquals($text, "Where is Bryan ?"); + $this->assertEquals('Kitchen', $response); + } + + public function testCanReadLineWithEmptyAnswer() + { + $line = new Line('Where is Bryan ?', true); + $line->setConsole($this->adapter); + ob_start(); + $response = $line->show(); + $text = ob_get_clean(); + $this->assertEquals($text, "Where is Bryan ?"); + $this->assertEquals('', $response); + } +} From 0244ee98cf0c93db1c6829fa0e1ff8f0244e4bdc Mon Sep 17 00:00:00 2001 From: blanchonvincent Date: Mon, 25 Feb 2013 09:21:20 +0100 Subject: [PATCH 05/24] Add tests to cover prompt/number --- test/Prompt/NumberTest.php | 119 +++++++++++++++++++++++++++++ test/TestAssets/ConsoleAdapter.php | 9 ++- 2 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 test/Prompt/NumberTest.php diff --git a/test/Prompt/NumberTest.php b/test/Prompt/NumberTest.php new file mode 100644 index 0000000..97c7f93 --- /dev/null +++ b/test/Prompt/NumberTest.php @@ -0,0 +1,119 @@ +adapter = new ConsoleAdapter(); + $this->adapter->stream = fopen('php://memory', 'w+'); + } + + public function tearDown() + { + fclose($this->adapter->stream); + } + + public function testCanReadNumber() + { + fwrite($this->adapter->stream, "123"); + + $number = new Number(); + $number->setConsole($this->adapter); + ob_start(); + $response = $number->show(); + $text = ob_get_clean(); + $this->assertEquals($text, "Please enter a number: "); + $this->assertEquals('123', $response); + } + + public function testCanReadNumberOnMultilign() + { + fwrite($this->adapter->stream, "a\n"); + fwrite($this->adapter->stream, "123\n"); + rewind($this->adapter->stream); + $this->adapter->autoRewind = false; + + $number = new Number(); + $number->setConsole($this->adapter); + ob_start(); + $response = $number->show(); + $text = ob_get_clean(); + $this->assertTrue((bool) preg_match('#a is not a number#', $text)); + $this->assertEquals('123', $response); + } + + public function testCanNotReadFloatByDefault() + { + fwrite($this->adapter->stream, "1.23\n"); + fwrite($this->adapter->stream, "123\n"); + rewind($this->adapter->stream); + $this->adapter->autoRewind = false; + + $number = new Number(); + $number->setConsole($this->adapter); + ob_start(); + $response = $number->show(); + $text = ob_get_clean(); + $this->assertTrue((bool) preg_match('#Please enter a non-floating number#', $text)); + $this->assertEquals('123', $response); + } + + public function testCanForceToReadFloat() + { + fwrite($this->adapter->stream, "1.23\n"); + fwrite($this->adapter->stream, "123\n"); + rewind($this->adapter->stream); + $this->adapter->autoRewind = false; + + $number = new Number('Give me a number', false, true); + $number->setConsole($this->adapter); + ob_start(); + $response = $number->show(); + $text = ob_get_clean(); + $this->assertEquals($text, 'Give me a number'); + $this->assertEquals('1.23', $response); + } + + public function testCanDefineAMax() + { + fwrite($this->adapter->stream, "1\n"); + fwrite($this->adapter->stream, "11\n"); + fwrite($this->adapter->stream, "6\n"); + rewind($this->adapter->stream); + $this->adapter->autoRewind = false; + + $number = new Number('Give me a number', false, false, 5, 10); + $number->setConsole($this->adapter); + ob_start(); + $response = $number->show(); + $text = ob_get_clean(); + + $this->assertTrue((bool) preg_match('#Please enter a number not smaller than 5#', $text)); + $this->assertTrue((bool) preg_match('#Please enter a number not greater than 10#', $text)); + $this->assertEquals('6', $response); + } +} diff --git a/test/TestAssets/ConsoleAdapter.php b/test/TestAssets/ConsoleAdapter.php index 479abe5..de7242a 100644 --- a/test/TestAssets/ConsoleAdapter.php +++ b/test/TestAssets/ConsoleAdapter.php @@ -21,6 +21,7 @@ class ConsoleAdapter extends AbstractAdapter { public $stream; + public $autoRewind = true; /** * Read a single line from the console input @@ -30,7 +31,9 @@ class ConsoleAdapter extends AbstractAdapter */ public function readLine($maxLength = 2048) { - rewind($this->stream); + if($this->autoRewind) { + rewind($this->stream); + } $line = stream_get_line($this->stream, $maxLength, PHP_EOL); return rtrim($line,"\n\r"); } @@ -43,7 +46,9 @@ public function readLine($maxLength = 2048) */ public function readChar($mask = null) { - rewind($this->stream); + if($this->autoRewind) { + rewind($this->stream); + } do { $char = fread($this->stream, 1); } while ($mask !== null && "" !== $char && false === stristr($mask, $char)); From a387d6c22604d9cdeb49fd41b24845b1bb58bf53 Mon Sep 17 00:00:00 2001 From: blanchonvincent Date: Mon, 25 Feb 2013 09:27:02 +0100 Subject: [PATCH 06/24] Add tests to cover prompt/select --- test/Prompt/SelectTest.php | 67 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 test/Prompt/SelectTest.php diff --git a/test/Prompt/SelectTest.php b/test/Prompt/SelectTest.php new file mode 100644 index 0000000..c42dfa9 --- /dev/null +++ b/test/Prompt/SelectTest.php @@ -0,0 +1,67 @@ +adapter = new ConsoleAdapter(); + $this->adapter->stream = fopen('php://memory', 'w+'); + } + + public function tearDown() + { + fclose($this->adapter->stream); + } + + public function testCanSelectOption() + { + fwrite($this->adapter->stream, "0"); + + $select = new Select('Select an option :', array('foo', 'bar')); + $select->setConsole($this->adapter); + ob_start(); + $response = $select->show(); + $text = ob_get_clean(); + $this->assertTrue((bool) preg_match('#0\) foo#', $text)); + $this->assertTrue((bool) preg_match('#1\) bar#', $text)); + $this->assertEquals('0', $response); + } + + public function testCanSelectOptionWithCustomIndex() + { + fwrite($this->adapter->stream, "2"); + + $select = new Select('Select an option :', array('2' => 'foo', '6' => 'bar')); + $select->setConsole($this->adapter); + ob_start(); + $response = $select->show(); + $text = ob_get_clean(); + $this->assertTrue((bool) preg_match('#2\) foo#', $text)); + $this->assertTrue((bool) preg_match('#6\) bar#', $text)); + $this->assertEquals('2', $response); + } +} From 113917b520c9cde3d16b3c0bbc48af1913e94d92 Mon Sep 17 00:00:00 2001 From: blanchonvincent Date: Wed, 27 Feb 2013 13:10:23 +0100 Subject: [PATCH 07/24] Add test for console request --- test/RequestTest.php | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/RequestTest.php diff --git a/test/RequestTest.php b/test/RequestTest.php new file mode 100644 index 0000000..5dbb095 --- /dev/null +++ b/test/RequestTest.php @@ -0,0 +1,46 @@ +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'); + } +} From 4171236d9199210aa3a551072df0eb096a02847b Mon Sep 17 00:00:00 2001 From: blanchonvincent Date: Wed, 27 Feb 2013 13:29:35 +0100 Subject: [PATCH 08/24] Add test for response --- test/ResponseTest.php | 78 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 test/ResponseTest.php diff --git a/test/ResponseTest.php b/test/ResponseTest.php new file mode 100644 index 0000000..13ee85e --- /dev/null +++ b/test/ResponseTest.php @@ -0,0 +1,78 @@ +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(); + } + */ +} From bf3a16c478e8cd718dae3def0c80cd489df3941e Mon Sep 17 00:00:00 2001 From: blanchonvincent Date: Wed, 27 Feb 2013 13:30:19 +0100 Subject: [PATCH 09/24] Fix PSR2 --- test/RequestTest.php | 6 +++--- test/ResponseTest.php | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/RequestTest.php b/test/RequestTest.php index 5dbb095..6799bff 100644 --- a/test/RequestTest.php +++ b/test/RequestTest.php @@ -19,7 +19,7 @@ * @group Zend_Console */ class RequestTest extends \PHPUnit_Framework_TestCase -{ +{ public function setUp() { if (ini_get('register_argc_argv') == false) { @@ -31,10 +31,10 @@ 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'); diff --git a/test/ResponseTest.php b/test/ResponseTest.php index 13ee85e..d5edc78 100644 --- a/test/ResponseTest.php +++ b/test/ResponseTest.php @@ -19,12 +19,12 @@ * @group Zend_Console */ class ResponseTest extends \PHPUnit_Framework_TestCase -{ +{ /** - * @var Response + * @var Response */ protected $response; - + public function setUp() { $this->response = new Response(); @@ -35,7 +35,7 @@ public function testInitialisation() $this->assertEquals(false, $this->response->contentSent()); $this->assertEquals(0, $this->response->getErrorLevel()); } - + public function testSetContent() { $this->response->setContent('foo, bar'); @@ -47,21 +47,21 @@ public function testSetContent() $this->assertEquals(true, $this->response->contentSent()); $this->assertEquals($this->response, $this->response->sendContent()); } - + /* public function testSetContentWithExit() { - if(!function_exists('set_exit_overload')) { + 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) { + function($param = null) use ($self) { + if ($param) { $self->assertEquals($param, 1); } + return false; } ); @@ -71,7 +71,7 @@ function($param = null) use ($self) $this->response->send(); $content = ob_get_clean(); $this->assertEquals('foo, bar', $content); - + unset_exit_overload(); } */ From 217ac1e19e21a5c36c90a9cee64636d3fb97f5c0 Mon Sep 17 00:00:00 2001 From: blanchonvincent Date: Wed, 27 Feb 2013 23:13:02 +0100 Subject: [PATCH 10/24] Add resetInstance & keep more clean isConsole method --- src/Console.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Console.php b/src/Console.php index 7389e60..b4f5a2f 100644 --- a/src/Console.php +++ b/src/Console.php @@ -101,6 +101,14 @@ public static function getInstance($forceAdapter = null, $forceCharset = null) return static::$instance; } + /** + * Reset the console instance + */ + public static function resetInstance() + { + static::$instance = null; + } + /** * Check if currently running under MS Windows * @@ -135,10 +143,10 @@ public static function isAnsicon() */ public static function isConsole() { - if (null !== static::$isConsole && is_bool(static::$isConsole)) { - return static::$isConsole; + if (null === static::$isConsole) { + static::$isConsole = (PHP_SAPI == 'cli'); } - return PHP_SAPI == 'cli'; + return static::$isConsole; } /** @@ -148,6 +156,9 @@ public static function isConsole() */ public static function overrideIsConsole($flag) { + if(null != $flag) { + $flag = (bool)$flag; + } static::$isConsole = $flag; } From ac516ede2cc61ce8f1c8946c83bddbfb6af36d57 Mon Sep 17 00:00:00 2001 From: blanchonvincent Date: Wed, 27 Feb 2013 23:13:14 +0100 Subject: [PATCH 11/24] Add tests on Zend\Console --- test/ConsoleTest.php | 86 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 test/ConsoleTest.php diff --git a/test/ConsoleTest.php b/test/ConsoleTest.php new file mode 100644 index 0000000..49779a3 --- /dev/null +++ b/test/ConsoleTest.php @@ -0,0 +1,86 @@ +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); + } +} From 265399f28c7cfee4274c6d8d0fd5e99da3bae95c Mon Sep 17 00:00:00 2001 From: blanchonvincent Date: Wed, 27 Feb 2013 23:39:47 +0100 Subject: [PATCH 12/24] Remove useless method in interface --- src/Adapter/AdapterInterface.php | 35 -------------------------------- 1 file changed, 35 deletions(-) diff --git a/src/Adapter/AdapterInterface.php b/src/Adapter/AdapterInterface.php index 2b9e320..eb3f8d3 100644 --- a/src/Adapter/AdapterInterface.php +++ b/src/Adapter/AdapterInterface.php @@ -143,28 +143,6 @@ public function getSize(); */ public function isUtf8(); - -// /** -// * Return current cursor position - array($x, $y) -// * -// * @return array array($x, $y); -// */ -// public function getPos(); -// -// /** -// * Return current cursor X coordinate (column) -// * -// * @return false|int Integer or false if failed to determine. -// */ -// public function getX(); -// -// /** -// * Return current cursor Y coordinate (row) -// * -// * @return false|int Integer or false if failed to determine. -// */ -// public function getY(); - /** * Set cursor position * @@ -190,19 +168,6 @@ public function showCursor(); */ public function getTitle(); - /** - * Set console window title - * - * @param $title - */ - public function setTitle($title); - - /** - * Reset console window title to previous value. - */ - public function resetTitle(); - - /** * Prepare a string that will be rendered in color. * From a483d9ff3f40d0ecfc49b575adbc0f4b80b6c259 Mon Sep 17 00:00:00 2001 From: blanchonvincent Date: Wed, 27 Feb 2013 23:43:32 +0100 Subject: [PATCH 13/24] Fix variable to remove newline characters --- src/Adapter/AbstractAdapter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index 4a406f9..53c6cea 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -85,7 +85,7 @@ public function writeLine($text = "", $color = null, $bgColor = null) $text = trim($text, "\r\n"); // Replace newline characters with spaces - $test = str_replace("\n", " ", $text); + $text = str_replace("\n", " ", $text); // Trim the line if it's too long and output text $consoleWidth = $this->getWidth(); From 5bd42eab1d475072776aa21be5cd6e532b5e3b4f Mon Sep 17 00:00:00 2001 From: blanchonvincent Date: Wed, 27 Feb 2013 23:43:49 +0100 Subject: [PATCH 14/24] Update the test with the fix of newline => space --- test/Adapater/AbstractAdapterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Adapater/AbstractAdapterTest.php b/test/Adapater/AbstractAdapterTest.php index 3b684f7..8752da5 100644 --- a/test/Adapater/AbstractAdapterTest.php +++ b/test/Adapater/AbstractAdapterTest.php @@ -58,7 +58,7 @@ public function testWriteLine() ob_start(); $this->adapter->writeLine("foo\nbar"); - $this->assertEquals("foo\nbar\n", ob_get_clean()); + $this->assertEquals("foo bar\n", ob_get_clean()); ob_start(); $this->adapter->writeLine("\rfoo\r"); From 57c0e5cc243fec49c303235faf65b3276aabaae2 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 11 Mar 2013 13:32:36 -0500 Subject: [PATCH 15/24] [zendframework/zf2#3885] Annotations cleanup - Added class-level annotation to abstract console class - Removed unwanted annotations from test classes --- src/Adapter/AbstractAdapter.php | 3 +++ test/Adapater/AbstractAdapterTest.php | 4 ---- test/TestAssets/ConsoleAdapter.php | 4 ---- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index 53c6cea..4d7fe89 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -12,6 +12,9 @@ use Zend\Console\Charset; use Zend\Console\Exception; +/** + * Common console adapter codebase + */ abstract class AbstractAdapter implements AdapterInterface { /** diff --git a/test/Adapater/AbstractAdapterTest.php b/test/Adapater/AbstractAdapterTest.php index 8752da5..76d131a 100644 --- a/test/Adapater/AbstractAdapterTest.php +++ b/test/Adapater/AbstractAdapterTest.php @@ -5,7 +5,6 @@ * @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\Adapater; @@ -13,9 +12,6 @@ use ZendTest\Console\TestAssets\ConsoleAdapter; /** - * @category Zend - * @package Zend_Console - * @subpackage UnitTests * @group Zend_Console */ class AbstractAdapterTest extends \PHPUnit_Framework_TestCase diff --git a/test/TestAssets/ConsoleAdapter.php b/test/TestAssets/ConsoleAdapter.php index 479abe5..d8dab2b 100644 --- a/test/TestAssets/ConsoleAdapter.php +++ b/test/TestAssets/ConsoleAdapter.php @@ -5,7 +5,6 @@ * @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\TestAssets; @@ -13,9 +12,6 @@ use Zend\Console\Adapter\AbstractAdapter; /** - * @category Zend - * @package Zend_Console - * @subpackage UnitTests * @group Zend_Console */ class ConsoleAdapter extends AbstractAdapter From c5a0144d6620c112116d5f7cefc1117b457daa33 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 11 Mar 2013 13:32:52 -0500 Subject: [PATCH 16/24] [zendframework/zf2#3885] CS fixes - trailing whitespace --- test/TestAssets/ConsoleAdapter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/TestAssets/ConsoleAdapter.php b/test/TestAssets/ConsoleAdapter.php index d8dab2b..7c025c9 100644 --- a/test/TestAssets/ConsoleAdapter.php +++ b/test/TestAssets/ConsoleAdapter.php @@ -17,7 +17,7 @@ class ConsoleAdapter extends AbstractAdapter { public $stream; - + /** * Read a single line from the console input * From 5304ba465dd818bd66b4d41b14f88326078e74e9 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 11 Mar 2013 13:37:52 -0500 Subject: [PATCH 17/24] [zendframework/zf2#3886] annotation cleanup - Removed unnecessary annotations --- test/Prompt/CharTest.php | 4 ---- test/Prompt/LineTest.php | 4 ---- test/Prompt/NumberTest.php | 4 ---- test/Prompt/SelectTest.php | 4 ---- 4 files changed, 16 deletions(-) diff --git a/test/Prompt/CharTest.php b/test/Prompt/CharTest.php index 611e113..77e5926 100644 --- a/test/Prompt/CharTest.php +++ b/test/Prompt/CharTest.php @@ -5,7 +5,6 @@ * @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\Char; @@ -14,9 +13,6 @@ use ZendTest\Console\TestAssets\ConsoleAdapter; /** - * @category Zend - * @package Zend_Console - * @subpackage UnitTests * @group Zend_Console */ class CharTest extends \PHPUnit_Framework_TestCase diff --git a/test/Prompt/LineTest.php b/test/Prompt/LineTest.php index 62f0b2b..3f110b7 100644 --- a/test/Prompt/LineTest.php +++ b/test/Prompt/LineTest.php @@ -5,7 +5,6 @@ * @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\Char; @@ -14,9 +13,6 @@ use ZendTest\Console\TestAssets\ConsoleAdapter; /** - * @category Zend - * @package Zend_Console - * @subpackage UnitTests * @group Zend_Console */ class LineTest extends \PHPUnit_Framework_TestCase diff --git a/test/Prompt/NumberTest.php b/test/Prompt/NumberTest.php index 97c7f93..c79a9f0 100644 --- a/test/Prompt/NumberTest.php +++ b/test/Prompt/NumberTest.php @@ -5,7 +5,6 @@ * @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\Char; @@ -14,9 +13,6 @@ use ZendTest\Console\TestAssets\ConsoleAdapter; /** - * @category Zend - * @package Zend_Console - * @subpackage UnitTests * @group Zend_Console */ class NumberTest extends \PHPUnit_Framework_TestCase diff --git a/test/Prompt/SelectTest.php b/test/Prompt/SelectTest.php index c42dfa9..8aed22f 100644 --- a/test/Prompt/SelectTest.php +++ b/test/Prompt/SelectTest.php @@ -5,7 +5,6 @@ * @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\Char; @@ -14,9 +13,6 @@ use ZendTest\Console\TestAssets\ConsoleAdapter; /** - * @category Zend - * @package Zend_Console - * @subpackage UnitTests * @group Zend_Console */ class SelectTest extends \PHPUnit_Framework_TestCase From 3293c9816aeba738b2aa7947971d99d7e6c985f7 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 11 Mar 2013 13:38:19 -0500 Subject: [PATCH 18/24] [zendframework/zf2#3886] CS fixes - trailing whitespace --- test/TestAssets/ConsoleAdapter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/TestAssets/ConsoleAdapter.php b/test/TestAssets/ConsoleAdapter.php index 878174b..0fd8de0 100644 --- a/test/TestAssets/ConsoleAdapter.php +++ b/test/TestAssets/ConsoleAdapter.php @@ -19,7 +19,7 @@ class ConsoleAdapter extends AbstractAdapter public $stream; public $autoRewind = true; - + /** * Read a single line from the console input * From 91ed0b68924acd312662bd93a8835b181e755911 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 11 Mar 2013 15:24:56 -0500 Subject: [PATCH 19/24] [zendframework/zf2#3917] CS fixes - trailing whitespace --- src/Adapter/AbstractAdapter.php | 4 ++-- src/Adapter/Virtual.php | 2 +- src/Adapter/Windows.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index ad985e7..f684f30 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -358,7 +358,7 @@ public function isUtf8() { return true; } - + /** * Set cursor position * @@ -392,7 +392,7 @@ public function getTitle() { return ''; } - + /** * Prepare a string that will be rendered in color. * diff --git a/src/Adapter/Virtual.php b/src/Adapter/Virtual.php index 3aa4b3a..bd983cb 100644 --- a/src/Adapter/Virtual.php +++ b/src/Adapter/Virtual.php @@ -115,7 +115,7 @@ public function isUtf8() return false; } - + /** * Return current console window title. * diff --git a/src/Adapter/Windows.php b/src/Adapter/Windows.php index e808dda..85966c4 100644 --- a/src/Adapter/Windows.php +++ b/src/Adapter/Windows.php @@ -143,7 +143,7 @@ public function isUtf8() return false; } - + /** * Return current console window title. * From 5e2b9026b49996647c13820bfff1cdaa08e460a6 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 11 Mar 2013 15:27:09 -0500 Subject: [PATCH 20/24] [zendframework/zf2#3907] CS fixes - trailing whitespace --- src/Console.php | 2 +- src/Request.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Console.php b/src/Console.php index b4f5a2f..0e84cb8 100644 --- a/src/Console.php +++ b/src/Console.php @@ -108,7 +108,7 @@ public static function resetInstance() { static::$instance = null; } - + /** * Check if currently running under MS Windows * diff --git a/src/Request.php b/src/Request.php index c1c4643..16d6bf0 100644 --- a/src/Request.php +++ b/src/Request.php @@ -134,7 +134,7 @@ public function setEnv(Parameters $env) $this->envParams = $env; return $this; } - + /** * Return a single parameter container responsible for env parameters * From ddb9c658b58bdaa5cb4d635fc4f199b428b1d10d Mon Sep 17 00:00:00 2001 From: blanchonvincent Date: Mon, 11 Mar 2013 22:52:23 +0100 Subject: [PATCH 21/24] Add tests for sensitive case --- src/Prompt/Confirm.php | 9 +++++++-- test/Adapater/AbstractAdapterTest.php | 12 ++---------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/Prompt/Confirm.php b/src/Prompt/Confirm.php index 65a8a05..7ec79ea 100644 --- a/src/Prompt/Confirm.php +++ b/src/Prompt/Confirm.php @@ -67,8 +67,13 @@ public function __construct( * @return bool */ public function show() - { - $response = parent::show() === $this->yesChar; + { + $char = parent::show(); + if($this->ignoreCase) { + $response = strtolower($char) === strtolower($this->yesChar); + } else { + $response = $char === $this->yesChar; + } return $this->lastResponse = $response; } diff --git a/test/Adapater/AbstractAdapterTest.php b/test/Adapater/AbstractAdapterTest.php index 76d131a..24f3aa7 100644 --- a/test/Adapater/AbstractAdapterTest.php +++ b/test/Adapater/AbstractAdapterTest.php @@ -92,20 +92,12 @@ public function testReadCharWithMask() $char = $this->adapter->readChar('ar'); $this->assertEquals($char, 'a'); } - + public function testReadCharWithMaskInsensitiveCase() { fwrite($this->adapter->stream, 'bAr'); $char = $this->adapter->readChar('ar'); - $this->assertEquals($char, 'A'); - } - - public function testReadCharWithNoReturn() - { - fwrite($this->adapter->stream, 'bar'); - - $char = $this->adapter->readChar('foo'); - $this->assertEquals($char, ''); + $this->assertEquals($char, 'r'); } } From d721e23a8444dd5a5b38ad8fc4922e750d56cc44 Mon Sep 17 00:00:00 2001 From: blanchonvincent Date: Mon, 11 Mar 2013 22:52:47 +0100 Subject: [PATCH 22/24] Add tests on prompt char & confirm --- test/Prompt/CharTest.php | 31 ++++++++++- test/Prompt/ConfirmTest.php | 108 ++++++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 test/Prompt/ConfirmTest.php diff --git a/test/Prompt/CharTest.php b/test/Prompt/CharTest.php index 77e5926..2d11224 100644 --- a/test/Prompt/CharTest.php +++ b/test/Prompt/CharTest.php @@ -49,14 +49,14 @@ public function testCanPromptChar() public function testCanPromptCharWithCharNotInDefaultMask() { - fwrite($this->adapter->stream, 'zywa'); + fwrite($this->adapter->stream, '*zywa'); $char = new Char(); $char->setEcho(false); $char->setConsole($this->adapter); ob_start(); $response = $char->show(); - $text = ob_get_clean(); + ob_get_clean(); $this->assertEquals('z', $response); } @@ -73,4 +73,31 @@ public function testCanPromptCharWithNewQuestionAndMask() $this->assertEquals($text, "Give a number\n"); $this->assertEquals('1', $response); } + + public function testCanPromptCharWithIgnoreCaseByDefault() + { + fwrite($this->adapter->stream, 'FOObar'); + + $char = new Char(); + $char->setEcho(false); + $char->setConsole($this->adapter); + ob_start(); + $response = $char->show(); + ob_get_clean(); + $this->assertEquals('F', $response); + } + + public function testCanPromptCharWithoutIgnoreCase() + { + fwrite($this->adapter->stream, 'FOObar'); + + $char = new Char(); + $char->setEcho(false); + $char->setConsole($this->adapter); + $char->setIgnoreCase(false); + ob_start(); + $response = $char->show(); + ob_get_clean(); + $this->assertEquals('b', $response); + } } diff --git a/test/Prompt/ConfirmTest.php b/test/Prompt/ConfirmTest.php new file mode 100644 index 0000000..a1df137 --- /dev/null +++ b/test/Prompt/ConfirmTest.php @@ -0,0 +1,108 @@ +adapter = new ConsoleAdapter(); + $this->adapter->stream = fopen('php://memory', 'w+'); + } + + public function tearDown() + { + fclose($this->adapter->stream); + } + + public function testCanPromptConfirm() + { + fwrite($this->adapter->stream, 'y'); + + $confirm = new Confirm("ZF2 is the better framework ?"); + $confirm->setEcho(false); + $confirm->setConsole($this->adapter); + ob_start(); + $response = $confirm->show(); + $text = ob_get_clean(); + $this->assertEquals($text, "ZF2 is the better framework ?\n"); + $this->assertTrue($response); + } + + public function testCanPromptConfirmWithDefaultIgnoreCase() + { + fwrite($this->adapter->stream, 'Y'); + + $confirm = new Confirm("ZF2 is the better framework ?"); + $confirm->setEcho(false); + $confirm->setConsole($this->adapter); + ob_start(); + $response = $confirm->show(); + $text = ob_get_clean(); + $this->assertEquals($text, "ZF2 is the better framework ?\n"); + $this->assertTrue($response); + } + + public function testCanPromptConfirmWithoutIgnoreCase() + { + fwrite($this->adapter->stream, 'Yn'); + + $confirm = new Confirm("ZF2 is the better framework ?"); + $confirm->setEcho(false); + $confirm->setConsole($this->adapter); + $confirm->setIgnoreCase(false); + ob_start(); + $response = $confirm->show(); + $text = ob_get_clean(); + $this->assertEquals($text, "ZF2 is the better framework ?\n"); + $this->assertFalse($response); + } + + public function testCanPromptConfirmWithYesNoCharChanged() + { + fwrite($this->adapter->stream, 'on0'); + + $confirm = new Confirm("ZF2 is the better framework ?", "1", "0"); + $confirm->setEcho(false); + $confirm->setConsole($this->adapter); + ob_start(); + $response = $confirm->show(); + $text = ob_get_clean(); + $this->assertEquals($text, "ZF2 is the better framework ?\n"); + $this->assertFalse($response); + } + + public function testCanPromptConfirmWithYesNoCharChangedWithSetter() + { + fwrite($this->adapter->stream, 'oaB'); + + $confirm = new Confirm("ZF2 is the better framework ?", "1", "0"); + $confirm->setYesChar("A"); + $confirm->setNoChar("B"); + $confirm->setEcho(false); + $confirm->setConsole($this->adapter); + ob_start(); + $response = $confirm->show(); + $text = ob_get_clean(); + $this->assertEquals($text, "ZF2 is the better framework ?\n"); + $this->assertTrue($response); + } +} From 0cc7c3de85575ab0264fb0a63dfbc21aff96fc98 Mon Sep 17 00:00:00 2001 From: blanchonvincent Date: Tue, 12 Mar 2013 08:10:54 +0100 Subject: [PATCH 23/24] Fix wording --- test/Prompt/ConfirmTest.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/Prompt/ConfirmTest.php b/test/Prompt/ConfirmTest.php index a1df137..92aa384 100644 --- a/test/Prompt/ConfirmTest.php +++ b/test/Prompt/ConfirmTest.php @@ -37,13 +37,13 @@ public function testCanPromptConfirm() { fwrite($this->adapter->stream, 'y'); - $confirm = new Confirm("ZF2 is the better framework ?"); + $confirm = new Confirm("Is ZF2 the best framework ?"); $confirm->setEcho(false); $confirm->setConsole($this->adapter); ob_start(); $response = $confirm->show(); $text = ob_get_clean(); - $this->assertEquals($text, "ZF2 is the better framework ?\n"); + $this->assertEquals($text, "Is ZF2 the best framework ?\n"); $this->assertTrue($response); } @@ -51,13 +51,13 @@ public function testCanPromptConfirmWithDefaultIgnoreCase() { fwrite($this->adapter->stream, 'Y'); - $confirm = new Confirm("ZF2 is the better framework ?"); + $confirm = new Confirm("Is ZF2 the best framework ?"); $confirm->setEcho(false); $confirm->setConsole($this->adapter); ob_start(); $response = $confirm->show(); $text = ob_get_clean(); - $this->assertEquals($text, "ZF2 is the better framework ?\n"); + $this->assertEquals($text, "Is ZF2 the best framework ?\n"); $this->assertTrue($response); } @@ -65,14 +65,14 @@ public function testCanPromptConfirmWithoutIgnoreCase() { fwrite($this->adapter->stream, 'Yn'); - $confirm = new Confirm("ZF2 is the better framework ?"); + $confirm = new Confirm("Is ZF2 the best framework ?"); $confirm->setEcho(false); $confirm->setConsole($this->adapter); $confirm->setIgnoreCase(false); ob_start(); $response = $confirm->show(); $text = ob_get_clean(); - $this->assertEquals($text, "ZF2 is the better framework ?\n"); + $this->assertEquals($text, "Is ZF2 the best framework ?\n"); $this->assertFalse($response); } @@ -80,13 +80,13 @@ public function testCanPromptConfirmWithYesNoCharChanged() { fwrite($this->adapter->stream, 'on0'); - $confirm = new Confirm("ZF2 is the better framework ?", "1", "0"); + $confirm = new Confirm("Is ZF2 the best framework ?", "1", "0"); $confirm->setEcho(false); $confirm->setConsole($this->adapter); ob_start(); $response = $confirm->show(); $text = ob_get_clean(); - $this->assertEquals($text, "ZF2 is the better framework ?\n"); + $this->assertEquals($text, "Is ZF2 the best framework ?\n"); $this->assertFalse($response); } @@ -94,7 +94,7 @@ public function testCanPromptConfirmWithYesNoCharChangedWithSetter() { fwrite($this->adapter->stream, 'oaB'); - $confirm = new Confirm("ZF2 is the better framework ?", "1", "0"); + $confirm = new Confirm("Is ZF2 the best framework ?", "1", "0"); $confirm->setYesChar("A"); $confirm->setNoChar("B"); $confirm->setEcho(false); @@ -102,7 +102,7 @@ public function testCanPromptConfirmWithYesNoCharChangedWithSetter() ob_start(); $response = $confirm->show(); $text = ob_get_clean(); - $this->assertEquals($text, "ZF2 is the better framework ?\n"); + $this->assertEquals($text, "Is ZF2 the best framework ?\n"); $this->assertTrue($response); } } From f05077e401ccc946394e4d87b6a025d43e8373db Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 12 Mar 2013 12:22:25 -0500 Subject: [PATCH 24/24] [zendframework/zf2#4005] CS fixes - trailing whitespace --- src/Prompt/Char.php | 2 +- src/Prompt/Confirm.php | 2 +- test/Adapater/AbstractAdapterTest.php | 2 +- test/Prompt/CharTest.php | 8 ++++---- test/Prompt/ConfirmTest.php | 10 +++++----- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Prompt/Char.php b/src/Prompt/Char.php index 55c2434..648ff2c 100644 --- a/src/Prompt/Char.php +++ b/src/Prompt/Char.php @@ -88,7 +88,7 @@ public function show() $mask = array_unique($mask); // remove duplicates $mask = implode("", $mask); // convert back to string } - + /** * Read char from console */ diff --git a/src/Prompt/Confirm.php b/src/Prompt/Confirm.php index 7ec79ea..83f949a 100644 --- a/src/Prompt/Confirm.php +++ b/src/Prompt/Confirm.php @@ -67,7 +67,7 @@ public function __construct( * @return bool */ public function show() - { + { $char = parent::show(); if($this->ignoreCase) { $response = strtolower($char) === strtolower($this->yesChar); diff --git a/test/Adapater/AbstractAdapterTest.php b/test/Adapater/AbstractAdapterTest.php index 24f3aa7..21ba5ae 100644 --- a/test/Adapater/AbstractAdapterTest.php +++ b/test/Adapater/AbstractAdapterTest.php @@ -92,7 +92,7 @@ public function testReadCharWithMask() $char = $this->adapter->readChar('ar'); $this->assertEquals($char, 'a'); } - + public function testReadCharWithMaskInsensitiveCase() { fwrite($this->adapter->stream, 'bAr'); diff --git a/test/Prompt/CharTest.php b/test/Prompt/CharTest.php index 2d11224..ffcac9d 100644 --- a/test/Prompt/CharTest.php +++ b/test/Prompt/CharTest.php @@ -73,11 +73,11 @@ public function testCanPromptCharWithNewQuestionAndMask() $this->assertEquals($text, "Give a number\n"); $this->assertEquals('1', $response); } - + public function testCanPromptCharWithIgnoreCaseByDefault() { fwrite($this->adapter->stream, 'FOObar'); - + $char = new Char(); $char->setEcho(false); $char->setConsole($this->adapter); @@ -86,11 +86,11 @@ public function testCanPromptCharWithIgnoreCaseByDefault() ob_get_clean(); $this->assertEquals('F', $response); } - + public function testCanPromptCharWithoutIgnoreCase() { fwrite($this->adapter->stream, 'FOObar'); - + $char = new Char(); $char->setEcho(false); $char->setConsole($this->adapter); diff --git a/test/Prompt/ConfirmTest.php b/test/Prompt/ConfirmTest.php index 92aa384..b9afd05 100644 --- a/test/Prompt/ConfirmTest.php +++ b/test/Prompt/ConfirmTest.php @@ -32,7 +32,7 @@ public function tearDown() { fclose($this->adapter->stream); } - + public function testCanPromptConfirm() { fwrite($this->adapter->stream, 'y'); @@ -46,7 +46,7 @@ public function testCanPromptConfirm() $this->assertEquals($text, "Is ZF2 the best framework ?\n"); $this->assertTrue($response); } - + public function testCanPromptConfirmWithDefaultIgnoreCase() { fwrite($this->adapter->stream, 'Y'); @@ -60,7 +60,7 @@ public function testCanPromptConfirmWithDefaultIgnoreCase() $this->assertEquals($text, "Is ZF2 the best framework ?\n"); $this->assertTrue($response); } - + public function testCanPromptConfirmWithoutIgnoreCase() { fwrite($this->adapter->stream, 'Yn'); @@ -75,7 +75,7 @@ public function testCanPromptConfirmWithoutIgnoreCase() $this->assertEquals($text, "Is ZF2 the best framework ?\n"); $this->assertFalse($response); } - + public function testCanPromptConfirmWithYesNoCharChanged() { fwrite($this->adapter->stream, 'on0'); @@ -89,7 +89,7 @@ public function testCanPromptConfirmWithYesNoCharChanged() $this->assertEquals($text, "Is ZF2 the best framework ?\n"); $this->assertFalse($response); } - + public function testCanPromptConfirmWithYesNoCharChangedWithSetter() { fwrite($this->adapter->stream, 'oaB');