Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Arminek committed Mar 10, 2016
1 parent d5a1519 commit e264853
Show file tree
Hide file tree
Showing 22 changed files with 227 additions and 180 deletions.
6 changes: 3 additions & 3 deletions etc/behat/services/contexts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<parameter key="sylius.behat.context.ui.paypal.class">Sylius\Behat\Context\Ui\PaypalContext</parameter>
<parameter key="sylius.behat.context.ui.customer.class">Sylius\Behat\Context\Ui\CustomerContext</parameter>
<parameter key="sylius.behat.context.ui.theme.class">Sylius\Behat\Context\Ui\ThemeContext</parameter>
<parameter key="sylius.behat.context.ui.admin.managing_country_context.class">Sylius\Behat\Context\Ui\Admin\ManagingCountryContext</parameter>
<parameter key="sylius.behat.context.ui.admin.managing_country.class">Sylius\Behat\Context\Ui\Admin\ManagingCountryContext</parameter>

<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>
Expand Down Expand Up @@ -194,6 +194,7 @@
<service id="sylius.behat.context.transform.addressing" class="%sylius.behat.context.transform.addressing.class%" scope="scenario">
<argument type="service" id="sylius.factory.address" container="symfony" />
<argument type="service" id="sylius.converter.country_name" container="symfony" />
<argument type="service" id="sylius.repository.country" container="symfony" />
<tag name="sylius.behat.context" />
</service>

Expand Down Expand Up @@ -314,8 +315,7 @@
<tag name="sylius.behat.context" />
</service>

<service id="sylius.behat.context.ui.admin.managing_country_context" class="%sylius.behat.context.ui.admin.managing_country_context.class%" scope="scenario">
<argument type="service" id="sylius.behat.shared_storage" container="symfony" />
<service id="sylius.behat.context.ui.admin.managing_country" class="%sylius.behat.context.ui.admin.managing_country.class%" scope="scenario">
<argument type="service" id="sylius.behat.page.admin.country.index" />
<argument type="service" id="sylius.behat.page.admin.country.create" />
<tag name="sylius.behat.context" />
Expand Down
6 changes: 4 additions & 2 deletions etc/behat/suites/ui_addressing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ default:
ui_addressing:
contexts_as_services:
- sylius.behat.context.hook.doctrine_orm
- sylius.behat.context.transform.lexical

- sylius.behat.context.transform.addressing

- sylius.behat.context.setup.security

- sylius.behat.context.ui.admin.managing_country_context
- sylius.behat.context.ui.admin.managing_country
filters:
tags: @addressing && @ui
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ Feature: Adding country
Given I am logged in as administrator

@ui
Scenario: Adding new country
Scenario: Adding country
Given I want to create new country
When I name it "France"
When I choose "France"
And I add it
Then I should be notified about success
And this country should appear in the store
And country with name "France" should appear in the store
29 changes: 27 additions & 2 deletions src/Sylius/Behat/Context/Transform/AddressingContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,24 @@ final class AddressingContext implements Context
*/
private $countryNameConverter;

/**
* @var RepositoryInterface
*/
private $countryRepository;

