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

How to add your custom fixtures? #23

Closed
wants to merge 19 commits into from
Closed
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
38 changes: 38 additions & 0 deletions behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,40 @@ default:
paths: false
snippets: false

suites:
ui_managing_shipping_methods:
contexts:
- sylius.behat.context.hook.doctrine_orm

- sylius.behat.context.transform.address
- sylius.behat.context.transform.channel
- sylius.behat.context.transform.currency
- sylius.behat.context.transform.customer
- sylius.behat.context.transform.locale
- sylius.behat.context.transform.payment
- sylius.behat.context.transform.product
- sylius.behat.context.transform.shared_storage
- sylius.behat.context.transform.shipping_method

- sylius.behat.context.setup.channel
- sylius.behat.context.setup.currency
- sylius.behat.context.setup.locale
- sylius.behat.context.setup.order
- sylius.behat.context.setup.payment
- sylius.behat.context.setup.product
- sylius.behat.context.setup.admin_security
- sylius.behat.context.setup.shipping
- sylius.behat.context.setup.user
- sylius.behat.context.setup.zone

- app.behat.context.ui.admin.managing_shipping_methods
- sylius.behat.context.ui.admin.managing_shipping_methods
- sylius.behat.context.ui.admin.notification
- sylius.behat.context.ui.shop.locale

filters:
tags: "@managing_shipping_methods && @ui"

extensions:
Lakion\Behat\MinkDebugExtension:
directory: etc/build
Expand Down Expand Up @@ -42,6 +76,10 @@ default:

FriendsOfBehat\SymfonyExtension: ~

FriendsOfBehat\ExcludeSpecificationsExtension:
features:
- "vendor/sylius/sylius/features/checkout/addressing_order/choosing_province_for_country.feature"

FriendsOfBehat\VariadicExtension: ~

FriendsOfBehat\SuiteSettingsExtension:
Expand Down
63 changes: 63 additions & 0 deletions config/packages/_sylius.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,66 @@ sylius_theme:
filesystem:
directories:
- "%kernel.project_dir%/themes"

sylius_fixtures:
suites:
default:
fixtures:
currency:
options:
currencies: ['PLN','HUF','EUR']
channel:
options:
custom:
pl_web_store:
name: "PL Web Store"
code: "PL_WEB"
locales:
- "%locale%"
currencies:
- "PLN"
enabled: true
hostname: "localhost"
hun_web_store:
name: "Hun Web Store"
code: "HUN_WEB"
locales:
- "%locale%"
currencies:
- "HUF"
enabled: true
hostname: "localhost"
shipping_method:
options:
custom:
ups_eu:
code: "ups_eu"
name: "UPS_eu"
enabled: true
channels:
- "PL_WEB"
ups:
channels:
- "HUN_WEB"
geis:
code: "geis"
name: "geis"
enabled: true
channels:
- "PL_WEB"
deliveryConditions: "delivered"
payment_method:
options:
custom:
cash_on_delivery_pl:
code: "cash_on_delivery_eu"
name: "Cash on delivery_eu"
channels:
- "PL_WEB"
bank_transfer:
code: "bank_transfer_eu"
name: "Bank transfer_eu"
channels:
- "PL_WEB"
- "HUN_WEB"
enabled: true
12 changes: 12 additions & 0 deletions config/packages/test/behat.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults public="true" />

