Skip to content

Commit

Permalink
refs matomo-org#4121 added simple command line tool including a not y…
Browse files Browse the repository at this point in the history
…et working tests and generatePlugin command
  • Loading branch information
tsteur committed Oct 3, 2013
1 parent a703355 commit 6922014
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 1 deletion.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"require": {
"php": ">=5.3.0",
"twig/twig": "1.*",
"leafo/lessphp": "0.3.*"
"leafo/lessphp": "0.3.*",
"symfony/console": ">=v2.3.5"
}
}
11 changes: 11 additions & 0 deletions console
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env php
<?php
define('PIWIK_DOCUMENT_ROOT', dirname(__FILE__) == '/' ? '' : dirname(__FILE__));
define('PIWIK_INCLUDE_PATH', PIWIK_DOCUMENT_ROOT);
define('PIWIK_USER_PATH', PIWIK_DOCUMENT_ROOT);

require_once PIWIK_INCLUDE_PATH . '/vendor/autoload.php';
require_once PIWIK_INCLUDE_PATH . '/core/Loader.php';

$console = new Piwik\Console();
$console->run();
28 changes: 28 additions & 0 deletions core/Console.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @category Piwik
* @package Piwik
*/
namespace Piwik;

use Piwik\Plugins\CoreConsole\GeneratePlugin;
use Piwik\Plugins\CoreConsole\RunTests;
use Symfony\Component\Console\Application;

class Console
{
public function run()
{
$console = new Application();

$console->add(new RunTests());
$console->add(new GeneratePlugin());

$console->run();
}
}
17 changes: 17 additions & 0 deletions core/Console/Command.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @category Piwik
* @package Piwik
*/
namespace Piwik\Console;

use Symfony\Component\Console\Command\Command as SymfonyCommand;

class Command extends SymfonyCommand
{
}
43 changes: 43 additions & 0 deletions plugins/CoreConsole/GeneratePlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @category Piwik_Plugins
* @package CoreConsole
*/

namespace Piwik\Plugins\CoreConsole;

use Piwik\Console\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;

/**
* @package CoreConsole
*/
class GeneratePlugin extends Command
{
protected function configure()
{
$this->setName('generate:plugin');
$this->setDescription('Generates a new plugin including all needed files');
$this->setDefinition(array(
new InputArgument('name', InputArgument::REQUIRED, 'Plugin name ([a-Z0-9_-])'),
new InputArgument('version', InputArgument::REQUIRED, 'Plugin version'),
new InputArgument('description', InputArgument::REQUIRED, 'Plugin description, max 150 characters.')
));
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$pluginName = $input->getArgument('name');
$version = $input->getArgument('version');
$description = $input->getArgument('description');

$output->writeln(sprintf('Dir listing for <info>%s</info>', $pluginName));
}
}
40 changes: 40 additions & 0 deletions plugins/CoreConsole/RunTests.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @category Piwik_Plugins
* @package CoreConsole
*/

namespace Piwik\Plugins\CoreConsole;

use Piwik\Console\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;

/**
* @package CoreConsole
*/
class RunTests extends Command
{
protected function configure()
{
$this->setName('tests');
$this->setDescription('Run Piwik PHPUnit tests');
$this->addArgument('options', InputArgument::OPTIONAL, 'All options will be forwarded to phpunit', '');
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$options = $input->getArgument('options');
echo '' . $options;return;
$cmd = sprintf('cd %s/tests/PHPUnit && phpunit %s', PIWIK_DOCUMENT_ROOT, $options);

$output->writeln('Executing command: ' . $cmd);
passthru($cmd);
}
}

0 comments on commit 6922014

Please sign in to comment.