Setting default channel and transfer to new Behats

This commit is contained in:
Magdalena Banasiak 2016-02-22 11:49:00 +01:00
parent 4da28dfe97
commit c138004032
7 changed files with 69 additions and 12 deletions

View file

@ -53,6 +53,8 @@
<parameter key="sylius.behat.context.domain.order.class">Sylius\Behat\Context\Domain\OrderContext</parameter>
<parameter key="sylius.behat.context.domain.payment.class">Sylius\Behat\Context\Domain\PaymentContext</parameter>
<parameter key="sylius.behat.context.domain.shipment.class">Sylius\Behat\Context\Domain\ShippingContext</parameter>
<parameter key="sylius.behat.context.cli.installer.class">Sylius\Behat\Context\Cli\InstallerContext</parameter>
</parameters>
<services>
<service id="sylius.behat.context.setup.channel" class="%sylius.behat.context.setup.channel.class%" scope="scenario">
@ -310,5 +312,10 @@
<argument type="service" id="sylius.repository.shipment" container="symfony"/>
<tag name="sylius.behat.context" />
</service>
<service id="sylius.behat.context.cli.installer" class="%sylius.behat.context.cli.installer.class%" scope="scenario">
<argument type="service" id="kernel" container="symfony" />
<tag name="sylius.behat.context" />
</service>
</services>
</container>

View file

@ -39,3 +39,5 @@ imports:
- suites/ui_user.yml
- suites/domain_order.yml
- suites/cli_installer.yml

View file

@ -0,0 +1,13 @@
# This file is part of the Sylius package.
# (c) Paweł Jędrzejewski
default:
suites:
cli_installer:
contexts_as_services:
- sylius.behat.context.hook.doctrine_orm
- sylius.behat.context.cli.installer
filters:
tags: @installer && @cli

View file

@ -1,4 +1,4 @@
@cli
@installer @cli
Feature: Sylius Install Feature
In order to install Sylius via CLI
As a Developer
@ -6,7 +6,7 @@ Feature: Sylius Install Feature
Scenario: Running install setup command
When I run Sylius CLI installer
Then I should see output "Please enter a currency code (For example "GBP") or press ENTER to use "USD"."
Then I should see output "Please enter a currency code"
And I should see output "In which currency can your customers buy goods?"
Scenario: Choosing default currency

View file

@ -9,20 +9,26 @@
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\InstallerBundle\Behat;
namespace Sylius\Behat\Context\Cli;
use Behat\Behat\Context\Context;
use Sylius\Bundle\InstallerBundle\Command\SetupCommand;
use Sylius\Bundle\ResourceBundle\Behat\DefaultContext;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Helper\DialogHelper;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpKernel\KernelInterface;
/**
* @author Magdalena Banasiak <magdalena.banasiak@lakion.com>
*/
class CliContext extends DefaultContext
final class InstallerContext implements Context
{
/**
* @var KernelInterface
*/
private $kernel;
/**
* @var Application
*/
@ -55,12 +61,20 @@ class CliContext extends DefaultContext
'confirmation' => ' pswd',
);
/**
* @param KernelInterface $kernel
*/
public function __construct(KernelInterface $kernel)
{
$this->kernel = $kernel;
}
/**
* @When I run Sylius CLI installer
*/
public function iRunSyliusCommandLineInstaller()
{
$this->application = new Application($this->getKernel());
$this->application = new Application($this->kernel);
$this->application->add(new SetupCommand());
$this->command = $this->application->find('sylius:install:setup');
@ -70,7 +84,7 @@ class CliContext extends DefaultContext
}
/**
* @Then /^I should see output "(.+)"$/
* @Then I should see output :text
*/
public function iShouldSeeOutput($text)
{

View file

@ -49,6 +49,7 @@ EOT
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->setupCurrency($input, $output);
$this->setupChannel();
$this->setupAdministratorUser($input, $output);
}
@ -137,18 +138,17 @@ EOT
$name = Intl::getCurrencyBundle()->getCurrencyName($code);
$output->writeln(sprintf('Adding <info>%s</info>', $name));
if (null !== $existingCurrency = $currencyRepository->findOneByCode($code)) {
if (null !== $existingCurrency = $currencyRepository->findOneBy(['code' => $code])) {
$this->currency = $existingCurrency;
return;
}
$currency = $currencyFactory->createNew();
$currency->setExchangeRate(1);
$currency->setBase(true);
$currency->setCode($code);
$currency->setExchangeRate(1);
$this->currency = $currency;
@ -156,6 +156,27 @@ EOT
$currencyManager->flush();
}
protected function setupChannel()
{
$channelRepository = $this->get('sylius.repository.channel');
$channelManager = $this->get('sylius.manager.channel');
$channelFactory = $this->get('sylius.factory.channel');
$channel = $channelRepository->findOneByCode('DEFAULT');
if (null !== $channel) {
return;
}
$channel = $channelFactory->createNew();
$channel->setCode('DEFAULT');
$channel->setName('DEFAULT');
$channel->setDefaultCurrency($this->currency);
$channelManager->persist($channel);
$channelManager->flush();
}
/**
* @param InputInterface $input
* @param OutputInterface $output