<service id="app.behat.context.ui.admin.managing_shipping_methods" class="App\Tests\Behat\Contexts\Ui\Admin\ManagingShippingMethodsContext">
<argument type="service" id="app.behat.page.admin.shipping_method.update" />
</service>
<service id="app.behat.page.admin.shipping_method.update" class="App\Tests\Behat\Page\ShippingMethod\UpdatePage" parent="sylius.behat.page.admin.shipping_method.update" public="true" />
</services>
</container>
26 changes: 25 additions & 1 deletion config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,34 @@ services:
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/*'
exclude: '../src/{Entity,Migrations,Tests,Kernel.php}'
exclude: '../src/{Entity,Fixture,Form,Migrations,Tests,Kernel.php}'

# Controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']

app.form.extension.type.shipping_method_translation:
class: App\Form\Extension\ShippingMethodTranslationTypeExtension
tags:
- { name: form.type_extension, extended_type: Sylius\Bundle\ShippingBundle\Form\Type\ShippingMethodTranslationType }

sylius.fixture.example_factory.shipping_method:
class: App\Fixture\Factory\ShippingMethodExampleFactory
arguments:
- "@sylius.factory.shipping_method"
- "@sylius.repository.zone"
- "@sylius.repository.shipping_category"
- "@sylius.repository.locale"
- "@sylius.repository.channel"
- "@sylius.repository.tax_category"
public: true

sylius.fixture.shipping_method:
class: App\Fixture\ShippingMethodFixture
arguments:
- "@sylius.manager.shipping_method"
- "@sylius.fixture.example_factory.shipping_method"
tags:
- { name: sylius_fixtures.fixture }
1 change: 1 addition & 0 deletions config/services_test.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
imports:
- { resource: "../vendor/sylius/sylius/src/Sylius/Behat/Resources/config/services.xml" }
- { resource: "packages/test/behat.xml" }
18 changes: 18 additions & 0 deletions features/adding_delivery_condition.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@managing_shipping_methods
Feature: Adding delivery condition
In order to make customers aware of the delivery condition
As an Administrator
I want to be able to add delivery condition to a shipping method

Background:
Given the store operates on a single channel in "United States"
And the store is available in "English (United States)"
And the store allows shipping with "UPS Carrier" identified by "UPS_CARRIER"
And I am logged in as an administrator

@ui
Scenario: Adding delivery condition to shipping method details
Given I am editing the "UPS Carrier" shipping method
When I add the delivery condition of "shipment only on Friday"
And I save my changes
Then I should see that this shipping method has the delivery condition of "shipment only on Friday"
5 changes: 5 additions & 0 deletions phpspec.yaml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
suites:
app:
namespace: App
psr4_prefix: App
src_path: src/
23 changes: 23 additions & 0 deletions spec/Entity/Shipping/ShippingMethodSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace spec\App\Entity\Shipping;

use App\Entity\Shipping\ShippingMethod;
use PhpSpec\ObjectBehavior;

final class ShippingMethodSpec extends ObjectBehavior
{
function it_is_initializable(): void
{
$this->shouldHaveType(ShippingMethod::class);
}

function it_checks_delivery_condition(): void
{
$this->setCurrentLocale('en_US');
$this->setDeliveryConditions('delivered');
$this->getDeliveryConditions()->shouldReturn('delivered');
}
}
22 changes: 22 additions & 0 deletions spec/Entity/Shipping/ShippingMethodTranslationSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace spec\App\Entity\Shipping;

use App\Entity\Shipping\ShippingMethodTranslation;
use PhpSpec\ObjectBehavior;

final class ShippingMethodTranslationSpec extends ObjectBehavior
{
function it_is_initializable(): void
{
$this->shouldHaveType(ShippingMethodTranslation::class);
}

function it_checks_delivery_condition(): void
{
$this->setDeliveryConditions('delivered');
$this->getDeliveryConditions()->shouldReturn('delivered');
}
}
20 changes: 15 additions & 5 deletions src/Entity/Shipping/ShippingMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,27 @@

namespace App\Entity\Shipping;

use Doctrine\ORM\Mapping\MappedSuperclass;
use Doctrine\ORM\Mapping\Table;
use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Core\Model\ShippingMethod as BaseShippingMethod;
use Sylius\Component\Core\Model\ShippingMethodInterface;
use Sylius\Component\Shipping\Model\ShippingMethodTranslationInterface;

/**
* @MappedSuperclass
* @Table(name="sylius_shipping_method")
* @ORM\Entity()
* @ORM\Table(name="sylius_shipping_method")
*/
class ShippingMethod extends BaseShippingMethod
class ShippingMethod extends BaseShippingMethod implements ShippingMethodInterface
{
public function getDeliveryConditions(): ?string
{
return $this->getTranslation()->getDeliveryConditions();
}

public function setDeliveryConditions(?string $deliveryConditions): void
{
$this->getTranslation()->setDeliveryConditions($deliveryConditions);
}

protected function createTranslation(): ShippingMethodTranslationInterface
{
return new ShippingMethodTranslation();
Expand Down
22 changes: 17 additions & 5 deletions src/Entity/Shipping/ShippingMethodTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,26 @@

namespace App\Entity\Shipping;

use Doctrine\ORM\Mapping\MappedSuperclass;
use Doctrine\ORM\Mapping\Table;
use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Shipping\Model\ShippingMethodTranslation as BaseShippingMethodTranslation;
use Sylius\Component\Shipping\Model\ShippingMethodTranslationInterface;

/**
* @MappedSuperclass
* @Table(name="sylius_shipping_method_translation")
* @ORM\Entity()
* @ORM\Table(name="sylius_shipping_method_translation")
*/
class ShippingMethodTranslation extends BaseShippingMethodTranslation
class ShippingMethodTranslation extends BaseShippingMethodTranslation implements ShippingMethodTranslationInterface
{
/** @ORM\Column(type="string", nullable=true) */
private $deliveryConditions;

public function getDeliveryConditions(): ?string
{
return $this->deliveryConditions;
}

public function setDeliveryConditions(?string $deliveryConditions): void
{
$this->deliveryConditions = $deliveryConditions;
}
}
78 changes: 78 additions & 0 deletions src/Fixture/Factory/ShippingMethodExampleFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

declare(strict_types=1);

namespace App\Fixture\Factory;

use App\Entity\Shipping\ShippingMethod;
use Sylius\Bundle\CoreBundle\Fixture\Factory\ShippingMethodExampleFactory as BaseShippingMethodExampleFactory;
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
use Sylius\Component\Core\Model\ShippingMethodInterface;
use Sylius\Component\Locale\Model\LocaleInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class ShippingMethodExampleFactory extends BaseShippingMethodExampleFactory
{
/** @var RepositoryInterface */
private $localeRepository;

public function __construct(
FactoryInterface $shippingMethodFactory,
RepositoryInterface $zoneRepository,
RepositoryInterface $shippingCategoryRepository,
RepositoryInterface $localeRepository,
ChannelRepositoryInterface $channelRepository,
?RepositoryInterface $taxCategoryRepository = null
) {
parent::__construct(
$shippingMethodFactory,
$zoneRepository,
$shippingCategoryRepository,
$localeRepository,
$channelRepository,
$taxCategoryRepository
);

$this->localeRepository = $localeRepository;
}

public function create(array $options = []): ShippingMethodInterface
{
/** @var ShippingMethod $shippingMethod */
$shippingMethod = parent::create($options);

if (!isset($options['deliveryConditions'])) {
return $shippingMethod;
}

foreach ($this->getLocales() as $localeCode) {
$shippingMethod->setCurrentLocale($localeCode);
$shippingMethod->setFallbackLocale($localeCode);

$shippingMethod->setDeliveryConditions($options['deliveryConditions']);
}

return $shippingMethod;
}

protected function configureOptions(OptionsResolver $resolver): void
{
parent::configureOptions($resolver);

$resolver
->setDefault('deliveryConditions', 'some_default_value')
->setAllowedTypes('deliveryConditions', ['null', 'string'])
;
}

private function getLocales(): iterable
{
/** @var LocaleInterface[] $locales */
$locales = $this->localeRepository->findAll();
foreach ($locales as $locale) {
yield $locale->getCode();
}
}
}
Loading