Skip to content

Commit eb849b3

Browse files
Merge pull request #109 from Progi1984/issue25921
Improved Github Action (Support PHP 5.6 => 8.1)
2 parents 93f2a79 + 34629d9 commit eb849b3

20 files changed

Lines changed: 172 additions & 60 deletions

.github/workflows/php.yml

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,81 @@
11
name: PHP tests
22
on: [push, pull_request]
33
jobs:
4+
# Check there is no syntax errors in the project
45
php-linter:
5-
name: PHP Syntax check 5.6|7.2|7.3
6+
name: PHP Syntax check 5.6 => 8.1
67
runs-on: ubuntu-latest
78
steps:
89
- name: Checkout
910
uses: actions/checkout@v2.0.0
11+
1012
- name: PHP syntax checker 5.6
1113
uses: prestashop/github-action-php-lint/5.6@master
14+
1215
- name: PHP syntax checker 7.2
1316
uses: prestashop/github-action-php-lint/7.2@master
17+
1418
- name: PHP syntax checker 7.3
1519
uses: prestashop/github-action-php-lint/7.3@master
20+
21+
- name: PHP syntax checker 7.4
22+
uses: prestashop/github-action-php-lint/7.4@master
23+
24+
- name: PHP syntax checker 8.0
25+
uses: prestashop/github-action-php-lint/8.0@master
26+
27+
- name: PHP syntax checker 8.1
28+
uses: prestashop/github-action-php-lint/8.1@master
29+
30+
# Check the PHP code follow the coding standards
1631
php-cs-fixer:
1732
name: PHP-CS-Fixer
1833
runs-on: ubuntu-latest
1934
steps:
35+
- name: Setup PHP
36+
uses: shivammathur/setup-php@v2
37+
with:
38+
php-version: '7.4'
39+
2040
- name: Checkout
2141
uses: actions/checkout@v2.0.0
42+
43+
- name: Cache dependencies
44+
uses: actions/cache@v2
45+
with:
46+
path: vendor
47+
key: php-${{ hashFiles('composer.lock') }}
48+
49+
- name: Install dependencies
50+
run: composer install
51+
2252
- name: Run PHP-CS-Fixer
23-
uses: prestashopcorp/github-action-php-cs-fixer@master
53+
run: ./vendor/bin/php-cs-fixer fix --dry-run --diff --using-cache=no --diff-format udiff
54+
55+
# Run PHPStan against the module and a PrestaShop release
2456
phpstan:
2557
name: PHPStan
2658
runs-on: ubuntu-latest
2759
strategy:
2860
matrix:
29-
presta-versions: ['latest', '1.7.0.3', '1.6.1.21','1.6.1.0']
61+
presta-versions: ['1.6.1.18', '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']
3062
steps:
63+
- name: Setup PHP
64+
uses: shivammathur/setup-php@v2
65+
with:
66+
php-version: '7.4'
67+
3168
- name: Checkout
3269
uses: actions/checkout@v2.0.0
3370

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

78+
# Add composer local folder in cache to make next builds faster
4079
- name: Cache composer folder
4180
uses: actions/cache@v1
4281
with:
@@ -45,14 +84,6 @@ jobs:
4584

4685
- run: composer install
4786

48-
- name: Pull PrestaShop files (Tag ${{ matrix.presta-versions }})
49-
run: docker run -tid --rm -v ps-volume:/var/www/html --name temp-ps prestashop/prestashop:${{ matrix.presta-versions }}
50-
51-
- name: Select .neon file to run with PHPStan
52-
id: neon
53-
run: |
54-
PS_VERSION=$(docker exec temp-ps bash -c 'echo "$PS_VERSION"')
55-
[[ "${PS_VERSION:0:3}" != '1.7' ]] && echo ::set-output name=filename::phpstan-PS-1.6.neon || echo ::set-output name=filename::phpstan-PS-1.7.neon
56-
57-
- name : Run PHPStan
58-
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/${{steps.neon.outputs.filename}}
87+
# Docker images prestashop/prestashop may be used, even if the shop remains uninstalled
88+
- name: Execute PHPStan on PrestaShop (Tag ${{ matrix.presta-versions }})
89+
run: ./tests/phpstan.sh ${{ matrix.presta-versions }}
File renamed without changes.

classes/Handler/ModuleHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function isModuleEnabled($moduleName)
3333
{
3434
$module = Module::getInstanceByName($moduleName);
3535

36-
if (false === $module) {
36+
if (!($module instanceof Module)) {
3737
return false;
3838
}
3939

@@ -78,7 +78,7 @@ public function uninstallModule($moduleName)
7878

7979
$oldModule = Module::getInstanceByName($moduleName);
8080

81-
if (false === $oldModule) {
81+
if (!($oldModule instanceof Module)) {
8282
return false;
8383
}
8484

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
"email": "contact@prestashop.com"
1010
}
1111
],
12+
"require": {
13+
"php": ">=5.6"
14+
},
15+
"require-dev": {
16+
"prestashop/php-dev-tools": "3.*"
17+
},
1218
"config": {
1319
"preferred-install": "dist",
1420
"optimize-autoloader": true,
@@ -17,12 +23,6 @@
1723
"php": "5.6"
1824
}
1925
},
20-
"require": {
21-
"php": ">=5.6"
22-
},
23-
"require-dev": {
24-
"prestashop/php-dev-tools": "3.*"
25-
},
2626
"autoload": {
2727
"classmap": [
2828
"ps_googleanalytics.php",
@@ -32,4 +32,4 @@
3232
},
3333
"type": "prestashop-module",
3434
"author": "PrestaShop"
35-
}
35+
}

