-
Notifications
You must be signed in to change notification settings - Fork 11
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
4 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
spec/EventListener/SelectParcelTemplateEventListener/SelectParcelTemplateActionSpec.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,46 @@ | ||
<?php | ||
|
||
namespace spec\BitBag\SyliusInPostPlugin\EventListener\SelectParcelTemplateEventListener; | ||
|
||
use BitBag\SyliusInPostPlugin\Entity\ShippingExportInterface; | ||
use BitBag\SyliusInPostPlugin\EventListener\SelectParcelTemplateEventListener\SelectParcelTemplateAction; | ||
use BitBag\SyliusInPostPlugin\EventListener\SelectParcelTemplateEventListener\SelectParcelTemplateActionInterface; | ||
use BitBag\SyliusShippingExportPlugin\Repository\ShippingExportRepositoryInterface; | ||
use PhpSpec\ObjectBehavior; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; | ||
use Symfony\Component\HttpFoundation\Session\SessionInterface; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
class SelectParcelTemplateActionSpec extends ObjectBehavior | ||
{ | ||
public function let( | ||
ShippingExportRepositoryInterface $shippingExportRepository, | ||
RequestStack $requestStack, | ||
TranslatorInterface $translator, | ||
): void { | ||
$this->beConstructedWith($shippingExportRepository, $requestStack, $translator); | ||
} | ||
|
||
public function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(SelectParcelTemplateAction::class); | ||
$this->shouldBeAnInstanceOf(SelectParcelTemplateActionInterface::class); | ||
} | ||
|
||
public function it_should_save_shipping_export_changes( | ||
ShippingExportInterface $shippingExport, | ||
ShippingExportRepositoryInterface $shippingExportRepository, | ||
RequestStack $requestStack, | ||
SessionInterface $session, | ||
FlashBagInterface $flashBag | ||
): void { | ||
$shippingExportRepository->add($shippingExport)->shouldBeCalled(); | ||
|
||
$requestStack->getSession()->willReturn($session); | ||
$session->getBag('flashes')->willReturn($flashBag); | ||
|
||
$this->execute($shippingExport); | ||
} | ||
|
||
} |
82 changes: 82 additions & 0 deletions
82
spec/EventListener/SelectParcelTemplateEventListenerSpec.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,82 @@ | ||
<?php | ||
|
||
/* | ||
* This file was created by developers working at BitBag | ||
* Do you need more information about us and what we do? Visit our https://bitbag.io website! | ||
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\BitBag\SyliusInPostPlugin\EventListener; | ||
|
||
use BitBag\SyliusInPostPlugin\EventListener\SelectParcelTemplateEventListener; | ||
use BitBag\SyliusInPostPlugin\EventListener\SelectParcelTemplateEventListener\SelectParcelTemplateActionInterface; | ||
use PhpSpec\ObjectBehavior; | ||
use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent; | ||
use Tests\BitBag\SyliusInPostPlugin\Spec\Builder\ShipmentBuilder; | ||
use Tests\BitBag\SyliusInPostPlugin\Spec\Builder\ShippingExportBuilder; | ||
use Tests\BitBag\SyliusInPostPlugin\Spec\Builder\ShippingGatewayBuilder; | ||
|
||
final class SelectParcelTemplateEventListenerSpec extends ObjectBehavior | ||
{ | ||
private const INCORRECT_PARCEL_TEMPLATE = 'x-large'; | ||
|
||
private const EXPECTED_PARCEL_TEMPLATE = 'small'; | ||
|
||
private const INPOST = 'inpost'; | ||
|
||
public function let( | ||
SelectParcelTemplateActionInterface $action | ||
): void { | ||
$this->beConstructedWith($action); | ||
} | ||
|
||
public function it_is_initializable(): void | ||
{ | ||
$this->shouldHaveType(SelectParcelTemplateEventListener::class); | ||
} | ||
|
||
public function it_should_throw_exception_if_subject_is_not_shipping_export_instance(ResourceControllerEvent $event): void | ||
{ | ||
$event->getSubject()->willReturn(new \stdClass()); | ||
|
||
$this | ||
->shouldThrow(\InvalidArgumentException::class) | ||
->during('setParcelTemplate', [$event]) | ||
; | ||
} | ||
|
||
public function it_should_throw_exception_if_incorrect_parcel_template_is_passed(ResourceControllerEvent $event): void | ||
{ | ||
$shippingGateway = ShippingGatewayBuilder::create()->withCode(self::INPOST)->build(); | ||
$shipment = ShipmentBuilder::create()->build(); | ||
$shippingExport = ShippingExportBuilder::create() | ||
->withShippingGateway($shippingGateway) | ||
->withShipment($shipment) | ||
->withParcelTemplate(self::INCORRECT_PARCEL_TEMPLATE) | ||
->build(); | ||
$event->getSubject()->willReturn($shippingExport); | ||
|
||
$this | ||
->shouldThrow(\Exception::class) | ||
->during('setParcelTemplate', [$event]) | ||
; | ||
} | ||
|
||
/** | ||
* @throws \Exception | ||
*/ | ||
public function it_should_perform_set_parcel_template_action(ResourceControllerEvent $event): void | ||
{ | ||
$shippingGateway = ShippingGatewayBuilder::create()->withCode(self::INPOST)->build(); | ||
$shipment = ShipmentBuilder::create()->build(); | ||
$shippingExport = ShippingExportBuilder::create() | ||
->withShippingGateway($shippingGateway) | ||
->withShipment($shipment) | ||
->withParcelTemplate(self::EXPECTED_PARCEL_TEMPLATE) | ||
->build(); | ||
$event->getSubject()->willReturn($shippingExport); | ||
$this->setParcelTemplate($event); | ||
} | ||
} |
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