Skip to content

Commit

Permalink
create Core ChannelFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
oallain committed Jun 16, 2020
1 parent 312d677 commit 70a40c6
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ before_install:
- etc/travis/run-suite before_install "${SYLIUS_SUITE}"

install:
- etc/travis/run-suite install "${SYLIUS_SUITE}"
- travis_wait etc/travis/run-suite install "${SYLIUS_SUITE}"

before_script:
- etc/travis/run-suite before_script "${SYLIUS_SUITE}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Sylius\Bundle\CoreBundle\Fixture\OptionsResolver\LazyOption;
use Sylius\Component\Addressing\Model\Scope as AddressingScope;
use Sylius\Component\Addressing\Model\ZoneInterface;
use Sylius\Component\Channel\Factory\ChannelFactoryInterface;
use Sylius\Component\Core\Factory\ChannelFactoryInterface;
use Sylius\Component\Core\Formatter\StringInflector;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\Scope;
Expand Down
5 changes: 5 additions & 0 deletions src/Sylius/Bundle/CoreBundle/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@
<argument type="service" id="sylius.custom_factory.address.inner" />
</service>

<service id="sylius.custom_factory.channel" class="Sylius\Component\Core\Factory\ChannelFactory" decorates="sylius.factory.channel" decoration-priority="256" public="false">
<argument type="service" id="sylius.custom_factory.channel.inner" />
<argument>order_items_based</argument>
</service>

<service id="sylius.factory.customer_after_checkout" class="Sylius\Component\Core\Factory\CustomerAfterCheckoutFactory">
<argument type="service" id="sylius.factory.customer" />
</service>
Expand Down
55 changes: 55 additions & 0 deletions src/Sylius/Component/Core/Factory/ChannelFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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\Component\Core\Factory;

use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;

class ChannelFactory implements ChannelFactoryInterface
{
/** @var FactoryInterface */
private $decoratedFactory;

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

public function __construct(FactoryInterface $decoratedFactory, string $defaultCalculationStrategy)
{
$this->decoratedFactory = $decoratedFactory;
$this->defaultCalculationStrategy = $defaultCalculationStrategy;
}

/**
* {@inheritdoc}
*/
public function createNew(): ChannelInterface
{
/** @var ChannelInterface $channel */
$channel = $this->decoratedFactory->createNew();
$channel->setTaxCalculationStrategy($this->defaultCalculationStrategy);

return $channel;
}

/**
* {@inheritdoc}
*/
public function createNamed(string $name): ChannelInterface
{
$channel = $this->createNew();
$channel->setName($name);

return $channel;
}
}
22 changes: 22 additions & 0 deletions src/Sylius/Component/Core/Factory/ChannelFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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\Component\Core\Factory;

use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;

interface ChannelFactoryInterface extends FactoryInterface
{
public function createNamed(string $name): ChannelInterface;
}
2 changes: 1 addition & 1 deletion src/Sylius/Component/Core/Model/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Channel extends BaseChannel implements ChannelInterface
protected $defaultTaxZone;

/** @var string */
protected $taxCalculationStrategy = 'order_items_based';
protected $taxCalculationStrategy;

/**
* @var Collection|CurrencyInterface[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Sylius\Component\Core\Test\Services;

use Sylius\Component\Channel\Factory\ChannelFactoryInterface;
use Sylius\Component\Core\Factory\ChannelFactoryInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Currency\Model\CurrencyInterface;
use Sylius\Component\Locale\Model\LocaleInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Sylius\Component\Addressing\Factory\ZoneFactoryInterface;
use Sylius\Component\Addressing\Model\CountryInterface;
use Sylius\Component\Addressing\Model\ZoneInterface;
use Sylius\Component\Channel\Factory\ChannelFactoryInterface;
use Sylius\Component\Core\Factory\ChannelFactoryInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Currency\Model\CurrencyInterface;
use Sylius\Component\Locale\Model\LocaleInterface;
Expand Down
46 changes: 46 additions & 0 deletions src/Sylius/Component/Core/spec/Factory/ChannelFactorySpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?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 spec\Sylius\Component\Core\Factory;

use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Factory\ChannelFactoryInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;

final class ChannelFactorySpec extends ObjectBehavior
{
function let(FactoryInterface $decoratedFactory): void
{
$this->beConstructedWith($decoratedFactory, 'order_items_based');
}

function it_implements_channel_factory_interface(): void
{
$this->shouldImplement(ChannelFactoryInterface::class);
}

function it_is_a_resource_factory(): void
{
$this->shouldImplement(FactoryInterface::class);
}

function it_creates_a_new_channel(FactoryInterface $decoratedFactory, ChannelInterface $channel): void
{
$decoratedFactory->createNew()->willReturn($channel);

$channel->setTaxCalculationStrategy('order_items_based')->shouldBeCalled();

$this->createNew()->shouldReturn($channel);
}
}
4 changes: 2 additions & 2 deletions src/Sylius/Component/Core/spec/Model/ChannelSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ function its_default_tax_zone_is_mutable(ZoneInterface $defaultTaxZone): void
$this->getDefaultTaxZone()->shouldReturn($defaultTaxZone);
}

function it_has_a_tax_calculation_strategy_by_default(): void
function it_has_no_tax_calculation_strategy_by_default(): void
{
$this->getTaxCalculationStrategy()->shouldReturn('order_items_based');
$this->getTaxCalculationStrategy()->shouldReturn(null);
}

function its_tax_calculation_strategy_is_mutable(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace spec\Sylius\Component\Core\Test\Services;

use PhpSpec\ObjectBehavior;
use Sylius\Component\Channel\Factory\ChannelFactoryInterface;
use Sylius\Component\Core\Factory\ChannelFactoryInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Test\Services\DefaultChannelFactoryInterface;
use Sylius\Component\Currency\Model\CurrencyInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Sylius\Component\Addressing\Factory\ZoneFactoryInterface;
use Sylius\Component\Addressing\Model\CountryInterface;
use Sylius\Component\Addressing\Model\ZoneInterface;
use Sylius\Component\Channel\Factory\ChannelFactoryInterface;
use Sylius\Component\Core\Factory\ChannelFactoryInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Test\Services\DefaultChannelFactoryInterface;
use Sylius\Component\Currency\Model\CurrencyInterface;
Expand Down

0 comments on commit 70a40c6

Please sign in to comment.