tests/index.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* 2007-2020 PrestaShop and Contributors
3+
* 2007-2020 PrestaShop SA and Contributors
44
*
55
* NOTICE OF LICENSE
66
*
@@ -12,12 +12,18 @@
1212
* obtain it through the world-wide-web, please send an email
1313
* to license@prestashop.com so we can send you a copy immediately.
1414
*
15+
* DISCLAIMER
16+
*
17+
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
18+
* versions in the future. If you wish to customize PrestaShop for your
19+
* needs please refer to https://www.prestashop.com for more information.
20+
*
1521
* @author PrestaShop SA <contact@prestashop.com>
1622
* @copyright 2007-2020 PrestaShop SA and Contributors
1723
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
1824
* International Registered Trademark & Property of PrestaShop SA
1925
*/
20-
header('Expires: Mon, 26 Jul 1998 05:00:00 GMT');
26+
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
2127
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
2228

2329
header('Cache-Control: no-store, no-cache, must-revalidate');

tests/phpstan.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
PS_VERSION=$1
3+
4+
set -e
5+
6+
# Docker images prestashop/prestashop may be used, even if the shop remains uninstalled
7+
echo "Pull PrestaShop files (Tag ${PS_VERSION})"
8+
9+
docker rm -f temp-ps || true
10+
docker volume rm -f ps-volume || true
11+
12+
docker run -tid --rm -v ps-volume:/var/www/html --name temp-ps prestashop/prestashop:$PS_VERSION
13+
14+
# Clear previous instance of the module in the PrestaShop volume
15+
echo "Clear previous module"
16+
17+
docker exec -t temp-ps rm -rf /var/www/html/modules/ps_googleanalytics
18+
19+
# Run a container for PHPStan, having access to the module content and PrestaShop sources.
20+
# This tool is outside the composer.json because of the compatibility with PHP 5.6
21+
echo "Run PHPStan using phpstan-${PS_VERSION}.neon file"
22+
23+
docker run --rm --volumes-from temp-ps \
24+
-v $PWD:/var/www/html/modules/ps_googleanalytics \
25+
-e _PS_ROOT_DIR_=/var/www/html \
26+
--workdir=/var/www/html/modules/ps_googleanalytics phpstan/phpstan:0.12 \
27+
analyse \
28+
--configuration=/var/www/html/modules/ps_googleanalytics/tests/phpstan/phpstan-$PS_VERSION.neon

tests/phpstan/index.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
<?php
22
/**
3-
* 2007-2020 PrestaShop and Contributors
3+
* Copyright since 2007 PrestaShop SA and Contributors
4+
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
45
*
56
* NOTICE OF LICENSE
67
*
78
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
8-
* that is bundled with this package in the file LICENSE.txt.
9+
* that is bundled with this package in the file LICENSE.md.
910
* It is also available through the world-wide-web at this URL:
1011
* https://opensource.org/licenses/AFL-3.0
1112
* If you did not receive a copy of the license and are unable to
1213
* obtain it through the world-wide-web, please send an email
1314
* to license@prestashop.com so we can send you a copy immediately.
1415
*
15-
* @author PrestaShop SA <contact@prestashop.com>
16-
* @copyright 2007-2020 PrestaShop SA and Contributors
16+
* DISCLAIMER
17+
*
18+
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
19+
* versions in the future. If you wish to customize PrestaShop for your
20+
* needs please refer to https://devdocs.prestashop.com/ for more information.
21+
*
22+
* @author PrestaShop SA and Contributors <contact@prestashop.com>
23+
* @copyright Since 2007 PrestaShop SA and Contributors
1724
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
18-
* International Registered Trademark & Property of PrestaShop SA
1925
*/
20-
header('Expires: Mon, 26 Jul 1998 05:00:00 GMT');
26+
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
2127
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
2228

2329
header('Cache-Control: no-store, no-cache, must-revalidate');
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
includes:
2+
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon
3+
4+
parameters:
5+
ignoreErrors:
6+
- '#PrestaShop\\Module\\Ps_Googleanalytics\\Handler\\ModuleHandler::uninstallModule\(\) calls parent::uninstall\(\) but PrestaShop\\Module\\Ps_Googleanalytics\\Handler\\ModuleHandler does not extend any class.#'

tests/phpstan/phpstan-1.7.1.2.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
includes:
2+
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon
3+
4+
parameters:
5+
ignoreErrors:
6+
- '#PrestaShop\\Module\\Ps_Googleanalytics\\Handler\\ModuleHandler::uninstallModule\(\) calls parent::uninstall\(\) but PrestaShop\\Module\\Ps_Googleanalytics\\Handler\\ModuleHandler does not extend any class.#'

tests/phpstan/phpstan-1.7.2.5.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
includes:
2+
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon
3+
4+
parameters:
5+
ignoreErrors:
6+
- '#PrestaShop\\Module\\Ps_Googleanalytics\\Handler\\ModuleHandler::uninstallModule\(\) calls parent::uninstall\(\) but PrestaShop\\Module\\Ps_Googleanalytics\\Handler\\ModuleHandler does not extend any class.#'

0 commit comments

Comments
 (0)