Skip to content

Commit fea5286

Browse files
authored
Merge pull request #7 from BitBagCommerce/bump-sylius-version
OP-172 Add support for Sylius 1.12 and Symfony 6
2 parents a404605 + 29dc371 commit fea5286

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+4891
-5639
lines changed

.github/workflows/build.yml

+5-13
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,12 @@ jobs:
1818
strategy:
1919
fail-fast: false
2020
matrix:
21-
php: ["8.0", "7.4"]
22-
symfony: ["^4.4", "^5.2"]
23-
sylius: ["~1.9.0", "~1.10.0", "~1.11.0"]
24-
node: ["10.x"]
21+
php: ["8.1", "8.2"]
22+
symfony: ["^5.4", "^6.0"]
23+
sylius: ["~1.12.0"]
24+
node: ["14.x"]
2525
mysql: ["8.0"]
2626

27-
exclude:
28-
- sylius: ~1.9.0
29-
php: 8.0
30-
31-
- sylius: ~1.11.0
32-
php: 7.4
33-
34-
3527
env:
3628
APP_ENV: test
3729
DATABASE_URL: "mysql://root:root@127.0.0.1/sylius?serverVersion=${{ matrix.mysql }}"
@@ -161,7 +153,7 @@ jobs:
161153

162154
-
163155
name: Run PHPStan
164-
run: vendor/bin/phpstan analyse -c phpstan.neon -l max src/
156+
run: vendor/bin/phpstan analyse
165157

166158
-
167159
name: Run PHPSpec

.github/workflows/coding-standard.yml

+3-13
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,12 @@ jobs:
2121
strategy:
2222
fail-fast: false
2323
matrix:
24-
php: ["8.0", "7.4"]
25-
symfony: ["^4.4", "^5.2"]
26-
sylius: ["~1.9.6", "~1.10.0", "~1.11.0"]
24+
php: ["8.1", "8.2"]
25+
symfony: ["^5.4", "^6.0"]
26+
sylius: ["~1.12.0"]
2727
node: ["14.x"]
2828
mysql: ["8.0"]
2929

30-
exclude:
31-
- sylius: ~1.9.6
32-
php: 8.0
33-
34-
- sylius: ~1.10.0
35-
symfony: 4.4
36-
37-
- sylius: ~1.11.0
38-
php: 7.4
39-
4030
env:
4131
APP_ENV: test
4232
DATABASE_URL: "mysql://root:root@127.0.0.1/sylius?serverVersion=${{ matrix.mysql }}"

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99
!/etc/build/.gitkeep
1010

