From 0580eb077af78f8acabd9e5842df43cf1fba1622 Mon Sep 17 00:00:00 2001 From: janpalen Date: Thu, 8 Aug 2024 08:37:31 +0200 Subject: [PATCH 1/3] OP-359 - Update builds, dependencies and coding standard --- .github/workflows/build.yml | 59 ++++++++----------- .github/workflows/coding_standard.yml | 85 +++++++++++++++++++++++++++ composer.json | 3 +- tests/Application/.env | 2 +- 4 files changed, 112 insertions(+), 37 deletions(-) create mode 100644 .github/workflows/coding_standard.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ed85ea5..aeb2763 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,28 +8,27 @@ on: release: types: [created] schedule: - - - cron: "0 1 * * 6" # Run at 1am every Saturday + - cron: "0 1 * * 6" # Run at 1am every Saturday workflow_dispatch: ~ jobs: tests: runs-on: ubuntu-latest - + name: "Sylius ${{ matrix.sylius }}, PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, MySQL ${{ matrix.mysql }}" - + strategy: fail-fast: false matrix: - php: [8.0, 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] - + php: [ "8.1", "8.2", "8.3" ] + symfony: [ "^5.4", "^6.4" ] + sylius: [ "^1.13" ] + node: [ "18.x", "20.x" ] + mysql: [ "8.0" ] + exclude: - - sylius: "~1.13.0" - php: "8.0" + - sylius: ^1.13 + php: 8.0 env: APP_ENV: test @@ -84,17 +83,16 @@ jobs: - name: Get Composer cache directory id: composer-cache - run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT" + run: echo "::set-output name=dir::$(composer config cache-files-dir)" - 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') }} restore-keys: | ${{ runner.os }}-php-${{ matrix.php }}-composer- - - name: Restrict Symfony version if: matrix.symfony != '' @@ -102,7 +100,6 @@ jobs: composer global config --no-plugins allow-plugins.symfony/flex true composer global require --no-progress --no-scripts --no-plugins "symfony/flex:^1.10" composer config extra.symfony.require "${{ matrix.symfony }}" - - name: Restrict Sylius version if: matrix.sylius != '' @@ -111,21 +108,22 @@ jobs: - name: Install PHP dependencies run: composer install --no-interaction + env: + SYMFONY_REQUIRE: ${{ matrix.symfony }} - name: Get Yarn cache directory id: yarn-cache - run: echo "dir=$(yarn cache dir)" >> "$GITHUB_OUTPUT" + run: echo "::set-output name=dir::$(yarn cache dir)" - name: Cache Yarn - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ${{ steps.yarn-cache.outputs.dir }} key: ${{ runner.os }}-node-${{ matrix.node }}-yarn-${{ hashFiles('**/package.json **/yarn.lock') }} restore-keys: | ${{ runner.os }}-node-${{ matrix.node }}-yarn- - - name: Install JS dependencies run: (cd tests/Application && yarn install) @@ -135,13 +133,11 @@ jobs: run: | (cd tests/Application && bin/console doctrine:database:create -vvv) (cd tests/Application && bin/console doctrine:schema:create -vvv) - - name: Prepare test application assets run: | (cd tests/Application && bin/console assets:install public -vvv) (cd tests/Application && yarn encore dev) - - name: Prepare test application cache run: (cd tests/Application && bin/console cache:warmup -vvv) @@ -158,22 +154,17 @@ jobs: name: Validate database schema run: (cd tests/Application && bin/console doctrine:schema:validate) - - - name: Run PHPStan - run: vendor/bin/phpstan analyse -c phpstan.neon -l 8 src/ - -# TODO: Temporary disabled! -# - -# name: Run Psalm -# run: vendor/bin/psalm - - name: Run PHPSpec run: vendor/bin/phpspec run --ansi -f progress --no-interaction -# - -# name: Run PHPUnit -# run: vendor/bin/phpunit --colors=always + - + name: Run PHPUnit + run: vendor/bin/phpunit --colors=always + + - + name: Create behat logs directory + run: (mkdir -p etc/build && chmod a+rw etc/build ) - name: Run Behat @@ -181,7 +172,7 @@ jobs: - name: Upload Behat logs - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 if: failure() with: name: Behat logs diff --git a/.github/workflows/coding_standard.yml b/.github/workflows/coding_standard.yml new file mode 100644 index 0000000..328d4ed --- /dev/null +++ b/.github/workflows/coding_standard.yml @@ -0,0 +1,85 @@ +name: Coding standard + +on: + push: + branches-ignore: + - 'dependabot/**' + pull_request: ~ + release: + types: [ created ] + workflow_dispatch: ~ + +jobs: + tests: + runs-on: ubuntu-latest + + name: "Sylius ${{ matrix.sylius }}, PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}" + + strategy: + fail-fast: false + matrix: + php: [ "8.1", "8.2", "8.3" ] + symfony: [ "^5.4", "^6.4" ] + sylius: [ "^1.13" ] + node: [ "18.x", "20.x" ] + + exclude: + - sylius: ^1.13 + php: 8.0 + + steps: + - uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "${{ matrix.php }}" + extensions: intl + tools: symfony + coverage: none + + - name: Get Composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache Composer + uses: actions/cache@v4 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json', '**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php-${{ matrix.php }}-composer- + + - name: Restrict Symfony version + if: matrix.symfony != '' + run: | + composer global config --no-plugins allow-plugins.symfony/flex true + composer global require --no-progress --no-scripts --no-plugins "symfony/flex:^1.10" + composer config extra.symfony.require "${{ matrix.symfony }}" + + - name: Restrict Sylius version + if: matrix.sylius != '' + run: composer require "sylius/sylius:${{ matrix.sylius }}" --no-update --no-scripts --no-interaction + + - name: Install PHP dependencies + run: composer install --no-interaction + env: + SYMFONY_REQUIRE: ${{ matrix.symfony }} + + - name: Run PHPStan + run: vendor/bin/phpstan analyse -c phpstan.neon -l 8 src/ + + - name: Run ECS + run: vendor/bin/ecs check src + + - name: Failed build Slack notification + uses: rtCamp/action-slack-notify@v2 + if: ${{ failure() && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') }} + env: + SLACK_CHANNEL: ${{ secrets.FAILED_BUILD_SLACK_CHANNEL }} + SLACK_COLOR: ${{ job.status }} + SLACK_ICON: https://github.com/rtCamp.png?size=48 + SLACK_MESSAGE: ':x:' + SLACK_TITLE: Failed build on ${{ github.event.repository.name }} repository + SLACK_USERNAME: ${{ secrets.FAILED_BUILD_SLACK_USERNAME }} + SLACK_WEBHOOK: ${{ secrets.FAILED_BUILD_SLACK_WEBHOOK }} diff --git a/composer.json b/composer.json index 996d680..234e10d 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "behat/behat": "^3.7", "behat/mink-selenium2-driver": "~1.6.0", "symfony/webpack-encore-bundle": "^1.15", - "bitbag/coding-standard": "^1.0.1 || ^2.0.0", + "bitbag/coding-standard": "^3.0", "dmore/behat-chrome-extension": "^1.3", "dmore/chrome-mink-driver": "^2.7", "friends-of-behat/mink": "^1.8", @@ -36,7 +36,6 @@ "symfony/dotenv": "^5.4 || ^6.0", "symfony/intl": "^5.4 || ^6.0", "symfony/web-profiler-bundle": "^5.4 || ^6.0", - "vimeo/psalm": "4.7.1 || ^5.0.0", "polishsymfonycommunity/symfony-mocker-container": "^1.0" }, "conflict": { diff --git a/tests/Application/.env b/tests/Application/.env index 27563a1..cb9bd21 100755 --- a/tests/Application/.env +++ b/tests/Application/.env @@ -12,7 +12,7 @@ APP_SECRET=EDITME # Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url # For a sqlite database, use: "sqlite:///%kernel.project_dir%/var/data.db" # Set "serverVersion" to your server version to avoid edge-case exceptions and extra database calls -DATABASE_URL=mysql://root@127.0.0.1/sylius_%kernel.environment%?serverVersion=5.5 +DATABASE_URL=mysql://root@127.0.0.1/shipping_export_%kernel.environment%?serverVersion=8.0 ###< doctrine/doctrine-bundle ### ###> symfony/swiftmailer-bundle ### From ec17ae462e0b829b2dc4889377841d2d86afaab9 Mon Sep 17 00:00:00 2001 From: janpalen Date: Thu, 8 Aug 2024 08:38:03 +0200 Subject: [PATCH 2/3] OP-359 - Fix ecs --- .github/workflows/build.yml | 7 ++++-- .github/workflows/coding_standard.yml | 8 +++++-- ecs.php | 22 +++++-------------- src/BitBagSyliusShippingExportPlugin.php | 9 ++++---- src/Context/ShippingGatewayContext.php | 15 +++++++------ .../ShippingGatewayContextInterface.php | 9 ++++---- src/Controller/ShippingExportController.php | 13 ++++++----- .../ShippingExportDownloadLabelAction.php | 15 +++++++------ .../RegisterShippingGatewayConfigTypePass.php | 11 +++++----- src/Entity/ShippingExport.php | 9 ++++---- src/Entity/ShippingExportInterface.php | 9 ++++---- src/Entity/ShippingGateway.php | 11 +++++----- src/Entity/ShippingGatewayInterface.php | 9 ++++---- src/Event/ExportShipmentEvent.php | 11 +++++----- .../AdminShippingGatewayGridEventListener.php | 9 ++++---- ...PlacingShipmentForGatewayEventListener.php | 11 +++++----- .../ShippingGatewayLabelNotFound.php | 11 +++++----- .../ShippingGatewayNotFoundException.php | 9 ++++---- src/Form/Type/ShippingGatewayType.php | 13 ++++++----- src/Menu/ShippingExportMenuBuilder.php | 9 ++++---- src/Menu/ShippingGatewayMenuBuilder.php | 9 ++++---- src/Repository/ShippingExportRepository.php | 9 ++++---- .../ShippingExportRepositoryInterface.php | 9 ++++---- src/Repository/ShippingGatewayRepository.php | 9 ++++---- .../ShippingGatewayRepositoryInterface.php | 10 ++++----- 25 files changed, 142 insertions(+), 124 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index aeb2763..8fcfa67 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,15 +20,18 @@ jobs: strategy: fail-fast: false matrix: - php: [ "8.1", "8.2", "8.3" ] + php: [ "8.0", "8.1", "8.2", "8.3" ] symfony: [ "^5.4", "^6.4" ] - sylius: [ "^1.13" ] + sylius: [ "^1.12", "^1.13" ] node: [ "18.x", "20.x" ] mysql: [ "8.0" ] exclude: - sylius: ^1.13 php: 8.0 + - sylius: ^1.12 + php: 8.0 + symfony: ^6.4 env: APP_ENV: test diff --git a/.github/workflows/coding_standard.yml b/.github/workflows/coding_standard.yml index 328d4ed..144689b 100644 --- a/.github/workflows/coding_standard.yml +++ b/.github/workflows/coding_standard.yml @@ -18,14 +18,18 @@ jobs: strategy: fail-fast: false matrix: - php: [ "8.1", "8.2", "8.3" ] + php: [ "8.0", "8.1", "8.2", "8.3" ] symfony: [ "^5.4", "^6.4" ] - sylius: [ "^1.13" ] + sylius: [ "^1.12", "^1.13" ] node: [ "18.x", "20.x" ] + mysql: [ "8.0" ] exclude: - sylius: ^1.13 php: 8.0 + - sylius: ^1.12 + php: 8.0 + symfony: ^6.4 steps: - uses: actions/checkout@v3 diff --git a/ecs.php b/ecs.php index 8c449af..abcfbcf 100644 --- a/ecs.php +++ b/ecs.php @@ -2,22 +2,12 @@ declare(strict_types=1); -use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer; -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; -use Symplify\EasyCodingStandard\ValueObject\Option; -use Symplify\EasyCodingStandard\ValueObject\Set\SetList; +use Symplify\EasyCodingStandard\Config\ECSConfig; -return static function (ContainerConfigurator $containerConfigurator): void { - $containerConfigurator->import('vendor/bitbag/coding-standard/ecs.php'); - $services = $containerConfigurator->services(); - $services->set(ArraySyntaxFixer::class) - ->call('configure', [[ - 'syntax' => 'short', - ]]); +return static function (ECSConfig $config): void { - $parameters = $containerConfigurator->parameters(); - $parameters->set(Option::PATHS, [ - __DIR__ . '/src', - __DIR__ . '/tests', - ]); + putenv('ALLOW_BITBAG_OS_HEADER=1'); + + $config->import('vendor/bitbag/coding-standard/ecs.php'); + $config->paths(['src', 'tests']); }; diff --git a/src/BitBagSyliusShippingExportPlugin.php b/src/BitBagSyliusShippingExportPlugin.php index 5bdadb2..bae9dba 100644 --- a/src/BitBagSyliusShippingExportPlugin.php +++ b/src/BitBagSyliusShippingExportPlugin.php @@ -1,10 +1,11 @@ requestStack = $requestStack; $this->shippingGatewayFormTypeRegistry = $shippingGatewayFormTypeRegistry; @@ -68,7 +69,7 @@ public function getCode(): ?string if (false === $this->shippingGatewayFormTypeRegistry->has('shipping_gateway_config', $code)) { throw new ShippingGatewayNotFoundException(sprintf( 'Gateway with %s code could not be found', - $code + $code, )); } @@ -93,7 +94,7 @@ private function getExistingShippingGateway(int $id): ShippingGatewayInterface if (false === $shippingGateway instanceof ShippingGatewayInterface) { throw new ShippingGatewayNotFoundException(sprintf( 'Gateway with %d id could not be found in the database.', - $id + $id, )); } diff --git a/src/Context/ShippingGatewayContextInterface.php b/src/Context/ShippingGatewayContextInterface.php index f5eddad..e23dd66 100644 --- a/src/Context/ShippingGatewayContextInterface.php +++ b/src/Context/ShippingGatewayContextInterface.php @@ -1,10 +1,11 @@ eventDispatcher->dispatch( ExportShipmentEvent::SHORT_NAME, $configuration, - $shippingExport + $shippingExport, ); } @@ -58,7 +59,7 @@ public function exportSingleShipmentAction(Request $request): RedirectResponse $this->eventDispatcher->dispatch( ExportShipmentEvent::SHORT_NAME, $configuration, - $shippingExport + $shippingExport, ); return $this->redirectToReferer($request); diff --git a/src/Controller/ShippingExportDownloadLabelAction.php b/src/Controller/ShippingExportDownloadLabelAction.php index 2672cfc..e10d27c 100644 --- a/src/Controller/ShippingExportDownloadLabelAction.php +++ b/src/Controller/ShippingExportDownloadLabelAction.php @@ -1,10 +1,11 @@ filesystem = $filesystem; $this->repository = $repository; @@ -72,12 +73,12 @@ function () use ($filePath): void { $fileStream = fopen($filePath, 'rb'); Assert::resource($fileStream); stream_copy_to_stream($fileStream, $outputStream); - } + }, ); $disposition = $response->headers->makeDisposition( ResponseHeaderBag::DISPOSITION_ATTACHMENT, - $fileName + $fileName, ); $response->headers->set('Content-Disposition', $disposition); diff --git a/src/DependencyInjection/Compiler/RegisterShippingGatewayConfigTypePass.php b/src/DependencyInjection/Compiler/RegisterShippingGatewayConfigTypePass.php index 8e9cb1f..44bab0b 100644 --- a/src/DependencyInjection/Compiler/RegisterShippingGatewayConfigTypePass.php +++ b/src/DependencyInjection/Compiler/RegisterShippingGatewayConfigTypePass.php @@ -1,10 +1,11 @@ addMethodCall( 'add', - ['shipping_gateway_config', $attributes[0]['type'], $container->getDefinition($id)->getClass()] + ['shipping_gateway_config', $attributes[0]['type'], $container->getDefinition($id)->getClass()], ); } diff --git a/src/Entity/ShippingExport.php b/src/Entity/ShippingExport.php index 62b0eb6..91ff5c2 100644 --- a/src/Entity/ShippingExport.php +++ b/src/Entity/ShippingExport.php @@ -1,10 +1,11 @@ config, $key, sprintf( 'Shipping gateway config named %s does not exist.', - $key + $key, )); return $this->config[$key]; diff --git a/src/Entity/ShippingGatewayInterface.php b/src/Entity/ShippingGatewayInterface.php index 38a61c9..78ba8ac 100644 --- a/src/Entity/ShippingGatewayInterface.php +++ b/src/Entity/ShippingGatewayInterface.php @@ -1,10 +1,11 @@ shippingExport = $shippingExport; diff --git a/src/EventListener/Grid/AdminShippingGatewayGridEventListener.php b/src/EventListener/Grid/AdminShippingGatewayGridEventListener.php index 5fd6f9e..5320f59 100644 --- a/src/EventListener/Grid/AdminShippingGatewayGridEventListener.php +++ b/src/EventListener/Grid/AdminShippingGatewayGridEventListener.php @@ -1,10 +1,11 @@ shippingGatewayRepository = $shippingGatewayRepository; $this->shippingExportRepository = $shippingExportRepository; diff --git a/src/Exception/ShippingGatewayLabelNotFound.php b/src/Exception/ShippingGatewayLabelNotFound.php index 1749a58..bc983ee 100644 --- a/src/Exception/ShippingGatewayLabelNotFound.php +++ b/src/Exception/ShippingGatewayLabelNotFound.php @@ -1,10 +1,11 @@ getData(); $shippingGateway->setCode($code); $shippingGateway->setName($label); - } + }, ) ; } diff --git a/src/Menu/ShippingExportMenuBuilder.php b/src/Menu/ShippingExportMenuBuilder.php index e7c1cf6..05476b1 100644 --- a/src/Menu/ShippingExportMenuBuilder.php +++ b/src/Menu/ShippingExportMenuBuilder.php @@ -1,10 +1,11 @@ */ interface ShippingGatewayRepositoryInterface extends RepositoryInterface From e394afabdac231fc714803b8840e6714262b2957 Mon Sep 17 00:00:00 2001 From: janpalen Date: Thu, 8 Aug 2024 10:05:12 +0200 Subject: [PATCH 3/3] OP-359 - Add phpUnit configuration --- .github/workflows/coding_standard.yml | 1 - .gitignore | 1 + phpunit.xml.dist | 27 +++++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 phpunit.xml.dist diff --git a/.github/workflows/coding_standard.yml b/.github/workflows/coding_standard.yml index 144689b..eb9c8e9 100644 --- a/.github/workflows/coding_standard.yml +++ b/.github/workflows/coding_standard.yml @@ -22,7 +22,6 @@ jobs: symfony: [ "^5.4", "^6.4" ] sylius: [ "^1.12", "^1.13" ] node: [ "18.x", "20.x" ] - mysql: [ "8.0" ] exclude: - sylius: ^1.13 diff --git a/.gitignore b/.gitignore index 07229a6..677ef5f 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ /behat.yml /phpspec.yml +/phpunit.xml diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..766495c --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,27 @@ + + + + + tests + + + + + + src + + +