/**
* @param FactoryInterface $addressFactory
* @param CountryNameConverterInterface $countryNameConverter
* @param RepositoryInterface $countryRepository
*/
public function __construct(FactoryInterface $addressFactory, CountryNameConverterInterface $countryNameConverter)
{
public function __construct(
FactoryInterface $addressFactory,
CountryNameConverterInterface $countryNameConverter,
RepositoryInterface $countryRepository
) {
$this->addressFactory = $addressFactory;
$this->countryNameConverter = $countryNameConverter;
$this->countryRepository = $countryRepository;
}

/**
Expand All @@ -53,6 +63,21 @@ public function createNewAddress($countryName)
return $this->createAddress($countryCode);
}

/**
* @Transform /^country with name "([^"]+)"$/
*/
public function getCountryByName($countryName)
{
$countryCode = $this->countryNameConverter->convertToCode($countryName);
$country = $this->countryRepository->findOneBy(['code' => $countryCode]);

if (null === $country) {
throw new \InvalidArgumentException(sprintf('Country with name %s does not exist', $countryName));
}

return $country;
}

/**
* @param string $countryCode
* @param string $firstName
Expand Down
52 changes: 23 additions & 29 deletions src/Sylius/Behat/Context/Ui/Admin/ManagingCountryContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,81 +12,75 @@
namespace Sylius\Behat\Context\Ui\Admin;

use Behat\Behat\Context\Context;
use Sylius\Behat\Page\Admin\Crud\CreatePageInterface;
use Sylius\Behat\Page\Admin\Country\CreatePageInterface;
use Sylius\Behat\Page\Admin\Crud\IndexPageInterface;
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
use Sylius\Component\Addressing\Model\CountryInterface;

/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
class ManagingCountryContext implements Context
final class ManagingCountryContext implements Context
{
/**
* @var SharedStorageInterface
*/
private $sharedStorage;

/**
* @var IndexPageInterface
*/
private $adminCountryIndexPage;
private $countryIndexPage;

/**
* @var CreatePageInterface
*/
private $adminCountryCreatePage;
private $countryCreatePage;

/**
* @param SharedStorageInterface $sharedStorage
* @param IndexPageInterface $adminCountryIndexPage
* @param CreatePageInterface $adminCountryCreatePage
* @param IndexPageInterface $countryIndexPage
* @param CreatePageInterface $countryCreatePage
*/
public function __construct(SharedStorageInterface $sharedStorage, IndexPageInterface $adminCountryIndexPage, CreatePageInterface $adminCountryCreatePage)
{
$this->sharedStorage = $sharedStorage;
$this->adminCountryIndexPage = $adminCountryIndexPage;
$this->adminCountryCreatePage = $adminCountryCreatePage;
public function __construct(
IndexPageInterface $countryIndexPage,
CreatePageInterface $countryCreatePage
) {
$this->countryIndexPage = $countryIndexPage;
$this->countryCreatePage = $countryCreatePage;
}

/**
* @Given I want to create new country
*/
public function iWantToCreateNewCountry()
{
$this->adminCountryCreatePage->open();
$this->countryCreatePage->open();
}

/**
* @When I name it :name
* @When /^I choose "([^"]*)"$/
*/
public function iNameIt($name)
public function iChoose($name)
{
$this->sharedStorage->set('countryName', $name);
$this->adminCountryCreatePage->fillName($name);
$this->countryCreatePage->chooseName($name);
}

/**
* @When I add it
*/
public function iAddIt()
{
$this->adminCountryCreatePage->create();
$this->countryCreatePage->create();
}

/**
* @Then I should be notified about success
*/
public function iShouldBeNotifiedAboutSuccess()
{
expect($this->adminCountryIndexPage->isSuccessfulMessage())->toBe(true);
expect($this->adminCountryIndexPage->isSuccessfullyCreated())->toBe(true);
expect($this->countryIndexPage->hasSuccessMessage())->toBe(true);
expect($this->countryIndexPage->isSuccessfullyCreated())->toBe(true);
}

/**
* @Then this country should appear in the store
* @Given /^(country with name "([^"]*)") should appear in the store$/
*/
public function thisCountryShouldAppearInTheStore()
public function countryWithNameShouldAppearInTheStore(CountryInterface $country)
{
expect($this->adminCountryIndexPage->isResourceAppearInTheStoreBy(['name' => $this->sharedStorage->get('countryName')]))->toBe(true);
expect($this->countryIndexPage->isResourceOnPage(['code' => $country->getCode()]))->toBe(true);
}
}
4 changes: 2 additions & 2 deletions src/Sylius/Behat/Page/Admin/Country/CreatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
class CreatePage extends BaseCreatePage
class CreatePage extends BaseCreatePage implements CreatePageInterface
{
/**
* {@inheritdoc}
*/
public function fillName($name)
public function chooseName($name)
{
$this->getDocument()->selectFieldOption('Name', $name);
}
Expand Down
28 changes: 28 additions & 0 deletions src/Sylius/Behat/Page/Admin/Country/CreatePageInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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.
*/

namespace Sylius\Behat\Page\Admin\Country;

use Behat\Mink\Exception\ElementNotFoundException;
use Sylius\Behat\Page\Admin\Crud\CreatePageInterface as BaseCreatePageInterface;

/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
interface CreatePageInterface extends BaseCreatePageInterface
{
/**
* @param string $name
*
* @throws ElementNotFoundException
*/
public function chooseName($name);
}
10 changes: 1 addition & 9 deletions src/Sylius/Behat/Page/Admin/Crud/CreatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ public function __construct(Session $session, array $parameters, RouterInterface
$this->resourceName = $resourceName;
}

/**
* {@inheritdoc}
*/
public function fillName($name)
{
$this->getDocument()->fillField('Name', $name);
}

/**
* {@inheritdoc}
*/
Expand All @@ -55,7 +47,7 @@ public function create()
}

/**
* @return string
* {@inheritdoc}
*/
protected function getRouteName()
{
Expand Down
7 changes: 0 additions & 7 deletions src/Sylius/Behat/Page/Admin/Crud/CreatePageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@
*/
interface CreatePageInterface extends PageInterface
{
/**
* @param string $name
*
* @throws ElementNotFoundException
*/
public function fillName($name);

/**
* @throws ElementNotFoundException
*/
Expand Down
12 changes: 3 additions & 9 deletions src/Sylius/Behat/Page/Admin/Crud/EditPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,9 @@ class EditPage extends SymfonyPage implements EditPageInterface
*/
public function __construct(Session $session, array $parameters, RouterInterface $router, $resourceName)
{
$this->resourceName = $resourceName;
}
parent::__construct($session, $parameters, $router);

/**
* {@inheritdoc}
*/
public function fillName($name)
{
$this->getDocument()->fillField('Name', $name);
$this->resourceName = $resourceName;
}

/**
Expand All @@ -53,7 +47,7 @@ public function saveChanges()
}

/**
* @return string
* {@inheritdoc}
*/
protected function getRouteName()
{
Expand Down
7 changes: 0 additions & 7 deletions src/Sylius/Behat/Page/Admin/Crud/EditPageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@
*/
interface EditPageInterface extends PageInterface
{
/**
* @param string $name
*
* @throws ElementNotFoundException
*/
public function fillName($name);

/**
* @throws ElementNotFoundException
*/
Expand Down
Loading

0 comments on commit e264853

Please sign in to comment.