1111
/tests/Application/shipping_labels/*
12+
13+
composer.lock

README.md

+23-6
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ This **open-source plugin was developed to help the Sylius community**. If you h
3636
# Installation
3737

3838
```bash
39-
$ composer require bitbag/dpdpl-shipping-export-plugin
39+
composer require bitbag/dpd-pl-shipping-export-plugin
4040
```
4141

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

5151
Import required config in your `config/packages/_sylius.yaml` file:
5252
```yaml
53-
# config/packages/_sylius.yaml
54-
5553
imports:
5654
...
5755

5856
- { resource: "@DpdPlShippingExportPlugin/Resources/config/config.yml" }
5957
```
6058
61-
Update your database schema
59+
Import routing in your `config/routes.yaml` file:
60+
61+
```yaml
62+
bitbag_shipping_export_plugin:
63+
resource: "@BitBagSyliusShippingExportPlugin/Resources/config/routing.yml"
64+
prefix: /admin
65+
```
66+
67+
Clear application cache by using command:
68+
6269
```bash
63-
bin/console doctrine:schema:update
70+
bin/console cache:clear
6471
```
6572

66-
**Note:** If you are running it on production, add the `-e prod` flag to this command.
73+
Verify database schema changes:
74+
75+
```bash
76+
bin/console doctrine:schema:update --dump-sql
77+
```
78+
79+
Update your database schema
80+
81+
```bash
82+
bin/console doctrine:schema:update --force --complete
83+
```
6784

6885
# About us
6986

composer.json

+16-18
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010
}
1111
],
1212
"require": {
13-
"php": "^7.4 || ^8.0",
14-
"bitbag/shipping-export-plugin": "^1.5",
13+
"php": "^8.0",
14+
"bitbag/shipping-export-plugin": "^3.0",
1515
"msztorc/php-dpd-api": "^2.1",
16-
"sylius/sylius": "~1.9.0 || ~1.10.0 || ~1.11.0"
16+
"sylius/sylius": "~1.12.0",
17+
"symfony/webpack-encore-bundle": "^1.17"
1718
},
1819
"require-dev": {
1920
"behat/behat": "^3.6.1",
2021
"behat/mink-selenium2-driver": "^1.4",
21-
"bitbag/coding-standard": "^1.0",
22+
"bitbag/coding-standard": "^3.0",
2223
"dmore/behat-chrome-extension": "^1.3",
2324
"dmore/chrome-mink-driver": "^2.7",
2425
"friends-of-behat/mink": "^1.8",
@@ -29,27 +30,24 @@
2930
"friends-of-behat/suite-settings-extension": "^1.0",
3031
"friends-of-behat/symfony-extension": "^2.1",
3132
"friends-of-behat/variadic-extension": "^1.3",
32-
"friendsofsymfony/oauth-server-bundle": "^1.6 || >2.0.0-alpha.0 ^2.0@dev",
3333
"phpspec/phpspec": "^7.0",
3434
"phpstan/extension-installer": "^1.0",
35-
"phpstan/phpstan": "0.12.85",
36-
"phpstan/phpstan-doctrine": "0.12.33",
37-
"phpstan/phpstan-strict-rules": "^0.12.0",
38-
"phpstan/phpstan-webmozart-assert": "0.12.12",
35+
"phpstan/phpstan": "^1.10",
36+
"phpstan/phpstan-doctrine": "^1.3",
37+
"phpstan/phpstan-strict-rules": "^1.5",
38+
"phpstan/phpstan-webmozart-assert": "^1.2",
3939
"phpunit/phpunit": "^9.5",
4040
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
41-
"sensiolabs/security-checker": "^6.0",
4241
"sylius-labs/coding-standard": "^4.0",
43-
"symfony/browser-kit": "^4.4 || ^5.2",
44-
"symfony/debug-bundle": "^4.4 || ^5.2",
45-
"symfony/dotenv": "^4.4 || ^5.2",
46-
"symfony/intl": "^4.4 || ^5.2",
47-
"symfony/web-profiler-bundle": "^4.4 || ^5.2",
48-
"vimeo/psalm": "4.7.1"
42+
"symfony/browser-kit": "^5.4 || ^6.0",
43+
"symfony/debug-bundle": "^5.4 || ^6.0",
44+
"symfony/dotenv": "^5.4 || ^6.0",
45+
"symfony/intl": "^5.4 || ^6.0",
46+
"symfony/web-profiler-bundle": "^5.4 || ^6.0",
47+
"league/flysystem-bundle": "2.4.0"
4948
},
5049
"conflict": {
51-
"sylius/resource-bundle": "1.9.1 || 1.9.0",
52-
"doctrine/orm": ">=2.15.2"
50+
"sylius/resource-bundle": "1.9.1 || 1.9.0"
5351
},
5452
"config": {
5553
"sort-packages": true,

phpstan.neon

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
parameters:
22
reportUnmatchedIgnoredErrors: false
33
checkMissingIterableValueType: false
4+
level: 8
45

5-
excludes_analyse:
6+
paths:
7+
- 'src'
8+
9+
excludePaths:
610
# Makes PHPStan crash
711
- 'src/DependencyInjection/Configuration.php'
812

9-
# Test dependencies
10-
- 'tests/Application/*'
11-
12-
# ECS Fixer dependency
13-
- 'src/Fixer'
14-
1513
ignoreErrors:
1614
- '/Parameter #1 \$configuration of method Symfony\\Component\\DependencyInjection\\Extension\\Extension::processConfiguration\(\) expects Symfony\\Component\\Config\\Definition\\ConfigurationInterface, Symfony\\Component\\Config\\Definition\\ConfigurationInterface\|null given\./'

spec/EventListener/ShippingExportEventListenerSpec.php

+11-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
use Sylius\Component\Core\Model\Order;
1313
use Sylius\Component\Core\Model\ShipmentInterface;
1414
use Symfony\Component\Filesystem\Filesystem;
15+
use Symfony\Component\HttpFoundation\RequestStack;
1516
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
17+
use Symfony\Component\HttpFoundation\Session\Session;
18+
use Symfony\Component\HttpFoundation\Session\SessionInterface;
1619

1720
final class ShippingExportEventListenerSpec extends ObjectBehavior
1821
{
@@ -23,12 +26,12 @@ function it_is_initializable()
2326

2427
function let (
2528
WebClientInterface $webClient,
26-
FlashBagInterface $flashBag,
29+
RequestStack $requestStack,
2730
Filesystem $filesystem,
2831
ObjectManager $objectManager
2932
) {
3033
$shippingLabelsPath = 'labels';
31-
$this->beConstructedWith($webClient, $flashBag, $filesystem, $objectManager, $shippingLabelsPath);
34+
$this->beConstructedWith($webClient, $requestStack, $filesystem, $objectManager, $shippingLabelsPath);
3235
}
3336

3437
function it_export_shipment
@@ -38,10 +41,15 @@ function it_export_shipment
3841
ShippingGatewayInterface $shippingGateway,
3942
ShipmentInterface $shipment,
4043
WebClientInterface $webClient,
41-
Order $order
44+
Order $order,
45+
RequestStack $requestStack,
46+
Session $session,
47+
FlashBagInterface $flashBag,
4248
)
4349
{
4450
$webClient->setShippingGateway($shippingGateway);
51+
$requestStack->getSession()->willReturn($session);
52+
$session->getFlashBag()->willReturn($flashBag);
4553

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

src/Api/WebClient.php

+3-14
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ final class WebClient implements WebClientInterface
1919
{
2020
public const DATE_FORMAT = 'Y-m-d';
2121

22-
/** @var ShippingGatewayInterface */
23-
private $shippingGateway;
22+
private ShippingGatewayInterface $shippingGateway;
2423

