Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OP-172 Add support for Sylius 1.12 and Symfony 6 #7

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,12 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ["8.0", "7.4"]
symfony: ["^4.4", "^5.2"]
sylius: ["~1.9.0", "~1.10.0", "~1.11.0"]
node: ["10.x"]
php: ["8.1", "8.2"]
symfony: ["^5.4", "^6.0"]
sylius: ["~1.12.0"]
node: ["14.x"]
mysql: ["8.0"]

exclude:
- sylius: ~1.9.0
php: 8.0

- sylius: ~1.11.0
php: 7.4


env:
APP_ENV: test
DATABASE_URL: "mysql://root:[email protected]/sylius?serverVersion=${{ matrix.mysql }}"
Expand Down Expand Up @@ -161,7 +153,7 @@ jobs:

-
name: Run PHPStan
run: vendor/bin/phpstan analyse -c phpstan.neon -l max src/
run: vendor/bin/phpstan analyse

-
name: Run PHPSpec
Expand Down
16 changes: 3 additions & 13 deletions .github/workflows/coding-standard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,12 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ["8.0", "7.4"]
symfony: ["^4.4", "^5.2"]
sylius: ["~1.9.6", "~1.10.0", "~1.11.0"]
php: ["8.1", "8.2"]
symfony: ["^5.4", "^6.0"]
sylius: ["~1.12.0"]
node: ["14.x"]
mysql: ["8.0"]

exclude:
- sylius: ~1.9.6
php: 8.0

- sylius: ~1.10.0
symfony: 4.4

- sylius: ~1.11.0
php: 7.4

env:
APP_ENV: test
DATABASE_URL: "mysql://root:[email protected]/sylius?serverVersion=${{ matrix.mysql }}"
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
!/etc/build/.gitkeep

