Add PHPStan configuration for Symfony4 tests

- Created a new phpstan.neon file in the Symfony4 tests directory.
- Configured paths and excluded Symfony3 directory.
- Added bootstrap files for autoloading.
- Set dynamic constant names and adjusted reporting settings.
- Established PHPStan level to 6 for stricter analysis.
This commit is contained in:
2026-02-09 23:14:09 +01:00
parent 58947ad589
commit 3bd8164d3d
169 changed files with 4964 additions and 3877 deletions

View File

@@ -0,0 +1,16 @@
name-template: v$NEXT_PATCH_VERSION
tag-template: v$NEXT_PATCH_VERSION
categories:
- title: 🔨 Improvements
label: enhancement
- title: 🐛 Bug Fixes
label: bug
- title: 🚀 New Features
label: Feature
change-template: '- #$NUMBER: $TITLE by @$AUTHOR'
template: |
# Changes
$CHANGES

View File

@@ -0,0 +1,78 @@
name: PHP tests
on: [push, pull_request]
jobs:
php-linter:
name: PHP Syntax check 5.6|7.2|7.3|8.0|8.1
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- 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 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
phpstan:
name: PHPStan
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Cache vendor folder
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
- name: Cache composer folder
uses: actions/cache@v2
with:
path: ~/.composer/cache
key: php-composer-cache
- run: composer install
- run: composer install
working-directory: tests/Symfony3
- run: composer install
working-directory: tests/Symfony4
- name : Run PHPStan for Symfony 3
run: composer run phpstan-sf3
- name : Run PHPStan for Symfony 4
run: composer run phpstan-sf4
phpunit:
name: PHPUnit
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Cache vendor folder
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
- name: Cache composer folder
uses: actions/cache@v2
with:
path: ~/.composer/cache
key: php-composer-cache
- run: composer install
- name: Run PHPUnit
run: vendor/bin/phpunit tests/Unit

View File

@@ -2,7 +2,7 @@
# Edit at https://www.gitignore.io/?templates=vim,vuejs,emacs,linux,macos,windows,phpstorm,composer,sublimetext,visualstudiocode
### Composer ###
/vendor/
/**/vendor/
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file

View File

@@ -8,11 +8,18 @@ You should install this library only on a PrestaShop environment and with PHP 5.
## Installation
```
```bash
# PrestaShop 1.7+
composer require prestashop/module-lib-service-container
# PrestaShop 1.6
composer require prestashop/module-lib-service-container
composer require symfony/config:^3.4 symfony/dependency-injection:^3.4 symfony/expression-language:^3.4 symfony/yaml:^3.4
```
When this project is successfully added to your dependencies, you can add the new ServiceContainer to your module and use it.
PrestaShop runs with Symfony components from version 1.7, so dependancies are not required anymore here. I you plan to run your module on PrestaShop, Symfony dependencies must be required separately.
## Usage
@@ -40,7 +47,8 @@ $this->serviceContainer = new ServiceContainer($this->name, $this->getLocalPath(
return $this->serviceContainer->getService($serviceName);
}
```
- Then, you have to declare your service in the services.yml file. You must declare your services in the config/ folder.
- Then, you have to declare your service in the services.yml file. You must declare your services in the config/ folder. From Symfony 4, services must be explicitely declared as public to be loaded with the method `getService()`;
We split the services in two folders in the config : /front and /admin folders. So the tree should be like :
```
/mymodule
@@ -57,4 +65,3 @@ imports:
- { resource: ../common.yml }
```
Now you can add your services in the services.yml like you were in a Symfony project ;)

View File

@@ -17,15 +17,17 @@
},
"require": {
"php": ">=5.6.0",
"symfony/config": "^3.4",
"symfony/dependency-injection": "^3.4",
"prestashop/module-lib-cache-directory-provider": "^1.0",
"symfony/expression-language": "^3.4",
"symfony/yaml": "^3.4"
"prestashop/module-lib-cache-directory-provider": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "~5.7"
},
"suggest": {
"symfony/config": "Needed when the running PrestaShop does not already run with Symfony",
"symfony/dependency-injection": "Needed when the running PrestaShop does not already run with Symfony",
"symfony/expression-language": "Needed when the running PrestaShop does not already run with Symfony",
"symfony/yaml": "Needed when the running PrestaShop does not already run with Symfony"
},
"autoload": {
"psr-4": {
"PrestaShop\\ModuleLibServiceContainer\\": "src/"
@@ -35,5 +37,13 @@
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"phpstan-sf3": "tests/Symfony3/vendor/bin/phpstan analyze -c tests/Symfony3/phpstan.neon",
"phpstan-sf4": "tests/Symfony4/vendor/bin/phpstan analyze -c tests/Symfony4/phpstan.neon",
"phpstan": [
"@phpstan-sf3",
"@phpstan-sf4"
]
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -69,7 +69,7 @@ class ContainerProvider
. 'Container'
;
$containerFilePath = $this->cacheDirectory->getPath() . '/' . $containerClassName . '.php';
$containerConfigCache = new ConfigCache($containerFilePath, _PS_MODE_DEV_);
$containerConfigCache = new ConfigCache($containerFilePath, constant('_PS_MODE_DEV_'));
if ($containerConfigCache->isFresh()) {
require_once $containerFilePath;

View File

@@ -66,13 +66,15 @@ class ServiceContainer
/**
* Instantiate a new ContainerProvider
*
* @return void
*/
private function initContainer()
{
$cacheDirectory = new CacheDirectoryProvider(
_PS_VERSION_,
_PS_ROOT_DIR_,
_PS_MODE_DEV_
constant('_PS_VERSION_'),
constant('_PS_ROOT_DIR_'),
constant('_PS_MODE_DEV_')
);
$containerProvider = new ContainerProvider($this->moduleName, $this->moduleLocalPath, $cacheDirectory);

View File

@@ -0,0 +1,9 @@
{
"require-dev": {
"phpstan/phpstan": "^1.7",
"symfony/config": "^3.4",
"symfony/dependency-injection": "^3.4",
"symfony/expression-language": "^3.4",
"symfony/yaml": "^3.4"
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,15 @@
parameters:
paths:
- ../../src
excludePaths:
- ../../src/Symfony4
bootstrapFiles:
- vendor/autoload.php
- ../../vendor/autoload.php
reportUnmatchedIgnoredErrors: false
dynamicConstantNames:
- _PS_VERSION_
- _PS_ROOT_DIR_
- _PS_MODE_DEV_
level: 6

View File

@@ -0,0 +1,9 @@
{
"require-dev": {
"phpstan/phpstan": "^1.7",
"symfony/config": "^4.4",
"symfony/dependency-injection": "^4.4",
"symfony/expression-language": "^4.4",
"symfony/yaml": "^4.4"
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,15 @@
parameters:
paths:
- ../../src
excludePaths:
- ../../src/Symfony3
bootstrapFiles:
- vendor/autoload.php
- ../../vendor/autoload.php
reportUnmatchedIgnoredErrors: false
dynamicConstantNames:
- _PS_VERSION_
- _PS_ROOT_DIR_
- _PS_MODE_DEV_
level: 6