25-
/** @var ShipmentInterface */
26-
private $shipment;
24+
private ShipmentInterface $shipment;
2725

2826
public function setShippingGateway(ShippingGatewayInterface $shippingGateway): void
2927
{
@@ -123,14 +121,6 @@ public function getPickupAddress(): array
123121
{
124122
return [
125123
'fid' => $this->getShippingGatewayConfig('id'),
126-
// 'name' => 'NAME',
127-
// 'company' => 'COMPANY',
128-
// 'address' => 'ADDRESS',
129-
// 'city' => 'CITY',
130-
// 'postalCode' => '85132',
131-
// 'countryCode' => 'PL',
132-
// 'email'=> 'test@test.test',
133-
// 'phone' => '777888999',
134124
];
135125
}
136126

@@ -214,8 +204,7 @@ private function resolveWeekend(\DateTime $date): \DateTime
214204
return $date;
215205
}
216206

217-
/** @return mixed */
218-
private function getShippingGatewayConfig(string $config)
207+
private function getShippingGatewayConfig(string $config): mixed
219208
{
220209
return $this->shippingGateway->getConfigValue($config);
221210
}

src/EventListener/ShippingExportEventListener.php

+15-17
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
use BitBag\SyliusShippingExportPlugin\Entity\ShippingExportInterface;
1515
use Doctrine\Persistence\ObjectManager;
1616
use DPD\Services\DPDService;
17-
use http\Exception\InvalidArgumentException;
17+
use Exception;
1818
use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent;
1919
use Symfony\Component\Filesystem\Filesystem;
20-
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
20+
use Symfony\Component\HttpFoundation\RequestStack;
21+
use Symfony\Component\HttpFoundation\Session\Session;
2122
use Webmozart\Assert\Assert;
2223

2324
final class ShippingExportEventListener
@@ -26,30 +27,25 @@ final class ShippingExportEventListener
2627

2728
public const BASE_LABEL_EXTENSION = 'pdf';
2829

29-
/** @var WebClientInterface */
30-
private $webClient;
30+
private WebClientInterface $webClient;
3131

32-
/** @var FlashBagInterface */
33-
private $flashBag;
32+
private RequestStack $requestStack;
3433

35-
/** @var Filesystem */
36-
private $fileSystem;
34+
private Filesystem $fileSystem;
3735

38-
/** @var ObjectManager */
39-
private $shippingExportManager;
36+
private ObjectManager $shippingExportManager;
4037

41-
/** @var string */
42-
private $shippingLabelsPath;
38+
private string $shippingLabelsPath;
4339

4440
public function __construct(
4541
WebClientInterface $webClient,
46-
FlashBagInterface $flashBag,
42+
RequestStack $requestStack,
4743
FileSystem $fileSystem,
4844
ObjectManager $shippingExportManager,
4945
string $shippingLabelsPath
5046
) {
5147
$this->webClient = $webClient;
52-
$this->flashBag = $flashBag;
48+
$this->requestStack = $requestStack;
5349
$this->fileSystem = $fileSystem;
5450
$this->shippingExportManager = $shippingExportManager;
5551
$this->shippingLabelsPath = $shippingLabelsPath;
@@ -75,6 +71,8 @@ public function exportShipment(ResourceControllerEvent $exportShipmentEvent): vo
7571
Assert::notNull($shipment);
7672

7773
$this->webClient->setShipment($shipment);
74+
/** @var Session $session */
75+
$session = $this->requestStack->getSession();
7876

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

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

102-
$this->flashBag->add('success', 'bitbag.ui.shipment_data_has_been_exported');
100+
$session->getFlashBag()->add('success', 'bitbag.ui.shipment_data_has_been_exported');
103101
$this->saveShippingLabel($shippingExport, $speedLabel->filedata, self::BASE_LABEL_EXTENSION); /** @phpstan-ignore-line */
104102
$this->markShipmentAsExported($shippingExport);
105103
}

src/Resources/config/config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
imports:
2+
- { resource: "@BitBagSyliusShippingExportPlugin/Resources/config/config.yml" }
23
- { resource: "@DpdPlShippingExportPlugin/Resources/config/services.yml" }

src/Resources/config/services.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ services:
88
class: BitBag\DpdPlShippingExportPlugin\EventListener\ShippingExportEventListener
99
arguments:
1010
- '@bitbag.dpd_pl_shipping_export_plugin.api.web_client'
11-
- '@session.flash_bag'
11+
- '@request_stack'
1212
- '@filesystem'
1313
- '@bitbag.manager.shipping_export'
1414
- '%bitbag.shipping_labels_path%'

tests/Application/.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/public/assets
2+
/public/build
23
/public/css
34
/public/js
45
/public/media/*
@@ -19,4 +20,4 @@
1920

2021
###> symfony/web-server-bundle ###
2122
/.web-server-pid
22-
###< symfony/web-server-bundle ###
23+
###< symfony/web-server-bundle ###

0 commit comments

Comments
 (0)