/tests/Application/shipping_labels/*

composer.lock
29 changes: 23 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ This **open-source plugin was developed to help the Sylius community**. If you h
# Installation

```bash
$ composer require bitbag/dpdpl-shipping-export-plugin
composer require bitbag/dpd-pl-shipping-export-plugin
```

Add plugin dependencies to your `config/bundles.php` file:
Expand All @@ -50,20 +50,37 @@ return [

Import required config in your `config/packages/_sylius.yaml` file:
```yaml
# config/packages/_sylius.yaml

imports:
...

- { resource: "@DpdPlShippingExportPlugin/Resources/config/config.yml" }
```

Update your database schema
Import routing in your `config/routes.yaml` file:

```yaml
bitbag_shipping_export_plugin:
resource: "@BitBagSyliusShippingExportPlugin/Resources/config/routing.yml"
prefix: /admin
```

Clear application cache by using command:

```bash
bin/console doctrine:schema:update
bin/console cache:clear
```

**Note:** If you are running it on production, add the `-e prod` flag to this command.
Verify database schema changes:

```bash
bin/console doctrine:schema:update --dump-sql
```

Update your database schema

```bash
bin/console doctrine:schema:update --force --complete
```

# About us

Expand Down
34 changes: 16 additions & 18 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"bitbag/shipping-export-plugin": "^1.5",
"php": "^8.0",
"bitbag/shipping-export-plugin": "^3.0",
"msztorc/php-dpd-api": "^2.1",
"sylius/sylius": "~1.9.0 || ~1.10.0 || ~1.11.0"
"sylius/sylius": "~1.12.0",
mpysiak marked this conversation as resolved.
Show resolved Hide resolved
"symfony/webpack-encore-bundle": "^1.17"
},
"require-dev": {
"behat/behat": "^3.6.1",
"behat/mink-selenium2-driver": "^1.4",
"bitbag/coding-standard": "^1.0",
"bitbag/coding-standard": "^3.0",
"dmore/behat-chrome-extension": "^1.3",
"dmore/chrome-mink-driver": "^2.7",
"friends-of-behat/mink": "^1.8",
Expand All @@ -29,27 +30,24 @@
"friends-of-behat/suite-settings-extension": "^1.0",
"friends-of-behat/symfony-extension": "^2.1",
"friends-of-behat/variadic-extension": "^1.3",
"friendsofsymfony/oauth-server-bundle": "^1.6 || >2.0.0-alpha.0 ^2.0@dev",
"phpspec/phpspec": "^7.0",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "0.12.85",
"phpstan/phpstan-doctrine": "0.12.33",
"phpstan/phpstan-strict-rules": "^0.12.0",
"phpstan/phpstan-webmozart-assert": "0.12.12",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-doctrine": "^1.3",
"phpstan/phpstan-strict-rules": "^1.5",
"phpstan/phpstan-webmozart-assert": "^1.2",
"phpunit/phpunit": "^9.5",
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
"sensiolabs/security-checker": "^6.0",
"sylius-labs/coding-standard": "^4.0",
"symfony/browser-kit": "^4.4 || ^5.2",
"symfony/debug-bundle": "^4.4 || ^5.2",
"symfony/dotenv": "^4.4 || ^5.2",
"symfony/intl": "^4.4 || ^5.2",
"symfony/web-profiler-bundle": "^4.4 || ^5.2",
"vimeo/psalm": "4.7.1"
"symfony/browser-kit": "^5.4 || ^6.0",
"symfony/debug-bundle": "^5.4 || ^6.0",
"symfony/dotenv": "^5.4 || ^6.0",
"symfony/intl": "^5.4 || ^6.0",
"symfony/web-profiler-bundle": "^5.4 || ^6.0",
"league/flysystem-bundle": "2.4.0"
},
"conflict": {
"sylius/resource-bundle": "1.9.1 || 1.9.0",
"doctrine/orm": ">=2.15.2"
"sylius/resource-bundle": "1.9.1 || 1.9.0"
},
"config": {
"sort-packages": true,
Expand Down
12 changes: 5 additions & 7 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
parameters:
reportUnmatchedIgnoredErrors: false
checkMissingIterableValueType: false
level: 8

excludes_analyse:
paths:
- 'src'

excludePaths:
# Makes PHPStan crash
- 'src/DependencyInjection/Configuration.php'

# Test dependencies
- 'tests/Application/*'

# ECS Fixer dependency
- 'src/Fixer'

ignoreErrors:
- '/Parameter #1 \$configuration of method Symfony\\Component\\DependencyInjection\\Extension\\Extension::processConfiguration\(\) expects Symfony\\Component\\Config\\Definition\\ConfigurationInterface, Symfony\\Component\\Config\\Definition\\ConfigurationInterface\|null given\./'
14 changes: 11 additions & 3 deletions spec/EventListener/ShippingExportEventListenerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
use Sylius\Component\Core\Model\Order;
use Sylius\Component\Core\Model\ShipmentInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\SessionInterface;

final class ShippingExportEventListenerSpec extends ObjectBehavior
{
Expand All @@ -23,12 +26,12 @@ function it_is_initializable()

function let (
WebClientInterface $webClient,
FlashBagInterface $flashBag,
RequestStack $requestStack,
Filesystem $filesystem,
ObjectManager $objectManager
) {
$shippingLabelsPath = 'labels';
$this->beConstructedWith($webClient, $flashBag, $filesystem, $objectManager, $shippingLabelsPath);
$this->beConstructedWith($webClient, $requestStack, $filesystem, $objectManager, $shippingLabelsPath);
}

function it_export_shipment
Expand All @@ -38,10 +41,15 @@ function it_export_shipment
ShippingGatewayInterface $shippingGateway,
ShipmentInterface $shipment,
WebClientInterface $webClient,
Order $order
Order $order,
RequestStack $requestStack,
Session $session,
FlashBagInterface $flashBag,
)
{
$webClient->setShippingGateway($shippingGateway);
$requestStack->getSession()->willReturn($session);
$session->getFlashBag()->willReturn($flashBag);

$shippingGateway->getCode()->willReturn(ShippingExportEventListener::DPD_GATEWAY_CODE);

Expand Down
17 changes: 3 additions & 14 deletions src/Api/WebClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ final class WebClient implements WebClientInterface
{
public const DATE_FORMAT = 'Y-m-d';

/** @var ShippingGatewayInterface */
private $shippingGateway;
private ShippingGatewayInterface $shippingGateway;

/** @var ShipmentInterface */
private $shipment;
private ShipmentInterface $shipment;

public function setShippingGateway(ShippingGatewayInterface $shippingGateway): void
{
Expand Down Expand Up @@ -123,14 +121,6 @@ public function getPickupAddress(): array
{
return [
'fid' => $this->getShippingGatewayConfig('id'),
// 'name' => 'NAME',
// 'company' => 'COMPANY',
// 'address' => 'ADDRESS',
// 'city' => 'CITY',
// 'postalCode' => '85132',
// 'countryCode' => 'PL',
// 'email'=> '[email protected]',
// 'phone' => '777888999',
];
}

Expand Down Expand Up @@ -214,8 +204,7 @@ private function resolveWeekend(\DateTime $date): \DateTime
return $date;
}

