Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Github Action (Support PHP 5.6 => 8.1) #158

Merged
merged 2 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,29 @@ name: PHP tests
on: [push, pull_request]
jobs:
php-linter:
name: PHP Syntax check 5.6|7.2|7.3
name: PHP Syntax check 5.6 => 8.1
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2.0.0

- name: PHP syntax checker 5.6
uses: prestashop/github-action-php-lint/5.6@master

- name: PHP syntax checker 7.2
uses: prestashop/github-action-php-lint/7.2@master

- name: PHP syntax checker 7.3
uses: prestashop/github-action-php-lint/7.3@master

- name: PHP syntax checker 7.4
uses: prestashop/github-action-php-lint/7.4@master

- name: PHP syntax checker 8.0
uses: prestashop/github-action-php-lint/8.0@master

- name: PHP syntax checker 8.1
uses: prestashop/github-action-php-lint/8.1@master
php-cs-fixer:
name: PHP-CS-Fixer
runs-on: ubuntu-latest
Expand Down Expand Up @@ -41,17 +53,24 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
presta-versions: ['1.7.0.3', 'latest']
presta-versions: ['1.7.0.6', '1.7.1.2', '1.7.2.5', '1.7.3.4', '1.7.4.4', '1.7.5.1', '1.7.6', '1.7.7', '1.7.8', 'latest']
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'

- name: Checkout
uses: actions/checkout@v2.0.0

# Add vendor folder in cache to make next builds faster
- name: Cache vendor folder
uses: actions/cache@v1
with:
path: vendor
key: php-${{ hashFiles('composer.lock') }}

# Add composer local folder in cache to make next builds faster
- name: Cache composer folder
uses: actions/cache@v1
with:
Expand All @@ -60,8 +79,6 @@ jobs:

- run: composer install

- name: Pull PrestaShop files (Tag ${{ matrix.presta-versions }})
run: docker run -tid --rm -v ps-volume:/var/www/html --name temp-ps prestashop/prestashop:${{ matrix.presta-versions }}

