Skip to content
Extraits de code Groupes Projets
Valider 2b641d3c rédigé par diosmosis's avatar diosmosis
Parcourir les fichiers

Add small base test case class for testing console commands.

parent 3b21c5df
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
<?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;
use Piwik\Config;
use Piwik\Console;
use Symfony\Component\Console\Tester\ApplicationTester;
/**
* Base class for test cases that test Piwik console commands. Derives from IntegrationTestCase
* so the entire Piwik environment is set up.
*
* This will create an ApplicationTester instance (provided by Symfony) which should be used to
* test commands like this:
*
* public function testThisAndThat()
* {
* $result = $this->applicationTester->run(array(
* 'command' => 'my-command',
* 'arg1' => 'value1',
* 'arg2' => 'value2',
* '--option' => true,
* '--another-option' => 'value3'
* ));
* $this->assertEquals(0, $result, $this->getCommandDisplayOutputErrorMessage());
*
* // other checks
* }
*/
class ConsoleCommandTestCase extends \IntegrationTestCase
{
protected $applicationTester = null;
public function setUp()
{
parent::setUp();
$application = new Console();
$application->setAutoExit(false);
$this->applicationTester = new ApplicationTester($application);
Config::unsetInstance();
}
protected function getCommandDisplayOutputErrorMessage()
{
return "Command did not behave as expected. Command output: " . $this->applicationTester->getDisplay();
}
}
\ No newline at end of file
...@@ -34,6 +34,7 @@ require_once PIWIK_INCLUDE_PATH . '/core/Loader.php'; ...@@ -34,6 +34,7 @@ require_once PIWIK_INCLUDE_PATH . '/core/Loader.php';
require_once PIWIK_INCLUDE_PATH . '/core/FrontController.php'; require_once PIWIK_INCLUDE_PATH . '/core/FrontController.php';
require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/DatabaseTestCase.php'; require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/DatabaseTestCase.php';
require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/IntegrationTestCase.php'; require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/IntegrationTestCase.php';
require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/ConsoleCommandTestCase.php';
require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/FakeAccess.php'; require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/FakeAccess.php';
require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/MockPiwikOption.php'; require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/MockPiwikOption.php';
require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/TestingEnvironment.php'; require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/TestingEnvironment.php';
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter