From bb69b4bd79a807d110683b45442c7647466242aa Mon Sep 17 00:00:00 2001 From: Elliot Chance Date: Wed, 10 Sep 2014 23:14:10 +1000 Subject: [PATCH 01/11] testVerbosityCanBeSet --- src/Concise/Console/ResultPrinter/AbstractResultPrinter.php | 4 ++++ .../Console/ResultPrinter/AbstractResultPrinterTest.php | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/Concise/Console/ResultPrinter/AbstractResultPrinter.php b/src/Concise/Console/ResultPrinter/AbstractResultPrinter.php index aeaf79a2..93767cd0 100644 --- a/src/Concise/Console/ResultPrinter/AbstractResultPrinter.php +++ b/src/Concise/Console/ResultPrinter/AbstractResultPrinter.php @@ -91,4 +91,8 @@ public function write($string) public function end() { } + + public function setVerbose($verbose) + { + } } diff --git a/tests/Concise/Console/ResultPrinter/AbstractResultPrinterTest.php b/tests/Concise/Console/ResultPrinter/AbstractResultPrinterTest.php index 3562cc36..a8e290b3 100644 --- a/tests/Concise/Console/ResultPrinter/AbstractResultPrinterTest.php +++ b/tests/Concise/Console/ResultPrinter/AbstractResultPrinterTest.php @@ -119,4 +119,9 @@ public function testEndReturnsNull() { $this->assert($this->resultPrinter->end(), is_null); } + + public function testVerbosityCanBeSet() + { + $this->assert($this->resultPrinter->setVerbose(false), is_null); + } } From 34f9d2a49ae832bc1778f4406da7ad1b47efb059 Mon Sep 17 00:00:00 2001 From: Elliot Chance Date: Wed, 10 Sep 2014 23:16:06 +1000 Subject: [PATCH 02/11] testDefaultVerboseIsOff --- src/Concise/Console/ResultPrinter/AbstractResultPrinter.php | 5 +++++ .../Console/ResultPrinter/AbstractResultPrinterTest.php | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/Concise/Console/ResultPrinter/AbstractResultPrinter.php b/src/Concise/Console/ResultPrinter/AbstractResultPrinter.php index 93767cd0..93d744b0 100644 --- a/src/Concise/Console/ResultPrinter/AbstractResultPrinter.php +++ b/src/Concise/Console/ResultPrinter/AbstractResultPrinter.php @@ -95,4 +95,9 @@ public function end() public function setVerbose($verbose) { } + + public function isVerbose() + { + return false; + } } diff --git a/tests/Concise/Console/ResultPrinter/AbstractResultPrinterTest.php b/tests/Concise/Console/ResultPrinter/AbstractResultPrinterTest.php index a8e290b3..81c09466 100644 --- a/tests/Concise/Console/ResultPrinter/AbstractResultPrinterTest.php +++ b/tests/Concise/Console/ResultPrinter/AbstractResultPrinterTest.php @@ -124,4 +124,9 @@ public function testVerbosityCanBeSet() { $this->assert($this->resultPrinter->setVerbose(false), is_null); } + + public function testDefaultVerboseIsOff() + { + $this->assert($this->resultPrinter->isVerbose(), is_false); + } } From 87c25713d1f5e9628bde08cd421cf0ff103ee4ce Mon Sep 17 00:00:00 2001 From: Elliot Chance Date: Wed, 10 Sep 2014 23:17:45 +1000 Subject: [PATCH 03/11] testGetVerbose --- src/Concise/Console/ResultPrinter/AbstractResultPrinter.php | 5 ++++- .../Console/ResultPrinter/AbstractResultPrinterTest.php | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Concise/Console/ResultPrinter/AbstractResultPrinter.php b/src/Concise/Console/ResultPrinter/AbstractResultPrinter.php index 93d744b0..eaf6efec 100644 --- a/src/Concise/Console/ResultPrinter/AbstractResultPrinter.php +++ b/src/Concise/Console/ResultPrinter/AbstractResultPrinter.php @@ -25,6 +25,8 @@ abstract class AbstractResultPrinter implements TestResultDelegateInterface, Sta public $assertionCount = 0; + protected $verbose = false; + public function getSuccessCount() { return $this->getTestCount() - $this->getFailureCount() - $this->getErrorCount() @@ -94,10 +96,11 @@ public function end() public function setVerbose($verbose) { + $this->verbose = $verbose; } public function isVerbose() { - return false; + return $this->verbose; } } diff --git a/tests/Concise/Console/ResultPrinter/AbstractResultPrinterTest.php b/tests/Concise/Console/ResultPrinter/AbstractResultPrinterTest.php index 81c09466..d3c4b465 100644 --- a/tests/Concise/Console/ResultPrinter/AbstractResultPrinterTest.php +++ b/tests/Concise/Console/ResultPrinter/AbstractResultPrinterTest.php @@ -129,4 +129,10 @@ public function testDefaultVerboseIsOff() { $this->assert($this->resultPrinter->isVerbose(), is_false); } + + public function testGetVerbose() + { + $this->resultPrinter->setVerbose(true); + $this->assert($this->resultPrinter->isVerbose(), is_true); + } } From 09d597e9a3e64526c455fac54a34fa51ecbeb92b Mon Sep 17 00:00:00 2001 From: Elliot Chance Date: Sat, 13 Sep 2014 11:38:40 +1000 Subject: [PATCH 04/11] testVerboseIsFalseByDefault --- src/Concise/Console/Command.php | 4 +++- tests/Concise/Console/CommandTest.php | 21 +++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Concise/Console/Command.php b/src/Concise/Console/Command.php index 447e11b2..9b643812 100644 --- a/src/Concise/Console/Command.php +++ b/src/Concise/Console/Command.php @@ -4,13 +4,15 @@ use Concise\Console\TestRunner\DefaultTestRunner; use Concise\Console\ResultPrinter\ResultPrinterProxy; +use Concise\Console\ResultPrinter\DefaultResultPrinter; class Command extends \PHPUnit_TextUI_Command { protected function createRunner() { + $resultPrinter = new DefaultResultPrinter(); $testRunner = new DefaultTestRunner(); - $testRunner->setPrinter(new ResultPrinterProxy()); + $testRunner->setPrinter(new ResultPrinterProxy($resultPrinter)); return $testRunner; } diff --git a/tests/Concise/Console/CommandTest.php b/tests/Concise/Console/CommandTest.php index dc03566c..d9ae6901 100644 --- a/tests/Concise/Console/CommandTest.php +++ b/tests/Concise/Console/CommandTest.php @@ -11,19 +11,28 @@ public function testCommandExtendsPHPUnit() $this->assert(new Command(), instance_of, 'PHPUnit_TextUI_Command'); } + protected function getCommandMock() + { + return $this->niceMock('Concise\Console\Command') + ->expose('createRunner') + ->done(); + } + public function testCreateRunnerReturnsAConciseRunner() { - $command = $this->niceMock('Concise\Console\Command') - ->expose('createRunner') - ->done(); + $command = $this->getCommandMock(); $this->assert($command->createRunner(), instance_of, 'Concise\Console\TestRunner\DefaultTestRunner'); } public function testPrinterUsesProxy() { - $command = $this->niceMock('Concise\Console\Command') - ->expose('createRunner') - ->done(); + $command = $this->getCommandMock(); $this->assert($command->createRunner()->getPrinter(), instance_of, 'Concise\Console\ResultPrinter\ResultPrinterProxy'); } + + public function testVerboseIsFalseByDefault() + { + $command = $this->getCommandMock(); + $this->assert($command->createRunner()->getPrinter()->getResultPrinter()->isVerbose(), is_false); + } } From 4c725a403765aefd9639cc9a6fb522dd10f20002 Mon Sep 17 00:00:00 2001 From: Elliot Chance Date: Sat, 13 Sep 2014 11:42:13 +1000 Subject: [PATCH 05/11] testVerboseIsTurnedOnIfItExistsAndHasBeenSet --- src/Concise/Console/Command.php | 3 +++ tests/Concise/Console/CommandTest.php | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Concise/Console/Command.php b/src/Concise/Console/Command.php index 9b643812..fbd2a4af 100644 --- a/src/Concise/Console/Command.php +++ b/src/Concise/Console/Command.php @@ -11,6 +11,9 @@ class Command extends \PHPUnit_TextUI_Command protected function createRunner() { $resultPrinter = new DefaultResultPrinter(); + if (array_key_exists('verbose', $this->arguments)) { + $resultPrinter->setVerbose(true); + } $testRunner = new DefaultTestRunner(); $testRunner->setPrinter(new ResultPrinterProxy($resultPrinter)); diff --git a/tests/Concise/Console/CommandTest.php b/tests/Concise/Console/CommandTest.php index d9ae6901..88734655 100644 --- a/tests/Concise/Console/CommandTest.php +++ b/tests/Concise/Console/CommandTest.php @@ -4,6 +4,14 @@ use \Concise\TestCase; +class CommandStub extends Command +{ + public function setArgument($name, $value) + { + $this->arguments[$name] = $value; + } +} + class CommandTest extends TestCase { public function testCommandExtendsPHPUnit() @@ -13,7 +21,7 @@ public function testCommandExtendsPHPUnit() protected function getCommandMock() { - return $this->niceMock('Concise\Console\Command') + return $this->niceMock('Concise\Console\CommandStub') ->expose('createRunner') ->done(); } @@ -35,4 +43,11 @@ public function testVerboseIsFalseByDefault() $command = $this->getCommandMock(); $this->assert($command->createRunner()->getPrinter()->getResultPrinter()->isVerbose(), is_false); } + + public function testVerboseIsTurnedOnIfItExistsAndHasBeenSet() + { + $command = $this->getCommandMock(); + $command->setArgument('verbose', true); + $this->assert($command->createRunner()->getPrinter()->getResultPrinter()->isVerbose(), is_true); + } } From 764b7deb1a2f8a753b4f72489d6a20fdf91abe00 Mon Sep 17 00:00:00 2001 From: Elliot Chance Date: Sat, 13 Sep 2014 11:43:30 +1000 Subject: [PATCH 06/11] testVerboseIsNotTurnedOnIfItExistsButIfNotTrue --- src/Concise/Console/Command.php | 2 +- tests/Concise/Console/CommandTest.php | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Concise/Console/Command.php b/src/Concise/Console/Command.php index fbd2a4af..e2532cf4 100644 --- a/src/Concise/Console/Command.php +++ b/src/Concise/Console/Command.php @@ -11,7 +11,7 @@ class Command extends \PHPUnit_TextUI_Command protected function createRunner() { $resultPrinter = new DefaultResultPrinter(); - if (array_key_exists('verbose', $this->arguments)) { + if (array_key_exists('verbose', $this->arguments) && $this->arguments['verbose']) { $resultPrinter->setVerbose(true); } $testRunner = new DefaultTestRunner(); diff --git a/tests/Concise/Console/CommandTest.php b/tests/Concise/Console/CommandTest.php index 88734655..77fe786c 100644 --- a/tests/Concise/Console/CommandTest.php +++ b/tests/Concise/Console/CommandTest.php @@ -50,4 +50,11 @@ public function testVerboseIsTurnedOnIfItExistsAndHasBeenSet() $command->setArgument('verbose', true); $this->assert($command->createRunner()->getPrinter()->getResultPrinter()->isVerbose(), is_true); } + + public function testVerboseIsNotTurnedOnIfItExistsButIfNotTrue() + { + $command = $this->getCommandMock(); + $command->setArgument('verbose', false); + $this->assert($command->createRunner()->getPrinter()->getResultPrinter()->isVerbose(), is_false); + } } From 878fd8f63e68b3806c8d8b38570dd46153e4162c Mon Sep 17 00:00:00 2001 From: Elliot Chance Date: Sat, 13 Sep 2014 11:50:13 +1000 Subject: [PATCH 07/11] testSkippedItemsAreNotPrintedWhenVerboseIsTurnedOff --- .../Console/ResultPrinter/DefaultResultPrinter.php | 3 +++ .../ResultPrinter/DefaultResultPrinterTest.php | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/Concise/Console/ResultPrinter/DefaultResultPrinter.php b/src/Concise/Console/ResultPrinter/DefaultResultPrinter.php index b2fa25b0..3b6ef123 100644 --- a/src/Concise/Console/ResultPrinter/DefaultResultPrinter.php +++ b/src/Concise/Console/ResultPrinter/DefaultResultPrinter.php @@ -74,6 +74,9 @@ public function update() protected function add($status, PHPUnit_Framework_Test $test, Exception $e) { + if ($status === PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED) { + return; + } $renderIssue = new RenderIssue(); $message = $renderIssue->render($status, $this->issueNumber, $test, $e); $this->appendTextAbove("$message\n\n"); diff --git a/tests/Concise/Console/ResultPrinter/DefaultResultPrinterTest.php b/tests/Concise/Console/ResultPrinter/DefaultResultPrinterTest.php index 6b8adff0..f5a63b9b 100644 --- a/tests/Concise/Console/ResultPrinter/DefaultResultPrinterTest.php +++ b/tests/Concise/Console/ResultPrinter/DefaultResultPrinterTest.php @@ -4,6 +4,7 @@ use Concise\TestCase; use PHPUnit_Runner_BaseTestRunner; +use Exception; class DefaultResultPrinterStub extends DefaultResultPrinter { @@ -102,4 +103,16 @@ public function testEndWillUpdateProgress() ->done(); $resultPrinter->end(); } + + public function testSkippedItemsAreNotPrintedWhenVerboseIsTurnedOff() + { + $resultPrinter = $this->niceMock('Concise\Console\ResultPrinter\DefaultResultPrinter') + ->expect('appendTextAbove')->never() + ->expose('add') + ->done(); + $test = $this->niceMock('PHPUnit_Framework_TestCase') + ->stub(array('getName' => '')) + ->done(); + $resultPrinter->add(PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED, $test, new Exception()); + } } From eb43e2701cce1a71e1944c55ed45c317578672e3 Mon Sep 17 00:00:00 2001 From: Elliot Chance Date: Sat, 13 Sep 2014 11:53:19 +1000 Subject: [PATCH 08/11] testSkippedItemsArePrintedWhenVerboseIsTurnedOn --- .../Console/ResultPrinter/DefaultResultPrinter.php | 2 +- .../ResultPrinter/DefaultResultPrinterTest.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Concise/Console/ResultPrinter/DefaultResultPrinter.php b/src/Concise/Console/ResultPrinter/DefaultResultPrinter.php index 3b6ef123..e9abbe3d 100644 --- a/src/Concise/Console/ResultPrinter/DefaultResultPrinter.php +++ b/src/Concise/Console/ResultPrinter/DefaultResultPrinter.php @@ -74,7 +74,7 @@ public function update() protected function add($status, PHPUnit_Framework_Test $test, Exception $e) { - if ($status === PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED) { + if (!$this->isVerbose() && $status === PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED) { return; } $renderIssue = new RenderIssue(); diff --git a/tests/Concise/Console/ResultPrinter/DefaultResultPrinterTest.php b/tests/Concise/Console/ResultPrinter/DefaultResultPrinterTest.php index f5a63b9b..64c2e870 100644 --- a/tests/Concise/Console/ResultPrinter/DefaultResultPrinterTest.php +++ b/tests/Concise/Console/ResultPrinter/DefaultResultPrinterTest.php @@ -115,4 +115,17 @@ public function testSkippedItemsAreNotPrintedWhenVerboseIsTurnedOff() ->done(); $resultPrinter->add(PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED, $test, new Exception()); } + + public function testSkippedItemsArePrintedWhenVerboseIsTurnedOn() + { + $resultPrinter = $this->niceMock('Concise\Console\ResultPrinter\DefaultResultPrinter') + ->expect('appendTextAbove') + ->expose('add') + ->done(); + $resultPrinter->setVerbose(true); + $test = $this->niceMock('PHPUnit_Framework_TestCase') + ->stub(array('getName' => '')) + ->done(); + $resultPrinter->add(PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED, $test, new Exception()); + } } From 893889cdf8ee3d067dad0d581cec576438291e5e Mon Sep 17 00:00:00 2001 From: Elliot Chance Date: Sat, 13 Sep 2014 11:57:50 +1000 Subject: [PATCH 09/11] testVerbosePrintsIssues --- .../DefaultResultPrinterTest.php | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/tests/Concise/Console/ResultPrinter/DefaultResultPrinterTest.php b/tests/Concise/Console/ResultPrinter/DefaultResultPrinterTest.php index 64c2e870..e5d405ad 100644 --- a/tests/Concise/Console/ResultPrinter/DefaultResultPrinterTest.php +++ b/tests/Concise/Console/ResultPrinter/DefaultResultPrinterTest.php @@ -104,28 +104,30 @@ public function testEndWillUpdateProgress() $resultPrinter->end(); } - public function testSkippedItemsAreNotPrintedWhenVerboseIsTurnedOff() + public function verboseDataSet() { - $resultPrinter = $this->niceMock('Concise\Console\ResultPrinter\DefaultResultPrinter') - ->expect('appendTextAbove')->never() - ->expose('add') - ->done(); - $test = $this->niceMock('PHPUnit_Framework_TestCase') - ->stub(array('getName' => '')) - ->done(); - $resultPrinter->add(PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED, $test, new Exception()); + $show = 1; + $hide = 0; + + return array( + array(PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED, true, $show), + array(PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED, false, $hide), + ); } - public function testSkippedItemsArePrintedWhenVerboseIsTurnedOn() + /** + * @dataProvider verboseDataSet + */ + public function testVerbosePrintsIssues($status, $isVerbose, $willBePrinted) { $resultPrinter = $this->niceMock('Concise\Console\ResultPrinter\DefaultResultPrinter') - ->expect('appendTextAbove') + ->expect('appendTextAbove')->exactly($willBePrinted) ->expose('add') ->done(); - $resultPrinter->setVerbose(true); + $resultPrinter->setVerbose($isVerbose); $test = $this->niceMock('PHPUnit_Framework_TestCase') ->stub(array('getName' => '')) ->done(); - $resultPrinter->add(PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED, $test, new Exception()); + $resultPrinter->add($status, $test, new Exception()); } } From 74e3085cffcbd485190643c272d409e6f5059ba3 Mon Sep 17 00:00:00 2001 From: Elliot Chance Date: Sat, 13 Sep 2014 12:02:42 +1000 Subject: [PATCH 10/11] testVerbosePrintsIssues --- .../Console/ResultPrinter/DefaultResultPrinter.php | 10 ++++++++-- .../ResultPrinter/DefaultResultPrinterTest.php | 12 ++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Concise/Console/ResultPrinter/DefaultResultPrinter.php b/src/Concise/Console/ResultPrinter/DefaultResultPrinter.php index e9abbe3d..611bfc56 100644 --- a/src/Concise/Console/ResultPrinter/DefaultResultPrinter.php +++ b/src/Concise/Console/ResultPrinter/DefaultResultPrinter.php @@ -74,9 +74,15 @@ public function update() protected function add($status, PHPUnit_Framework_Test $test, Exception $e) { - if (!$this->isVerbose() && $status === PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED) { - return; + switch ($status) { + case PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED: + case PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE: + case PHPUnit_Runner_BaseTestRunner::STATUS_RISKY: + if (!$this->isVerbose()) { + return; + } } + $renderIssue = new RenderIssue(); $message = $renderIssue->render($status, $this->issueNumber, $test, $e); $this->appendTextAbove("$message\n\n"); diff --git a/tests/Concise/Console/ResultPrinter/DefaultResultPrinterTest.php b/tests/Concise/Console/ResultPrinter/DefaultResultPrinterTest.php index e5d405ad..3d860483 100644 --- a/tests/Concise/Console/ResultPrinter/DefaultResultPrinterTest.php +++ b/tests/Concise/Console/ResultPrinter/DefaultResultPrinterTest.php @@ -110,8 +110,16 @@ public function verboseDataSet() $hide = 0; return array( - array(PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED, true, $show), - array(PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED, false, $hide), + array(PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED, true, $show), + array(PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED, false, $hide), + array(PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE, true, $show), + array(PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE, false, $hide), + array(PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE, true, $show), + array(PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE, false, $show), + array(PHPUnit_Runner_BaseTestRunner::STATUS_ERROR, true, $show), + array(PHPUnit_Runner_BaseTestRunner::STATUS_ERROR, false, $show), + array(PHPUnit_Runner_BaseTestRunner::STATUS_RISKY, true, $show), + array(PHPUnit_Runner_BaseTestRunner::STATUS_RISKY, false, $hide), ); } From af17b4cc5038784d01fe5f1fbe5f67f9b490a3fa Mon Sep 17 00:00:00 2001 From: Elliot Chance Date: Sat, 13 Sep 2014 13:57:07 +1000 Subject: [PATCH 11/11] Remove dead code --- src/Concise/Console/ResultPrinter/ResultPrinterProxy.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Concise/Console/ResultPrinter/ResultPrinterProxy.php b/src/Concise/Console/ResultPrinter/ResultPrinterProxy.php index db51ba63..ed8a4d27 100644 --- a/src/Concise/Console/ResultPrinter/ResultPrinterProxy.php +++ b/src/Concise/Console/ResultPrinter/ResultPrinterProxy.php @@ -19,14 +19,10 @@ class ResultPrinterProxy extends \PHPUnit_TextUI_ResultPrinter protected $totalSuccesses = 0; - public function __construct(TestResultDelegateInterface $resultPrinter = null) + public function __construct(TestResultDelegateInterface $resultPrinter) { parent::__construct(); - if ($resultPrinter) { - $this->resultPrinter = $resultPrinter; - } else { - $this->resultPrinter = new DefaultResultPrinter(); - } + $this->resultPrinter = $resultPrinter; } public function getResultPrinter()