-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addding validation for product in current channel
- Loading branch information
Showing
18 changed files
with
322 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace spec\Sylius\ShopApiPlugin\Checker; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use PhpSpec\ObjectBehavior; | ||
use Sylius\Component\Core\Model\ChannelInterface; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Sylius\Component\Core\Model\ProductInterface; | ||
use Sylius\ShopApiPlugin\Checker\ProductInCartChannelCheckerInterface; | ||
|
||
final class ProductInCartChannelCheckerSpec extends ObjectBehavior | ||
{ | ||
function it_implements_product_in_cart_channel_checker_interface(): void | ||
{ | ||
$this->shouldImplement(ProductInCartChannelCheckerInterface::class); | ||
} | ||
|
||
function it_returns_true_if_the_channels_match( | ||
ProductInterface $product, | ||
OrderInterface $order, | ||
ChannelInterface $channel | ||
): void | ||
{ | ||
$product->getChannels()->willReturn(new ArrayCollection([$channel->getWrappedObject()])); | ||
|
||
$order->getChannel()->willReturn($channel); | ||
|
||
$this->isProductInCartChannel($product, $order)->shouldReturn(true); | ||
} | ||
|
||
function it_returns_false_if_the_channels_do_not_match( | ||
ProductInterface $product, | ||
OrderInterface $order, | ||
ChannelInterface $orderChannel, | ||
ChannelInterface $productChannel1, | ||
ChannelInterface $productChannel2 | ||
): void { | ||
$product->getChannels()->willReturn(new ArrayCollection([ | ||
$productChannel1->getWrappedObject(), | ||
$productChannel2->getWrappedObject() | ||
])); | ||
|
||
$order->getChannel()->willReturn($orderChannel); | ||
|
||
$this->isProductInCartChannel($product, $order)->shouldReturn(false); | ||
} | ||
} |
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
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,15 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Sylius\ShopApiPlugin\Checker; | ||
|
||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Sylius\Component\Core\Model\ProductInterface; | ||
|
||
final class ProductInCartChannelChecker implements ProductInCartChannelCheckerInterface | ||
{ | ||
public function isProductInCartChannel(ProductInterface $product, OrderInterface $cart): bool | ||
{ | ||
return in_array($cart->getChannel(), $product->getChannels()->toArray(), true); | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Sylius\ShopApiPlugin\Checker; | ||
|
||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Sylius\Component\Core\Model\ProductInterface; | ||
|
||
interface ProductInCartChannelCheckerInterface | ||
{ | ||
public function isProductInCartChannel(ProductInterface $product, OrderInterface $cart): bool; | ||
} |
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
Oops, something went wrong.