Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiosmosis <diosmosis@users.noreply.github.com>2018-08-11 11:13:55 +0300
committerMatthieu Aubry <mattab@users.noreply.github.com>2018-08-11 11:13:55 +0300
commit2d7896c3df5540bc109e89782880c0780a6b7bc2 (patch)
tree75584e348745db16b22a4d74f99c9d7c259f0af0 /tests/PHPUnit
parentbc33259f6b6fc730826eceeb2a029eef63e97fc0 (diff)
If warning/error log detected in console command exit w/ code = 1. (#13275)
Diffstat (limited to 'tests/PHPUnit')
-rw-r--r--tests/PHPUnit/System/ConsoleTest.php100
1 files changed, 100 insertions, 0 deletions
diff --git a/tests/PHPUnit/System/ConsoleTest.php b/tests/PHPUnit/System/ConsoleTest.php
new file mode 100644
index 0000000000..ad45405718
--- /dev/null
+++ b/tests/PHPUnit/System/ConsoleTest.php
@@ -0,0 +1,100 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ */
+
+namespace Piwik\Tests\System;
+
+use Piwik\Container\StaticContainer;
+use Piwik\Plugin\ConsoleCommand;
+use Piwik\Plugins\Monolog\Handler\FailureLogMessageDetector;
+use Psr\Log\LoggerInterface;
+use Monolog\Logger;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+use Piwik\Tests\Framework\TestCase\ConsoleCommandTestCase;
+
+class TestCommandWithWarning extends ConsoleCommand
+{
+ public function configure()
+ {
+ parent::configure();
+
+ $this->setName('test-command-with-warning');
+ }
+
+ public function execute(InputInterface $input, OutputInterface $output)
+ {
+ StaticContainer::get(LoggerInterface::class)->warning('warn');
+ }
+}
+
+class TestCommandWithError extends ConsoleCommand
+{
+ public function configure()
+ {
+ parent::configure();
+
+ $this->setName('test-command-with-error');
+ $this->addOption('no-error', null, InputOption::VALUE_NONE);
+ }
+
+ public function execute(InputInterface $input, OutputInterface $output)
+ {
+ if (!$input->getOption('no-error')) {
+ StaticContainer::get(LoggerInterface::class)->error('error');
+ }
+ }
+}
+
+class ConsoleTest extends ConsoleCommandTestCase
+{
+ public function setUp()
+ {
+ parent::setUp();
+ $this->application->addCommands([
+ new TestCommandWithWarning(),
+ new TestCommandWithError(),
+ ]);
+
+ StaticContainer::get(FailureLogMessageDetector::class)->reset();
+ }
+
+ public function test_Console_ReturnsCorrectExitCode_IfCommandEmitsWarning()
+ {
+ $exitCode = $this->applicationTester->run([
+ 'command' => 'test-command-with-warning',
+ ]);
+ $this->assertEquals(1, $exitCode);
+ }
+
+ public function test_Console_ReturnsCorrectExitCode_IfCommandEmitsError()
+ {
+ $exitCode = $this->applicationTester->run([
+ 'command' => 'test-command-with-error',
+ ]);
+ $this->assertEquals(1, $exitCode);
+ }
+
+ public function test_Console_ReturnsCorrectExitCode_IfCommandDoesNotEmitAnything()
+ {
+ $exitCode = $this->applicationTester->run([
+ 'command' => 'test-command-with-error',
+ '--no-error' => true,
+ ]);
+ $this->assertEquals(0, $exitCode);
+ }
+
+ public static function provideContainerConfigBeforeClass()
+ {
+ return [
+ 'log.handlers' => [\DI\get(FailureLogMessageDetector::class)],
+ LoggerInterface::class => \DI\object(Logger::class)
+ ->constructor('piwik', \DI\get('log.handlers'), \DI\get('log.processors')),
+ ];
+ }
+} \ No newline at end of file