Skip to content

Commit

Permalink
Build fixes (#13)
Browse files Browse the repository at this point in the history
* Fix PHPSpec tests

* Update build - add PHPSpec run

* Bump node version in build

* Bump node version from 12 to 14

* Fix typo in spec function name

Co-authored-by: Marcin Kukliński <[email protected]>
  • Loading branch information
marekrzytki and senghe authored Mar 4, 2022
1 parent f2611f5 commit 74f85eb
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 37 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
php: [7.4, 8.0]
node: [10.x]
node: [14.x]
mysql: [5.7, 8.0]

exclude:
Expand Down Expand Up @@ -133,7 +133,9 @@ jobs:
-
name: Validate database schema
run: (cd tests/Application && bin/console doctrine:schema:validate)

-
name: Run PHPSpec
run: vendor/bin/phpspec run --ansi -f progress --no-interaction
-
name: Run Behat
run: vendor/bin/behat --colors --strict -vvv --no-interaction || vendor/bin/behat --colors --strict -vvv --no-interaction --rerun
92 changes: 58 additions & 34 deletions spec/EventListener/ShippingExportEventListenerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@

namespace spec\BitBag\SyliusDhl24PlShippingExportPlugin\EventListener;

use BitBag\SyliusDhl24PlShippingExportPlugin\Api\SoapClientInterface;
use BitBag\SyliusDhl24PlShippingExportPlugin\Api\WebClientInterface;
use BitBag\SyliusDhl24PlShippingExportPlugin\Api\ShippingLabelFetcherInterface;
use BitBag\SyliusDhl24PlShippingExportPlugin\EventListener\ShippingExportEventListener;
use BitBag\SyliusShippingExportPlugin\Entity\ShippingExportInterface;
use BitBag\SyliusShippingExportPlugin\Entity\ShippingGatewayInterface;
use BitBag\SyliusShippingExportPlugin\Event\ExportShipmentEvent;
use BitBag\SyliusShippingExportPlugin\Repository\ShippingExportRepository;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\Order;
use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent;
use Sylius\Component\Core\Model\ShipmentInterface;
use Symfony\Component\Filesystem\Filesystem;
use Webmozart\Assert\InvalidArgumentException;

final class ShippingExportEventListenerSpec extends ObjectBehavior
{
Expand All @@ -29,49 +30,72 @@ function it_is_initializable(): void
$this->shouldHaveType(ShippingExportEventListener::class);
}

function let(WebClientInterface $webClient, SoapClientInterface $soapClient): void
function let(
Filesystem $filesystem,
ShippingExportRepository $shippingExportRepository,
ShippingLabelFetcherInterface $shippingLabelFetcher
): void
{
$this->beConstructedWith($webClient, $soapClient);
$this->beConstructedWith(
$filesystem,
$shippingExportRepository,
'shippingLabel',
$shippingLabelFetcher
);
}

function it_export_shipment(
ExportShipmentEvent $exportShipmentEvent,
function it_exports_shipment(
ResourceControllerEvent $event,
ShippingExportInterface $shippingExport,
ShippingGatewayInterface $shippingGateway,
ShipmentInterface $shipment,
WebClientInterface $webClient,
SoapClientInterface $soapClient,
Order $order
ShippingLabelFetcherInterface $shippingLabelFetcher,
ShippingExportEventListener $shippingExportEventListener
): void {
$webClient->setShippingGateway($shippingGateway);
$labelContent = 'labelContent';
$shippingGatewayCode = "'dhl24_pl'";

$shippingGateway->getCode()->willReturn(ShippingExportEventListener::DHL_GATEWAY_CODE);
$shippingGateway->getConfigValue('wsdl')->willReturn('wsdl');
$event->getSubject()
->willReturn($shippingExport);

$webClient->getRequestData()->willReturn([]);
$webClient->setShippingGateway($shippingGateway)->shouldBeCalled();
$webClient->setShipment($shipment)->shouldBeCalled();
$shippingExport->getShippingGateway()
->willReturn($shippingGateway);

$shippingExport->getShipment()->willReturn($shipment);
$shippingGateway->getCode()
->willReturn($shippingGatewayCode);

$exportShipmentEvent->getShippingExport()->willReturn($shippingExport);
$exportShipmentEvent->addSuccessFlash()->shouldBeCalled();
$exportShipmentEvent->exportShipment()->shouldBeCalled();
$exportShipmentEvent->saveShippingLabel('', 'pdf')->shouldBeCalled();
$shippingExport->getShippingGateway()->willReturn($shippingGateway);
$shippingExport->getShipment()
->willReturn($shipment);

$order->getNumber()->willReturn(1000);
$shipment->getOrder()->willReturn($order);
$shippingLabelFetcher->getLabelContent()
->willReturn($labelContent);

$soapClient->createShipment([], 'wsdl')->willReturn(
(object) ['createShipmentResult' => (object) ['label' => (object) [
'labelContent' => '',
'labelType' => 't',
],
],
]
);
$this->exportShipment($event);
}

function it_throws_exception_if_given_wrong_instance(
ResourceControllerEvent $event,
ShippingGatewayInterface $shippingGateway
): void {
$event->getSubject()
->willReturn($shippingGateway);

$this->shouldThrow(InvalidArgumentException::class)
->during('exportShipment', [$event]);
}

function it_throws_exception_if_shipping_gateway_is_null(
ResourceControllerEvent $event,
ShippingExportInterface $shippingExport
): void {
$shippingGateway = null;
$event->getSubject()
->willReturn($shippingExport);

$shippingExport->getShippingGateway()
->willReturn($shippingGateway);

$this->exportShipment($exportShipmentEvent);
$this->shouldThrow(InvalidArgumentException::class)
->during('exportShipment', [$event]);
}
}
2 changes: 1 addition & 1 deletion src/EventListener/ShippingExportEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Symfony\Component\Filesystem\Filesystem;
use Webmozart\Assert\Assert;

final class ShippingExportEventListener
class ShippingExportEventListener
{
public const DHL_GATEWAY_CODE = 'dhl24_pl';

Expand Down

0 comments on commit 74f85eb

Please sign in to comment.