-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
145 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?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; | ||
|
||
public function __construct(FactoryInterface $decoratedFactory) | ||
{ | ||
$this->decoratedFactory = $decoratedFactory; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createNew(): ChannelInterface | ||
{ | ||
/** @var ChannelInterface $channel */ | ||
$channel = $this->decoratedFactory->createNew(); | ||
$channel->setTaxCalculationStrategy('order_items_based'); | ||
|
||
return $channel; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createNamed(string $name): ChannelInterface | ||
{ | ||
/** @var ChannelInterface $channel */ | ||
$channel = $this->decoratedFactory->createNew(); | ||
$channel->setTaxCalculationStrategy('order_items_based'); | ||
$channel->setName($name); | ||
|
||
return $channel; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Sylius/Component/Core/Factory/ChannelFactoryInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/Sylius/Component/Core/spec/Factory/ChannelFactorySpec.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?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); | ||
} | ||
|
||
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); | ||
} | ||
|
||
function it_creates_a_new_channel_with_name( | ||
FactoryInterface $decoratedFactory, | ||
ChannelInterface $channel | ||
): void { | ||
$decoratedFactory->createNew()->willReturn($channel); | ||
|
||
$channel->setTaxCalculationStrategy('order_items_based')->shouldBeCalled(); | ||
$channel->setName('name')->shouldBeCalled(); | ||
|
||
$this->createNamed('name')->shouldReturn($channel); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters