Skip to content

Commit

Permalink
Code cleaning (#49)
Browse files Browse the repository at this point in the history
* Prepare dependency;Install bitbag/coding-standard

* Delete always true assertions and redundant parameters, add variables to PHPDocs, fix invalid method names

* Fix src dir with bitbag/codin-standard tool

* Fix tests dir with bitbag/codin-standard tool

* New workflow

* Add PHP 7.3 and env

* Delete .env.local

* Fix doctrine conflict

* Add doctrine conflict

* Add env to build.yml

* Remove unnecessary line from build.yml

* Fix build.yaml invalid format

* MailChimpContext fixed

* Fix too wide specification in .gitignore file
  • Loading branch information
kuba-end committed Dec 21, 2021
1 parent 3d9a334 commit ae5e5e5
Show file tree
Hide file tree
Showing 21 changed files with 224 additions and 128 deletions.
87 changes: 87 additions & 0 deletions .github/coding_standard.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Coding standard

on:
push:
branches-ignore:
- 'dependabot/**'
pull_request: ~
release:
types: [created]
schedule:
-
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: [7.4, 7.3, 8.0]
symfony: [^4.4, ^5.2]
sylius: [~1.8.0, ~1.9.0, ~1.10.0]
node: [10.x]
mysql: [5.7]

exclude:
-
php: 7.3
mysql: 8.0
-
sylius: ~1.8.0
symfony: ^5.2
-
sylius: ~1.8.0
php: 8.0
-
sylius: ~1.9.0
php: 8.0
-
sylius: ~1.10.0
php: 7.3

env:
APP_ENV: test
DATABASE_URL: "mysql://root:root@127.0.0.1/sylius?serverVersion=${{ matrix.mysql }}"

steps:
-
uses: actions/checkout@v2
-
name: Get Composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

-
name: Cache Composer
uses: actions/cache@v2
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 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

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

- name: Run ECS
run: vendor/bin/ecs
112 changes: 62 additions & 50 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,36 @@ on:

jobs:
tests:
runs-on: ubuntu-18.04
runs-on: ubuntu-latest

name: "PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, MySQL ${{ matrix.mysql }}"
name: "Sylius ${{ matrix.sylius }}, PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, MySQL ${{ matrix.mysql }}"

strategy:
fail-fast: false
matrix:
php: [7.4]
symfony: [^5.2]
php: [7.4, 7.3, 8.0]
symfony: [^4.4, ^5.2]
sylius: [~1.8.0, ~1.9.0, ~1.10.0]
node: [10.x]
mysql: [5.7]

exclude:
-
php: 7.3
mysql: 8.0
-
sylius: ~1.8.0
symfony: ^5.2
-
sylius: ~1.8.0
php: 8.0
-
sylius: ~1.9.0
php: 8.0
-
sylius: ~1.10.0
php: 7.3

env:
APP_ENV: test
DATABASE_URL: "mysql://root:root@127.0.0.1/sylius?serverVersion=${{ matrix.mysql }}"
Expand Down Expand Up @@ -59,34 +77,11 @@ jobs:
with:
mysql version: "${{ matrix.mysql }}"
mysql root password: "root"

-
name: Configure sysctl limits
run: |
sudo swapoff -a
sudo sysctl -w vm.swappiness=1
sudo sysctl -w fs.file-max=262144
sudo sysctl -w vm.max_map_count=262144
-
name: Runs Elasticsearch
uses: elastic/elastic-github-actions/elasticsearch@master
with:
stack-version: 6.8.15

-
name: Output PHP version for Symfony CLI
run: php -v | head -n 1 | awk '{ print $2 }' > .php-version

-
name: Install wkhtmltopdf
run: |
sudo apt-get update
sudo apt-get install xvfb libfontconfig wkhtmltopdf --fix-missing
echo 'xvfb-run -a -s "-screen 0 640x480x16" wkhtmltopdf "$@"' > "/usr/local/bin/wkhtmltopdf.sh"
sudo chmod a+x /usr/local/bin/wkhtmltopdf.sh
echo export WKHTMLTOPDF_PATH="/usr/local/wkhtmltopdf.sh"
-
name: Install certificates
run: symfony server:ca:install
Expand All @@ -97,12 +92,7 @@ jobs:

-
name: Run webserver
run: symfony server:start --port=8080 --dir=public --daemon

-
name: Restrict Symfony version
if: matrix.symfony != ''
run: composer config extra.symfony.require "${{ matrix.symfony }}"
run: (cd tests/Application && symfony server:start --port=8080 --dir=public --daemon)

-
name: Get Composer cache directory
Expand All @@ -117,8 +107,19 @@ jobs:
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 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
-
name: Install PHP dependencies
run: composer install --no-interaction

-
Expand All @@ -134,7 +135,6 @@ jobs:
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)
Expand All @@ -143,38 +143,50 @@ jobs:
name: Prepare test application database
run: |
(cd tests/Application && bin/console doctrine:database:create -vvv)
(cd tests/Application && bin/console doctrine:migrations:migrate -n -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 build)
-
name: Prepare test application cache
run: (cd tests/Application && bin/console cache:warmup -vvv)

-
name: Load fixtures
name: Load fixtures in test application
run: (cd tests/Application && bin/console sylius:fixtures:load -n)

-
-
name: Validate composer.json
run: composer validate --ansi --strict --no-check-publish

-
name: Run security check
run: symfony security:check

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

-
-
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 7 src/

-
name: Run PHPSpec
run: vendor/bin/phpspec run --ansi -f progress --no-interaction


-
name: Run Behat
env:
MAIL_CHIMP_API_KEY: ${{ secrets.MAILCHIMP_API_TOKEN }}
MAIL_CHIMP_LIST_ID: ${{ secrets.MAIL_CHIMP_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
if: failure()
with:
name: Behat logs
path: etc/build/
if-no-files-found: ignore
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@
!/etc/build/.gitkeep

/tests/Application/yarn.lock
/.env.*.local
/.env.local
/.env.local.php
13 changes: 9 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
"description": "MailChimp plugin for Sylius.",
"license": "MIT",
"require": {
"php": "^7.4 || ^8.0",
"php": "^7.3 || ^7.4 || ^8.0",
"sylius/sylius": "^1.10",
"drewm/mailchimp-api": "^v2.5.4",
"ext-json": "*"
"ext-json": "*",
"vimeo/psalm": "^4.12",
"composer/xdebug-handler": "^2.0",
"bitbag/coding-standard": "^1.0"
},
"require-dev": {
"behat/behat": "^3.6.1",
Expand Down Expand Up @@ -36,10 +39,12 @@
"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.6.4"
"symfony/web-profiler-bundle": "^4.4 || ^5.2"
},
"prefer-stable": true,
"conflict": {
"doctrine/orm": "^2.10.0"
},
"autoload": {
"psr-4": {
"BitBag\\SyliusMailChimpPlugin\\": "src/",
Expand Down
2 changes: 1 addition & 1 deletion features/changing_newsletter_email_as_admin.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Feature: Changing customer newsletter email

Background:
Given I am logged in as an administrator
And there is a created list in MailChimp with specified ID


@ui
Scenario: Subscribing to newsletter as guest
Expand Down
4 changes: 2 additions & 2 deletions features/subscribing_newsletter_as_customer.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Feature: Updating not subscribed customer
Background:
Given the store operates on a single channel
And there is no customer with "tata@escobar.co" email
And there is a created list in MailChimp with specified ID


Scenario: Subscribing to newsletter as customer
Given I want to subscribe to the newsletter
Expand All @@ -15,4 +15,4 @@ Feature: Updating not subscribed customer
Then the "tata@escobar.co" customer should be created
And the customer should be subscribed to the newsletter
And I should be notified that I am subscribed to the newsletter
And the email "tata@escobar.co" should be exported to MailChimp's default list
And the email "tata@escobar.co" should be exported to MailChimp's default list
4 changes: 2 additions & 2 deletions features/subscribing_newsletter_as_guest.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Feature: Creating new newsletter customer
Background:
Given the store operates on a single channel
And there is no customer with "tata@escobar.co" email
And there is a created list in MailChimp with specified ID


Scenario: Subscribing to newsletter as guest
Given I want to subscribe to the newsletter
Expand All @@ -16,4 +16,4 @@ Feature: Creating new newsletter customer
Then the "tata@escobar.co" customer should be created
And the customer should be subscribed to the newsletter
And I should be notified that I am subscribed to the newsletter
And the email "tata@escobar.co" should be exported to MailChimp's default list
And the email "tata@escobar.co" should be exported to MailChimp's default list
4 changes: 2 additions & 2 deletions features/subscribing_newsletter_with_invalid_data.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Feature: Validating newsletter form

Background:
Given the store operates on a single channel
And there is a created list in MailChimp with specified ID


Scenario: Subscribing to newsletter with invalid email
When I want to subscribe to the newsletter
Expand All @@ -26,4 +26,4 @@ Feature: Validating newsletter form
When I want to subscribe to the newsletter
And I fill newsletter with "los@pepes.co" email
And I subscribe to it
Then I should be notified that the submitted email is already subscribed to the newsletter
Then I should be notified that the submitted email is already subscribed to the newsletter
2 changes: 1 addition & 1 deletion src/Controller/NewsletterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function subscribeAction(Request $request): JsonResponse
$email = $request->request->get('email');
$token = $request->request->get('_token');

if(!is_string($email) || !is_string($token)){
if (!is_string($email) || !is_string($token)) {
return new JsonResponse([
'success' => false,
'errors' => json_encode($this->translator->trans('bitbag_sylius_mailchimp_plugin.ui.invalid_variable_type')),
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/BitBagSyliusMailChimpExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
final class BitBagSyliusMailChimpExtension extends Extension
{
/**
* {@inheritdoc}
* @inheritdoc
*/
public function load(array $config, ContainerBuilder $container): void
{
Expand Down
Loading

0 comments on commit ae5e5e5

Please sign in to comment.