Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Console] Add command for showing available Sylius plugins #10004

Merged
merged 4 commits into from
Dec 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions features/cli/showing_available_plugins.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@showing_available_plugins @cli
Feature: Showing available Sylius plugins
In order to be aware of available plugins
As a Developer
I want to be informed about available plugins

Scenario: Showing available Sylius plugins
When I run show available plugins command
Then I should see output "Available official Sylius Plugins" with listed plugins
69 changes: 69 additions & 0 deletions src/Sylius/Behat/Context/Cli/ShowingAvailablePluginsContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Behat\Context\Cli;

use Behat\Behat\Context\Context;
use Sylius\Bundle\CoreBundle\Command\SetupCommand;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\HttpKernel\KernelInterface;
use Webmozart\Assert\Assert;

final class ShowingAvailablePluginsContext implements Context
{
/** @var KernelInterface */
private $kernel;

/** @var Application */
private $application;

/** @var CommandTester */
private $tester;

/** @var SetupCommand */
private $command;

public function __construct(KernelInterface $kernel)
{
$this->kernel = $kernel;
}

/**
* @When I run show available plugins command
*/
public function runShowAvailablePluginsCommand(): void
{
$this->application = new Application($this->kernel);
$this->application->add(new SetupCommand());

$this->command = $this->application->find('sylius:show-available-plugins');
$this->tester = new CommandTester($this->command);

$this->tester->execute(['command' => 'sylius:show-available-plugins']);
}

/**
* @Then I should see output :output with listed plugins
*/
public function shouldSeeOutputWithListedPlugins(string $output): void
{
Assert::contains($this->tester->getDisplay(), $output);
Assert::contains($this->tester->getDisplay(), 'Admin Order Creation');
Assert::contains($this->tester->getDisplay(), 'Customer Order Cancellation');
Assert::contains($this->tester->getDisplay(), 'Customer Reorder');
Assert::contains($this->tester->getDisplay(), 'Invoicing');
Assert::contains($this->tester->getDisplay(), 'RBAC');
Assert::contains($this->tester->getDisplay(), 'Refund');
}
}
5 changes: 5 additions & 0 deletions src/Sylius/Behat/Resources/config/services/contexts/cli.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
<services>
<defaults public="true" />

<service id="Sylius\Behat\Context\Cli\ShowingAvailablePluginsContext">
<argument type="service" id="__symfony__.kernel" />
<tag name="fob.context_service" />
</service>

<service id="sylius.behat.context.cli.installer" class="Sylius\Behat\Context\Cli\InstallerContext">
<argument type="service" id="__symfony__.kernel" />
<tag name="fob.context_service" />
Expand Down
1 change: 1 addition & 0 deletions src/Sylius/Behat/Resources/config/suites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ imports:
- suites/api/product/managing_product_variants.yml

- suites/cli/installer.yml
- suites/cli/showing_available_plugins.yml

- suites/domain/cart/shopping_cart.yml
- suites/domain/order/managing_orders.yml
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file is part of the Sylius package.
# (c) Paweł Jędrzejewski

default:
suites:
cli_showing_available_plugins:
contexts_services:
- Sylius\Behat\Context\Cli\ShowingAvailablePluginsContext

filters:
tags: "@showing_available_plugins && @cli"
39 changes: 39 additions & 0 deletions src/Sylius/Bundle/CoreBundle/Command/Model/PluginInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace Sylius\Bundle\CoreBundle\Command\Model;

final class PluginInfo
{
/** @var string */
private $name;

/** @var string */
private $description;

/** @var string */
private $url;

public function __construct(string $name, string $description, string $url)
{
$this->name = $name;
$this->description = $description;
$this->url = $url;
}

public function name(): string
{
return $this->name;
}

public function description(): string
{
return $this->description;
}

public function url(): string
{
return $this->url;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Bundle\CoreBundle\Command;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Sylius\Bundle\CoreBundle\Command\Model\PluginInfo;
use Sylius\Bundle\CoreBundle\Installer\Renderer\TableRenderer;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

final class ShowAvailablePluginsCommand extends Command
{
/** @var Collection|PluginInfo[] */
private $plugins;

protected function configure(): void
{
$this->setName('sylius:show-available-plugins');
$this->setDescription('Shows official Sylius Plugins');
$this->configurePlugins();
}

protected function execute(InputInterface $input, OutputInterface $output): void
{
$output->writeln('<comment>Available official Sylius Plugins:</comment>');

$pluginTable = new TableRenderer($output);
$pluginTable->setHeaders(['Plugin', 'Description', 'URL']);

foreach ($this->plugins as $plugin) {
$pluginTable->addRow([sprintf('<info>%s</info>', $plugin->name()), $plugin->description(), $plugin->url()]);
}

$pluginTable->render();
}

private function configurePlugins(): void
{
$this->plugins = new ArrayCollection();

/** @var PluginInfo[] */
$this->plugins->add(new PluginInfo('<info>Admin Order Creation</info>', 'Creating (and copying) orders in the administration panel.', 'https://github.com/Sylius/AdminOrderCreationPlugin'));
$this->plugins->add(new PluginInfo('<info>Customer Order Cancellation</info>', 'Allows customers to quickly cancel their unpaid and unshipped orders.', 'https://github.com/Sylius/CustomerOrderCancellationPlugin'));
$this->plugins->add(new PluginInfo('<info>Customer Reorder</info>', 'Convenient reordering for the customers from the `My account` section.', 'https://github.com/Sylius/CustomerReorderPlugin'));
$this->plugins->add(new PluginInfo('<info>Invoicing</info>', 'Automatised, basic invoicing system for orders.', 'https://github.com/Sylius/InvoicingPlugin'));
$this->plugins->add(new PluginInfo('<info>RBAC</info>', 'Permissions management for the administration panel.', 'https://github.com/Sylius/RBACPlugin'));
$this->plugins->add(new PluginInfo('<info>Refund</info>', 'Full and partial refunds of items and/or shipping costs including Credit Memos.', 'https://github.com/Sylius/RefundPlugin'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,9 @@
<service id="Sylius\Bundle\CoreBundle\Command\SetupCommand">
<tag name="console.command" />
</service>

<service id="Sylius\Bundle\CoreBundle\Command\ShowAvailablePluginsCommand">
<tag name="console.command" />
</service>
</services>
</container>
34 changes: 34 additions & 0 deletions src/Sylius/Bundle/CoreBundle/spec/Command/Model/PluginInfoSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace spec\Sylius\Bundle\CoreBundle\Command\Model;

use PhpSpec\ObjectBehavior;

final class PluginInfoSpec extends ObjectBehavior
{
function let(): void
{
$this->beConstructedWith(
'Admin Order Creation',
'Creating (and copying) orders in the administration panel.',
'https://github.com/Sylius/AdminOrderCreationPlugin'
);
}

function it_has_a_name(): void
{
$this->name()->shouldBeLike('Admin Order Creation');
}

function it_has_a_description(): void
{
$this->description()->shouldBeLike('Creating (and copying) orders in the administration panel.');
}

function it_has_a_url(): void
{
$this->url()->shouldBeLike('https://github.com/Sylius/AdminOrderCreationPlugin');
}
}