Skip to content

Commit

Permalink
feature #736 Add Support for Symfony 6 (TheMilek)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.6 branch.

Discussion
----------

continuation of / to potential merge after merging #734

Commits
-------

ea5dee9 Support symfony 6
162af39 Fix PHPStan
  • Loading branch information
GSadee authored Jan 12, 2023
2 parents 5eb9811 + 162af39 commit 95043cc
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 19 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ jobs:
fail-fast: false
matrix:
php: ["8.0", "8.1"]
symfony: ["^5.4"]
symfony: ["^5.4", "^6.0"]
sylius: ["~1.11.10", "~1.12.0"]
node: ["16.x"]
mysql: ["5.7", "8.0"]

exclude:
- sylius: "~1.11.10"
symfony: "^6.0"

env:
APP_ENV: test
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"php": "^8.0",
"sylius/sylius": "~1.11.10 || ~1.12.0",
"lexik/jwt-authentication-bundle": "^2.5",
"symfony/messenger": "^5.4",
"symfony/messenger": "^5.4 || ^6.0",
"doctrine/doctrine-bundle": "^2.0"
},
"require-dev": {
Expand All @@ -19,9 +19,9 @@
"phpstan/phpstan-webmozart-assert": "^1.2",
"phpunit/phpunit": "^9.0",
"sylius-labs/coding-standard": "^4.0",
"symfony/debug-bundle": "^5.4",
"symfony/dotenv": "^5.4",
"symfony/web-profiler-bundle": "^5.4",
"symfony/debug-bundle": "^5.4 || ^6.0",
"symfony/dotenv": "^5.4 || ^6.0",
"symfony/web-profiler-bundle": "^5.4 || ^6.0",
"symfony/webpack-encore-bundle": "^1.15"
},
"autoload": {
Expand Down
4 changes: 0 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ parameters:
ignoreErrors:
- /^Access to an undefined property Symfony\\Component\\Validator\\Constraint::\$message\.$/
- '/Sylius\\Component\\Core\\Model\\(\w+), Sylius\\Component\\\w+\\Model\\\1 given\./'
- '/Empty array passed to foreach./'
- '/Property Sylius\\ShopApiPlugin\\Request\\Checkout\\AddressOrderRequest::\$\w+Address \(array\|null\) does not accept bool\|float\|int\|string\|null\./'
- '/Property Sylius\\ShopApiPlugin\\Request\\Customer\\UpdateCustomerRequest::\$birthday \(DateTimeImmutable\|null\) does not accept bool\|float\|int\|string\|null\./'
- '/Parameter #3 \$options of class Sylius\\ShopApiPlugin\\Request\\Cart\\PutOptionBasedConfigurableItemToCartRequest constructor expects array\|null, bool\|float\|int\|string\|null given\./'
- '/Argument of an invalid type bool\|float\|int\|string supplied for foreach, only iterables are supported\./'
- '/^Property Sylius\\ShopApiPlugin\\Request\\Cart\\(\w+)\:\:\$productCode \(string\) on left side of \?\? is not nullable\./'
- '/^Expression on left side of \?\? is not nullable\./'
2 changes: 1 addition & 1 deletion src/Controller/Cart/PutItemsToCartAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function __invoke(Request $request): Response

$token = $request->attributes->get('token');

foreach ($request->request->get('items') as $item) {
foreach ($request->request->all('items') as $item) {
$item['token'] = $token;
$commandRequests[] = $this->provideCommandRequest($item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static function fromHttpRequest(Request $request): RequestInterface
return new self(
$request->attributes->get('token'),
$request->request->get('productCode'),
$request->request->get('options'),
$request->request->all('options'),
$request->request->getInt('quantity', 1),
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Request/Checkout/AddressOrderRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class AddressOrderRequest implements RequestInterface
protected function __construct(Request $request)
{
$this->token = $request->attributes->get('token');
$this->shippingAddress = $request->request->get('shippingAddress');
$this->billingAddress = $request->request->get('billingAddress') ?: $request->request->get('shippingAddress');
$this->shippingAddress = $request->request->all('shippingAddress');
$this->billingAddress = $request->request->all('billingAddress') ?: $request->request->all('shippingAddress');
}

public static function fromHttpRequest(Request $request): RequestInterface
Expand Down
13 changes: 11 additions & 2 deletions tests/Controller/AddressBook/CreateAddressApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Sylius\Component\Core\Repository\AddressRepositoryInterface;
use Sylius\Component\Core\Repository\CustomerRepositoryInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Kernel;
use Tests\Sylius\ShopApiPlugin\Controller\JsonApiTestCase;
use Tests\Sylius\ShopApiPlugin\Controller\Utils\ShopUserLoginTrait;

Expand Down Expand Up @@ -110,7 +111,11 @@ public function it_does_not_allow_user_to_add_new_address_to_address_book_withou
JSON;

$response = $this->createAddress($data);
$this->assertResponse($response, 'address_book/validation_create_address_book_with_wrong_country_response', Response::HTTP_BAD_REQUEST);
if (Kernel::VERSION_ID < 60000) {
$this->assertResponse($response, 'address_book/SF5/validation_create_address_book_with_wrong_country_response', Response::HTTP_BAD_REQUEST);
} else {
$this->assertResponse($response, 'address_book/SF6/validation_create_address_book_with_wrong_country_response', Response::HTTP_BAD_REQUEST);
}
}

/**
Expand All @@ -135,7 +140,11 @@ public function it_does_not_allow_user_to_add_new_address_to_address_book_withou
JSON;

$response = $this->createAddress($data);
$this->assertResponse($response, 'address_book/validation_create_address_book_with_wrong_province_response', Response::HTTP_BAD_REQUEST);
if (Kernel::VERSION_ID < 60000) {
$this->assertResponse($response, 'address_book/SF5/validation_create_address_book_with_wrong_province_response', Response::HTTP_BAD_REQUEST);
} else {
$this->assertResponse($response, 'address_book/SF6/validation_create_address_book_with_wrong_province_response', Response::HTTP_BAD_REQUEST);
}
}

private function createAddress(string $data): Response
Expand Down
5 changes: 5 additions & 0 deletions tests/Controller/Checkout/CompleteOrderApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ final class CompleteOrderApiTest extends JsonApiTestCase
use ShopUserLoginTrait;
use MailerAssertionsTrait;

protected function setUp(): void
{
$this->setUpClient();
}

/**
* @test
*/
Expand Down
3 changes: 0 additions & 3 deletions tests/Controller/Utils/MailerAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ trait MailerAssertionsTrait
{
private static ContainerInterface $clientContainer;

/**
* @before
*/
public function setUpClient(): void
{
parent::setUpClient();
Expand Down
6 changes: 5 additions & 1 deletion tests/Controller/Utils/PurgeMessagesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ trait PurgeMessagesTrait
{
private static ?string $poolDirectory = null;

use MailerAssertionsTrait;

/**
* @before
*/
public function purgeMessages(): void
{
$this->setUpClient();

/** @var Filesystem $filesystem */
$filesystem = $this->getContainer()->get('filesystem');
$filesystem = self::$clientContainer->get('filesystem');

$filesystem->remove($this->getContainer()->getParameter('kernel.cache_dir') . '/pools');
$filesystem->remove($this->getContainer()->getParameter('kernel.cache_dir') . '/spool');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"code": 400,
"message": "Validation Failed",
"errors": {
"errors": [
"Please select proper province."
],
"children": {
"firstName": {},
"lastName": {},
"phoneNumber": {},
"company": {},
"countryCode": {},
"street": {},
"city": {},
"postcode": {},
"provinceCode": {
"errors": [
"This value is not valid."
]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"code": 400,
"message": "Validation Failed",
"errors": {
"children": {
"firstName": [],
"lastName": [],
"phoneNumber": [],
"company": [],
"countryCode": {
"errors": [
"The selected choice is invalid."
]
},
"street": [],
"city": [],
"postcode": []
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"code": 400,
"message": "Validation Failed",
"errors": {
"errors": [
"Please select proper province."
],
"children": {
"firstName": [],
"lastName": [],
"phoneNumber": [],
"company": [],
"countryCode": [],
"street": [],
"city": [],
"postcode": [],
"provinceCode": {
"errors": [
"The selected choice is invalid."
]
}
}
}
}

0 comments on commit 95043cc

Please sign in to comment.