/** @return mixed */
private function getShippingGatewayConfig(string $config)
private function getShippingGatewayConfig(string $config): mixed
{
return $this->shippingGateway->getConfigValue($config);
}
Expand Down
32 changes: 15 additions & 17 deletions src/EventListener/ShippingExportEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
use BitBag\SyliusShippingExportPlugin\Entity\ShippingExportInterface;
use Doctrine\Persistence\ObjectManager;
use DPD\Services\DPDService;
use http\Exception\InvalidArgumentException;
use Exception;
use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Session;
use Webmozart\Assert\Assert;

final class ShippingExportEventListener
Expand All @@ -26,30 +27,25 @@ final class ShippingExportEventListener

public const BASE_LABEL_EXTENSION = 'pdf';

/** @var WebClientInterface */
private $webClient;
private WebClientInterface $webClient;

/** @var FlashBagInterface */
private $flashBag;
private RequestStack $requestStack;

/** @var Filesystem */
private $fileSystem;
private Filesystem $fileSystem;

/** @var ObjectManager */
private $shippingExportManager;
private ObjectManager $shippingExportManager;

/** @var string */
private $shippingLabelsPath;
private string $shippingLabelsPath;

public function __construct(
WebClientInterface $webClient,
FlashBagInterface $flashBag,
RequestStack $requestStack,
FileSystem $fileSystem,
ObjectManager $shippingExportManager,
string $shippingLabelsPath
) {
$this->webClient = $webClient;
$this->flashBag = $flashBag;
$this->requestStack = $requestStack;
$this->fileSystem = $fileSystem;
$this->shippingExportManager = $shippingExportManager;
$this->shippingLabelsPath = $shippingLabelsPath;
Expand All @@ -75,6 +71,8 @@ public function exportShipment(ResourceControllerEvent $exportShipmentEvent): vo
Assert::notNull($shipment);

$this->webClient->setShipment($shipment);
/** @var Session $session */
$session = $this->requestStack->getSession();

try {
$dpd = new DPDService(
Expand All @@ -89,8 +87,8 @@ public function exportShipment(ResourceControllerEvent $exportShipmentEvent): vo
$result = $dpd->sendPackage($this->webClient->getParcels(), $this->webClient->getReceiver(), 'SENDER', $this->webClient->getServices());

$speedLabel = $dpd->generateSpeedLabelsByPackageIds([$result->packageId], $this->webClient->getPickupAddress()); /** @phpstan-ignore-line */
} catch (\Exception $exception) {
$this->flashBag->add('error', sprintf(
} catch (Exception $exception) {
$session->getFlashBag()->add('error', sprintf(
'DPD Web Service for #%s order: %s',
$shipment->getOrder() !== null ? (string) $shipment->getOrder()->getNumber() : '',
$exception->getMessage()
Expand All @@ -99,7 +97,7 @@ public function exportShipment(ResourceControllerEvent $exportShipmentEvent): vo
return;
}

$this->flashBag->add('success', 'bitbag.ui.shipment_data_has_been_exported');
$session->getFlashBag()->add('success', 'bitbag.ui.shipment_data_has_been_exported');
$this->saveShippingLabel($shippingExport, $speedLabel->filedata, self::BASE_LABEL_EXTENSION); /** @phpstan-ignore-line */
$this->markShipmentAsExported($shippingExport);
}
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/config.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
imports:
- { resource: "@BitBagSyliusShippingExportPlugin/Resources/config/config.yml" }
- { resource: "@DpdPlShippingExportPlugin/Resources/config/services.yml" }
2 changes: 1 addition & 1 deletion src/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
class: BitBag\DpdPlShippingExportPlugin\EventListener\ShippingExportEventListener
arguments:
- '@bitbag.dpd_pl_shipping_export_plugin.api.web_client'
- '@session.flash_bag'
- '@request_stack'
- '@filesystem'
- '@bitbag.manager.shipping_export'
- '%bitbag.shipping_labels_path%'
Expand Down
3 changes: 2 additions & 1 deletion tests/Application/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/public/assets
/public/build
/public/css
/public/js
/public/media/*
Expand All @@ -19,4 +20,4 @@

###> symfony/web-server-bundle ###
/.web-server-pid
###< symfony/web-server-bundle ###
###< symfony/web-server-bundle ###
Loading
Loading