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
1 parent
cf116f2
commit e29fa93
Showing
21 changed files
with
372 additions
and
22 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
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
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,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\Behat\Context\Api\Shop; | ||
|
||
use Behat\Behat\Context\Context; | ||
use Sylius\Behat\Client\ApiClientInterface; | ||
use Sylius\Behat\Client\Request; | ||
use Sylius\Behat\Client\ResponseCheckerInterface; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class CartContext implements Context | ||
{ | ||
/** @var ApiClientInterface */ | ||
private $cartsClient; | ||
|
||
/** @var ResponseCheckerInterface */ | ||
private $responseChecker; | ||
|
||
public function __construct(ApiClientInterface $cartsClient, ResponseCheckerInterface $responseChecker) | ||
{ | ||
$this->cartsClient = $cartsClient; | ||
$this->responseChecker = $responseChecker; | ||
} | ||
|
||
/** | ||
* @When I see the summary of my cart | ||
*/ | ||
public function iSeeTheSummaryOfMyCart(): void | ||
{ | ||
$this->cartsClient->create(Request::create('orders')); | ||
} | ||
|
||
/** | ||
* @Then my cart should be empty | ||
*/ | ||
public function myCartShouldBeEmpty(): void | ||
{ | ||
$response = $this->cartsClient->getLastResponse(); | ||
Assert::true( | ||
$this->responseChecker->isCreationSuccessful($response), | ||
'Cart has not been created. Reason: ' . $response->getContent() | ||
); | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
src/Sylius/Behat/Resources/config/suites/api/cart/shopping_cart.yml
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 @@ | ||
# This file is part of the Sylius package. | ||
# (c) Paweł Jędrzejewski | ||
|
||
default: | ||
suites: | ||
api_shopping_cart: | ||
contexts: | ||
- sylius.behat.context.hook.doctrine_orm | ||
|
||
- sylius.behat.context.setup.channel | ||
|
||
- sylius.behat.context.api.shop.cart | ||
|
||
filters: | ||
tags: "@shopping_cart && @api" |
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,21 @@ | ||
<?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\Bundle\ApiBundle\Command; | ||
|
||
/** | ||
* @psalm-immutable | ||
*/ | ||
class PickupCart | ||
{ | ||
} |
72 changes: 72 additions & 0 deletions
72
src/Sylius/Bundle/ApiBundle/CommandHandler/PickupCartHandler.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,72 @@ | ||
<?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\Bundle\ApiBundle\CommandHandler; | ||
|
||
use Doctrine\Persistence\ObjectManager; | ||
use Sylius\Bundle\ApiBundle\Command\PickupCart; | ||
use Sylius\Component\Channel\Context\ChannelContextInterface; | ||
use Sylius\Component\Core\Model\ChannelInterface; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Sylius\Component\Currency\Model\CurrencyInterface; | ||
use Sylius\Component\Locale\Model\LocaleInterface; | ||
use Sylius\Component\Resource\Factory\FactoryInterface; | ||
use Sylius\Component\Resource\Generator\RandomnessGeneratorInterface; | ||
use Symfony\Component\Messenger\Handler\MessageHandlerInterface; | ||
|
||
final class PickupCartHandler implements MessageHandlerInterface | ||
{ | ||
/** @var FactoryInterface */ | ||
private $cartFactory; | ||
|
||
/** @var ChannelContextInterface */ | ||
private $channelContext; | ||
|
||
/** @var ObjectManager */ | ||
private $orderManager; | ||
|
||
/** @var RandomnessGeneratorInterface */ | ||
private $generator; | ||
|
||
public function __construct( | ||
FactoryInterface $cartFactory, | ||
ChannelContextInterface $channelContext, | ||
ObjectManager $orderManager, | ||
RandomnessGeneratorInterface $generator | ||
) { | ||
$this->cartFactory = $cartFactory; | ||
$this->channelContext = $channelContext; | ||
$this->orderManager = $orderManager; | ||
$this->generator = $generator; | ||
} | ||
|
||
public function __invoke(PickupCart $pickupCart) | ||
{ | ||
/** @var OrderInterface $cart */ | ||
$cart = $this->cartFactory->createNew(); | ||
|
||
/** @var ChannelInterface $channel */ | ||
$channel = $this->channelContext->getChannel(); | ||
/** @var LocaleInterface $locale */ | ||
$locale = $channel->getDefaultLocale(); | ||
/** @var CurrencyInterface $currency */ | ||
$currency = $channel->getBaseCurrency(); | ||
|
||
$cart->setChannel($channel); | ||
$cart->setLocaleCode($locale->getCode()); | ||
$cart->setCurrencyCode($currency->getCode()); | ||
$cart->setTokenValue($this->generator->generateUriSafeString(10)); | ||
|
||
$this->orderManager->persist($cart); | ||
|
||
return $cart; | ||
} | ||
} |
Oops, something went wrong.