- name : Run PHPStan
run: docker run --rm --volumes-from temp-ps -v $PWD:/web/module -e _PS_ROOT_DIR_=/var/www/html --workdir=/web/module phpstan/phpstan:0.12 analyse --configuration=/web/module/tests/phpstan/phpstan.neon --error-format github
# Docker images prestashop/prestashop may be used, even if the shop remains uninstalled
- name: Execute PHPStan on PrestaShop (Tag ${{ matrix.presta-versions }})
run: ./tests/phpstan.sh ${{ matrix.presta-versions }}
4 changes: 2 additions & 2 deletions psgdpr.php
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ public function createAnonymousCustomer()
$address->vat_number = '0000';
$address->dni = '0000';
$address->postcode = '00000';
$address->id_country = Configuration::get('PS_COUNTRY_DEFAULT');
$address->id_country = (int) Configuration::get('PS_COUNTRY_DEFAULT');
$address->city = 'Anonymous';
if ($address->save() == false) {
return false;
Expand Down Expand Up @@ -1103,7 +1103,7 @@ public function getCustomerNameById($id_customer)
*/
public function getAgeCustomer($id_customer)
{
$value = (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT AVG(DATEDIFF("' . date('Y-m-d') . ' 00:00:00", birthday))
$value = (int) Db::getInstance((bool) _PS_USE_SQL_SLAVE_)->getValue('SELECT AVG(DATEDIFF("' . date('Y-m-d') . ' 00:00:00", birthday))
FROM `' . _DB_PREFIX_ . 'customer` c
WHERE active = 1
AND id_customer = ' . (int) $id_customer . '
Expand Down
34 changes: 34 additions & 0 deletions tests/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');

header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');

header('Location: ../');
exit;
28 changes: 28 additions & 0 deletions tests/phpstan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
PS_VERSION=$1

set -e

# Docker images prestashop/prestashop may be used, even if the shop remains uninstalled
echo "Pull PrestaShop files (Tag ${PS_VERSION})"

docker rm -f temp-ps || true
docker volume rm -f ps-volume || true

docker run -tid --rm -v ps-volume:/var/www/html --name temp-ps prestashop/prestashop:$PS_VERSION

# Clear previous instance of the module in the PrestaShop volume
echo "Clear previous module"

docker exec -t temp-ps rm -rf /var/www/html/modules/psgdpr

# Run a container for PHPStan, having access to the module content and PrestaShop sources.
# This tool is outside the composer.json because of the compatibility with PHP 5.6
echo "Run PHPStan using phpstan-${PS_VERSION}.neon file"

docker run --rm --volumes-from temp-ps \
-v $PWD:/var/www/html/modules/psgdpr \
-e _PS_ROOT_DIR_=/var/www/html \
--workdir=/var/www/html/modules/psgdpr phpstan/phpstan:0.12 \
analyse \
--configuration=/var/www/html/modules/psgdpr/tests/phpstan/phpstan-$PS_VERSION.neon
34 changes: 34 additions & 0 deletions tests/phpstan/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');

header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');

header('Location: ../');
exit;
11 changes: 11 additions & 0 deletions tests/phpstan/phpstan-1.7.0.6.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon

parameters:
ignoreErrors:
- '#Call to method assign\(\) on an unknown class Smarty_Data#'
- '#Parameter \#1 \$hook_name of method ModuleCore\:\:registerHook\(\) expects string, array<int, string> given.#'
- '#Parameter \#1 \$id of class Customer constructor expects null, int given.#'
- '#Parameter \#4 \$idShop of static method CMSCore\:\:getCMSPages\(\) expects null, int given.#'
- '#Parameter \#4 \$ssl of method LinkCore\:\:getModuleLink\(\) expects null, true given.#'
- '#Property CustomerCore\:\:\$passwd \(int\) does not accept string.#'
11 changes: 11 additions & 0 deletions tests/phpstan/phpstan-1.7.1.2.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon

parameters:
ignoreErrors:
- '#Call to method assign\(\) on an unknown class Smarty_Data#'
- '#Parameter \#1 \$hook_name of method ModuleCore\:\:registerHook\(\) expects string, array<int, string> given.#'
- '#Parameter \#1 \$id of class Customer constructor expects null, int given.#'
- '#Parameter \#4 \$idShop of static method CMSCore\:\:getCMSPages\(\) expects null, int given.#'
- '#Parameter \#4 \$ssl of method LinkCore\:\:getModuleLink\(\) expects null, true given.#'
- '#Property CustomerCore\:\:\$passwd \(int\) does not accept string.#'
11 changes: 11 additions & 0 deletions tests/phpstan/phpstan-1.7.2.5.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon

parameters:
ignoreErrors:
- '#Call to method assign\(\) on an unknown class Smarty_Data#'
- '#Parameter \#1 \$hook_name of method ModuleCore\:\:registerHook\(\) expects string, array<int, string> given.#'
- '#Parameter \#1 \$id of class Customer constructor expects null, int given.#'
- '#Parameter \#4 \$idShop of static method CMSCore\:\:getCMSPages\(\) expects null, int given.#'
- '#Parameter \#4 \$ssl of method LinkCore\:\:getModuleLink\(\) expects null, true given.#'
- '#Property CustomerCore\:\:\$passwd \(int\) does not accept string.#'
11 changes: 11 additions & 0 deletions tests/phpstan/phpstan-1.7.3.4.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon

parameters:
ignoreErrors:
- '#Call to method assign\(\) on an unknown class Smarty_Data#'
- '#Parameter \#1 \$hook_name of method ModuleCore\:\:registerHook\(\) expects string, array<int, string> given.#'
- '#Parameter \#1 \$id of class Customer constructor expects null, int given.#'
- '#Parameter \#4 \$idShop of static method CMSCore\:\:getCMSPages\(\) expects null, int given.#'
- '#Parameter \#4 \$ssl of method LinkCore\:\:getModuleLink\(\) expects null, true given.#'
- '#Property CustomerCore\:\:\$passwd \(int\) does not accept string.#'
11 changes: 11 additions & 0 deletions tests/phpstan/phpstan-1.7.4.4.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon

parameters:
ignoreErrors:
- '#Call to method assign\(\) on an unknown class Smarty_Data#'
- '#Parameter \#1 \$hook_name of method ModuleCore\:\:registerHook\(\) expects string, array<int, string> given.#'
- '#Parameter \#1 \$id of class Customer constructor expects null, int given.#'
- '#Parameter \#4 \$idShop of static method CMSCore\:\:getCMSPages\(\) expects null, int given.#'
- '#Parameter \#4 \$ssl of method LinkCore\:\:getModuleLink\(\) expects null, true given.#'
- '#Property CustomerCore\:\:\$passwd \(int\) does not accept string.#'
11 changes: 11 additions & 0 deletions tests/phpstan/phpstan-1.7.5.1.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon

parameters:
ignoreErrors:
- '#Call to method assign\(\) on an unknown class Smarty_Data#'
- '#Parameter \#1 \$hook_name of method ModuleCore\:\:registerHook\(\) expects string, array<int, string> given.#'
- '#Parameter \#1 \$id of class Customer constructor expects null, int given.#'
- '#Parameter \#4 \$idShop of static method CMSCore\:\:getCMSPages\(\) expects null, int given.#'
- '#Parameter \#4 \$ssl of method LinkCore\:\:getModuleLink\(\) expects null, true given.#'
- '#Property CustomerCore\:\:\$passwd \(int\) does not accept string.#'
11 changes: 11 additions & 0 deletions tests/phpstan/phpstan-1.7.6.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon

parameters:
ignoreErrors:
- '#Call to method assign\(\) on an unknown class Smarty_Data#'
- '#Parameter \#1 \$hook_name of method ModuleCore\:\:registerHook\(\) expects string, array<int, string> given.#'
- '#Parameter \#1 \$id of class Customer constructor expects null, int given.#'
- '#Parameter \#4 \$idShop of static method CMSCore\:\:getCMSPages\(\) expects null, int given.#'
- '#Parameter \#4 \$ssl of method LinkCore\:\:getModuleLink\(\) expects null, true given.#'
- '#Property CustomerCore\:\:\$passwd \(int\) does not accept string.#'
7 changes: 7 additions & 0 deletions tests/phpstan/phpstan-1.7.7.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon

parameters:
ignoreErrors:
- '#Parameter \#4 \$idShop of static method CMSCore\:\:getCMSPages\(\) expects null, int given.#'
- '#Property CustomerCore\:\:\$passwd \(int\) does not accept string.#'
2 changes: 2 additions & 0 deletions tests/phpstan/phpstan-1.7.8.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon
2 changes: 2 additions & 0 deletions tests/phpstan/phpstan-latest.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon
40 changes: 9 additions & 31 deletions tests/phpstan/phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,34 +1,12 @@
includes:
- %currentWorkingDirectory%/vendor/prestashop/php-dev-tools/phpstan/ps-module-extension.neon

parameters:
paths:
# From PHPStan 0.12, paths to check are relative to the neon file
- ../../classes
- ../../controllers
- ../../psgdpr.php
reportUnmatchedIgnoredErrors: false
ignoreErrors:
- '#Property ModuleCore::\$version \(float\) does not accept string.#'
- '#Parameter \#7 \$currency_special of method PaymentModuleCore::validateOrder\(\) expects null, int given.#'
- '#Parameter \#9 \$secure_key of method PaymentModuleCore::validateOrder\(\) expects bool, string given.#'
- '#Strict comparison using === between false and string will always evaluate to false.#'
- '#Strict comparison using === between false and true will always evaluate to false.#'
- '#Parameter \#1 \$id of class Customer constructor expects null, int given.#'
- '#Parameter \#1 \$hook_name of method ModuleCore::registerHook\(\) expects string, array<int, string> given.#'
- '#Parameter \#6 \$idShop of method LinkCore::getModuleLink\(\) expects null, int given.#'
- '#Parameter \#1 \$id_hook of method ModuleCore::updatePosition\(\) expects bool, int given.#'
- '#Property TabCore::\$name \(string\) does not accept array.#'
- '#Access to an undefined property PaymentModule::\$currentOrderReference.#'
- '#Property CustomerCore::\$passwd \(int\) does not accept bool\|string.#'
- '#Parameter \#4 \$ssl of method LinkCore::getModuleLink\(\) expects null, true given.#'
- '#Parameter \#1 \$id of class Currency constructor expects null, int given.#'
- '#Property OrderStateCore::\$name \(string\) does not accept array.#'
- '#Access to an undefined property Psgdpr::\$bootstrap.#'
- '#Access to an undefined property Psgdpr::\$confirmUninstall.#'
- '#Parameter \#4 \$idShop of static method CMSCore::getCMSPages\(\) expects null, int given.#'
- '#Property CustomerCore::\$passwd \(int\) does not accept string.#'
- '#Property AddressCore::\$id_country \(int\) does not accept string.#'
- '#Parameter \#1 \$master of static method DbCore::getInstance\(\) expects bool, int given.#'

level: 5
paths:
# From PHPStan 0.12, paths to check are relative to the neon file
- ../../psgdpr.php
- ../../classes/
- ../../controllers/
- ../../sql/
- ../../upgrade/
reportUnmatchedIgnoredErrors: false
level: 5