Skip to content

Commit

Permalink
Merge pull request #69 from SzymonKostrubiec/op-266
Browse files Browse the repository at this point in the history
OP-266 - Sylius 1.13 support
  • Loading branch information
senghe authored Aug 1, 2024
2 parents 0853cf3 + 0a0b5fc commit b2323e0
Show file tree
Hide file tree
Showing 34 changed files with 193 additions and 154 deletions.
34 changes: 17 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,20 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [8.0 ]
symfony: [^5.4, ^6.0]
sylius: [~1.11.0, ~1.12.0]
node: [14.19]
mysql: [5.7, 8.0]
php: ["8.1", "8.2", "8.3"]
symfony: ["^5.4", "^6.0"]
sylius: ["~1.12.0", "~1.13.0"]
node: ["18.x", "20.x"]
mysql: ["5.7", "8.0"]

exclude:
-
sylius: ~1.11.0
symfony: ^6.0

env:
APP_ENV: test
DATABASE_URL: "mysql://root:[email protected]/sylius?serverVersion=${{ matrix.mysql }}"

steps:
-
uses: actions/checkout@v2
uses: actions/checkout@v3

-
name: Setup PHP
Expand All @@ -51,7 +47,7 @@ jobs:

-
name: Setup Node
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: "${{ matrix.node }}"

Expand Down Expand Up @@ -89,7 +85,7 @@ jobs:

-
name: Cache Composer
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json **/composer.lock') }}
Expand All @@ -114,7 +110,7 @@ jobs:
-
name: Get Yarn cache directory
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

-
name: Cache Yarn
Expand Down Expand Up @@ -154,6 +150,10 @@ jobs:
name: Validate database schema
run: (cd tests/Application && bin/console doctrine:schema:validate)

-
name: Run ECS
run: vendor/bin/ecs check src

-
name: Run PHPStan
run: vendor/bin/phpstan analyse -c phpstan.neon -l 7 src/
Expand All @@ -166,20 +166,20 @@ jobs:
-
name: Run Behat
env:
MAIL_CHIMP_API_KEY: ${{ secrets.MAILCHIMP_API_TOKEN }}
MAIL_CHIMP_LIST_ID: ${{ secrets.MAIL_CHIMP_LIST_ID }}
MAIL_CHIMP_API_KEY: "mailchimp-api-key"
MAIL_CHIMP_LIST_ID: "mailchimp-list-id"
MAIL_CHIMP_WEBHOOK_SECRET: ${{ secrets.MAIL_CHIMP_WEBHOOK_SECRET }}
run: vendor/bin/behat --colors --strict -vvv --no-interaction || vendor/bin/behat --colors --strict -vvv --no-interaction --rerun

-
name: Upload Behat logs
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
if: failure()
with:
name: Behat logs
path: etc/build/
if-no-files-found: ignore

-
name: Failed build Slack notification
uses: rtCamp/action-slack-notify@v2
Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"description": "MailChimp plugin for Sylius.",
"license": "MIT",
"require": {
"php": " ^8.0",
"sylius/sylius": "~1.11.0 || ~1.12.0",
"drewm/mailchimp-api": "^v2.5.4",
"php": " ^8.1",
"sylius/sylius": "~1.12.0 || ~1.13.0",
"drewm/mailchimp-api": "^2.5.4",
"ext-json": "*",
"symfony/webpack-encore-bundle": "^1.16"
},
"require-dev": {
"behat/behat": "^3.6.1",
"behat/mink-selenium2-driver": "^1.4",
"behat/behat": "^3.7",
"behat/mink-selenium2-driver": "~1.6.0",
"dmore/behat-chrome-extension": "^1.3",
"dmore/chrome-mink-driver": "^2.7",
"friends-of-behat/mink": "^1.8",
Expand All @@ -39,8 +39,8 @@
"bitbag/coding-standard": "^1.0.0 || ^2.0.0"
},
"conflict": {
"doctrine/orm": ">=2.15.2"
},
"doctrine/orm": ">=2.15.2"
},
"prefer-stable": true,
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion doc/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Add these javascripts to the layout template that includes your subscription for

