added command to show plugin versions (#994)
This commit is contained in:
75
src/Command/PluginCommand.php
Normal file
75
src/Command/PluginCommand.php
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Kimai time-tracking app.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Command;
|
||||||
|
|
||||||
|
use App\Plugin\PluginManager;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Command used to fetch plugin information.
|
||||||
|
*/
|
||||||
|
class PluginCommand extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var PluginManager
|
||||||
|
*/
|
||||||
|
private $plugins;
|
||||||
|
|
||||||
|
public function __construct(PluginManager $plugins)
|
||||||
|
{
|
||||||
|
$this->plugins = $plugins;
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
$this
|
||||||
|
->setName('kimai:plugins')
|
||||||
|
->setDescription('Receive plugin information')
|
||||||
|
->setHelp('This command prints detailed plugin information.')
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
$io = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
|
$plugins = $this->plugins->getPlugins();
|
||||||
|
if (empty($plugins)) {
|
||||||
|
$io->warning('No plugins installed');
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$rows = [];
|
||||||
|
foreach ($plugins as $plugin) {
|
||||||
|
$this->plugins->loadMetadata($plugin);
|
||||||
|
$meta = $plugin->getMetadata();
|
||||||
|
$rows[] = [
|
||||||
|
$plugin->getName(),
|
||||||
|
$meta->getVersion(),
|
||||||
|
$meta->getKimaiVersion(),
|
||||||
|
$plugin->getPath(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$io->table(['Name', 'Version', 'Requires', 'Directory'], $rows);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -80,7 +80,7 @@ class PluginManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call this method and pass a plugin, to set its metdata.
|
* Call this method and pass a plugin, to set its metadata.
|
||||||
* This is not pre-filled by default, as it would mean to parse several composer.json on each request.
|
* This is not pre-filled by default, as it would mean to parse several composer.json on each request.
|
||||||
*
|
*
|
||||||
* @param Plugin $plugin
|
* @param Plugin $plugin
|
||||||
|
|||||||
61
tests/Command/PluginCommandTest.php
Normal file
61
tests/Command/PluginCommandTest.php
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Kimai time-tracking app.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Tests\Command;
|
||||||
|
|
||||||
|
use App\Command\PluginCommand;
|
||||||
|
use App\Plugin\PluginInterface;
|
||||||
|
use App\Plugin\PluginManager;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \App\Command\PluginCommand
|
||||||
|
* @group integration
|
||||||
|
*/
|
||||||
|
class PluginCommandTest extends KernelTestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Application
|
||||||
|
*/
|
||||||
|
protected $application;
|
||||||
|
|
||||||
|
public function testWithPlugins()
|
||||||
|
{
|
||||||
|
$plugin1 = $this->getMockBuilder(PluginInterface::class)->setMethods(['getName', 'getPath'])->getMock();
|
||||||
|
$plugin1->expects($this->exactly(3))->method('getName')->willReturn('Test-Bundle');
|
||||||
|
$plugin1->expects($this->once())->method('getPath')->willReturn(__DIR__);
|
||||||
|
|
||||||
|
$plugin2 = $this->getMockBuilder(PluginInterface::class)->setMethods(['getName', 'getPath'])->getMock();
|
||||||
|
$plugin2->expects($this->exactly(3))->method('getName')->willReturn('Another one');
|
||||||
|
$plugin2->expects($this->once())->method('getPath')->willReturn('BundleDirectory');
|
||||||
|
|
||||||
|
$commandTester = $this->getCommandTester([$plugin1, $plugin2], []);
|
||||||
|
$output = $commandTester->getDisplay();
|
||||||
|
$this->assertContains(__DIR__, $output);
|
||||||
|
$this->assertContains('BundleDirectory', $output);
|
||||||
|
$this->assertContains('Test-Bundle', $output);
|
||||||
|
$this->assertContains('Another one', $output);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getCommandTester(array $plugins, array $options = [])
|
||||||
|
{
|
||||||
|
$kernel = self::bootKernel();
|
||||||
|
$this->application = new Application($kernel);
|
||||||
|
$this->application->add(new PluginCommand(new PluginManager($plugins)));
|
||||||
|
|
||||||
|
$command = $this->application->find('kimai:plugins');
|
||||||
|
$commandTester = new CommandTester($command);
|
||||||
|
$inputs = array_merge(['command' => $command->getName()], $options);
|
||||||
|
$commandTester->execute($inputs);
|
||||||
|
|
||||||
|
return $commandTester;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user