Clear project cache:
```php
bin/console cache:clear
bin/console cache:clear # if there is an issue with translations displaying correctly, clear the cache again.
```

Update your webpack build:
Expand Down
10 changes: 7 additions & 3 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

declare(strict_types=1);

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import('vendor/sylius-labs/coding-standard/ecs.php');
return static function (ECSConfig $config): void {

putenv('ALLOW_BITBAG_OS_HEADER=1');

$config->import('vendor/bitbag/coding-standard/ecs.php');
$config->paths(['src', 'tests']);
};
6 changes: 3 additions & 3 deletions src/Controller/MailchimpController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ final class MailchimpController
public function __construct(
WebhookValidator $validator,
NewsletterSubscriptionInterface $handler,
TranslatorInterface $translator
) {
TranslatorInterface $translator,
) {
$this->validator = $validator;
$this->handler = $handler;
$this->translator = $translator;
Expand All @@ -43,7 +43,7 @@ public function webhookAction(Request $request): JsonResponse
$webhookData = WebhookData::createFromRequest($request);
$errors = $this->validateRequest($webhookData, $request);

if (count($errors) === 0) {
if (0 === count($errors)) {
$this->handler->unsubscribeCustomerFromLocalDatabase($webhookData->getData()['email']);

return new JsonResponse([
Expand Down
6 changes: 3 additions & 3 deletions src/Controller/NewsletterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public function __construct(
NewsletterValidator $validator,
TranslatorInterface $translator,
NewsletterSubscriptionInterface $handler,
CsrfTokenManager $tokenManager
) {
CsrfTokenManager $tokenManager,
) {
$this->validator = $validator;
$this->translator = $translator;
$this->handler = $handler;
Expand All @@ -65,7 +65,7 @@ public function subscribeAction(Request $request): JsonResponse
$errors[] = $this->translator->trans('bitbag_sylius_mailchimp_plugin.ui.invalid_csrf_token');
}

if (count($errors) === 0) {
if (0 === count($errors)) {
$this->handler->subscribe($email);

return new JsonResponse([
Expand Down
6 changes: 3 additions & 3 deletions src/EventListener/CustomerNewsletterListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public function customerCreateEvent(GenericEvent $event): void
if (!$customer instanceof CustomerInterface) {
throw new UnexpectedTypeException(
$customer,
CustomerInterface::class
CustomerInterface::class,
);
}

$customer->isSubscribedToNewsletter() === false ? $this->unsubscribe($customer) : $this->subscribe($customer);
false === $customer->isSubscribedToNewsletter() ? $this->unsubscribe($customer) : $this->subscribe($customer);
}

public function customerPostUpdateEvent(GenericEvent $event): void
Expand All @@ -62,7 +62,7 @@ public function customerPreUpdateEvent(GenericEvent $event): void
if (!$customer instanceof CustomerInterface) {
throw new UnexpectedTypeException(
$customer,
CustomerInterface::class
CustomerInterface::class,
);
}

Expand Down
22 changes: 11 additions & 11 deletions src/Handler/NewsletterSubscriptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public function __construct(
FactoryInterface $customerFactory,
EntityManagerInterface $customerManager,
MailChimp $mailChimp,
string $listId
) {
string $listId,
) {
$this->customerRepository = $customerRepository;
$this->customerFactory = $customerFactory;
$this->customerManager = $customerManager;
Expand Down Expand Up @@ -128,14 +128,14 @@ private function exportNewEmail(string $email): void
throw new BadRequestHttpException(
sprintf(
'Mailchimp returned false instead of response array, last error : %s',
$this->mailChimp->getLastError()
)
$this->mailChimp->getLastError(),
),
);
}

Assert::keyExists($response, 'status');

if ($response['status'] === Response::HTTP_NOT_FOUND) {
if (Response::HTTP_NOT_FOUND === $response['status']) {
$validListIds = $this->getValidMailchimpListIds();
$concatenatedList = implode(',', $validListIds);

Expand All @@ -144,13 +144,13 @@ private function exportNewEmail(string $email): void
'Mailchimp returned %1$d code, is the MAIL_CHIMP_LIST_ID [ %2$s ] one of available ones: [ %3$s ] ?',
Response::HTTP_NOT_FOUND,
$this->listId,
$concatenatedList
)
$concatenatedList,
),
);
}
if ($response['status'] !== 'subscribed') {
if ('subscribed' !== $response['status']) {
throw new BadRequestHttpException(
sprintf('Response status is %s instead of %s', $response['status'], 'subscribed')
sprintf('Response status is %s instead of %s', $response['status'], 'subscribed'),
);
}
}
Expand All @@ -174,8 +174,8 @@ protected function addMailchimpData(string $email): void
throw new BadRequestHttpException(
sprintf(
'Mailchimp returned false instead of response array, last error : %s',
$this->mailChimp->getLastError()
)
$this->mailChimp->getLastError(),
),
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Model/WebhookData.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ final class WebhookData
public function __construct(
string $type,
string $firedAt,
array $data
) {
array $data,
) {
$this->type = $type;
$this->firedAt = $firedAt;
$this->data = $data;
Expand All @@ -55,7 +55,7 @@ public static function createFromRequest(Request $request): self
return new self(
$request->get('type', self::TYPE_UNSUBSCRIBE),
$request->get('fired_at', $dateString),
$request->get('data', [])
$request->get('data', []),
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Validator/Constraints/UniqueNewsletterEmailValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function validate($value, Constraint $constraint): void
{
Assert::isInstanceOf($constraint, UniqueNewsletterEmail::class);

if ($this->isEmailValid($value) === false) {
if (false === $this->isEmailValid($value)) {
$this->context->addViolation($constraint->message);
}
}
Expand All @@ -43,11 +43,11 @@ private function isEmailValid(?string $email): bool
{
$customer = $this->customerRepository->findOneBy(['email' => $email]);

if ($customer instanceof CustomerInterface === false) {
if (false === $customer instanceof CustomerInterface) {
return true;
}

if ($customer->isSubscribedToNewsletter() === true) {
if (true === $customer->isSubscribedToNewsletter()) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Validator/NewsletterValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function validate(?string $email): array

$errors = [];

if (count($violations) === 0) {
if (0 === count($violations)) {
return $errors;
}

Expand Down
9 changes: 6 additions & 3 deletions src/Validator/WebhookValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ final class WebhookValidator
/** @var string */
private $webhookSecret;

public function __construct(ValidatorInterface $validator, string $listId, string $webhookSecret)
{
public function __construct(
ValidatorInterface $validator,
string $listId,
string $webhookSecret
) {
$this->validator = $validator;
$this->listId = $listId;
$this->webhookSecret = $webhookSecret;
Expand Down Expand Up @@ -66,7 +69,7 @@ public function validate(WebhookData $webhookData): array

$errors = [];

if (count($violations) === 0) {
if (0 === count($violations)) {
return $errors;
}

Expand Down
11 changes: 11 additions & 0 deletions tests/Application/.env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
APP_ENV=test
APP_SECRET='ch4mb3r0f5ecr3ts'

DATABASE_URL=sqlite:///%kernel.project_dir%/var/data_%kernel.environment%.db

JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem
JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem
JWT_PASSPHRASE=acme_plugin_development

MAIL_CHIMP_API_KEY="mailchimp-api-key"
MAIL_CHIMP_LIST_ID="mailchimp-list-id"
6 changes: 5 additions & 1 deletion tests/Application/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,9 @@
Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true],
Sylius\Bundle\ApiBundle\SyliusApiBundle::class => ['all' => true],
SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true],
Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true]
Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true],
Sylius\Calendar\SyliusCalendarBundle::class => ['all' => true],
League\FlysystemBundle\FlysystemBundle::class => ['all' => true],
BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true],
SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true],
];
16 changes: 0 additions & 16 deletions tests/Application/config/sylius/1.11/bundles.php

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit b2323e0

Please sign in to comment.