3.9 KiB
3.9 KiB
Testing Patterns
Analysis Date: 2026-05-10
Test Framework
Runner:
- PHPUnit (~5.7) — present only in select PrestaShop-shipped modules, NOT at project root
- Mockery — used by
modules/ps_facetedsearch/
Assertion Library:
- PHPUnit built-in assertions
- Mockery for mocks:
Mockery::mock(Configuration::class)
Run Commands:
- No project-level test command exists. Custom modules (
modules/crosssellpro/,modules/caraty/) have no test suites. - For modules that ship tests:
cd modules/ps_facetedsearch && php vendor/bin/phpunit -c tests/php/phpunit.xml
cd modules/gamification && php vendor/bin/phpunit
Test File Organization
Location:
- Per-module:
modules/<module>/tests/ - No root-level
tests/directory - No collocated tests
Examples (third-party PrestaShop modules):
modules/ps_facetedsearch/tests/php/FacetedSearch/Filters/BlockTest.phpmodules/gamification/tests/unit/AdviceTest.phpmodules/gamification/tests/functional/
Naming:
*Test.phpsuffix- PSR-4 namespace under
Tests\
Custom modules in this project:
modules/crosssellpro/— NO tests directorymodules/caraty/— NO tests directory
Test Structure
Example from modules/ps_facetedsearch/tests/php/FacetedSearch/Filters/BlockTest.php:
namespace PrestaShop\Module\FacetedSearch\Tests\Filters;
use Mockery;
use Mockery\Adapter\Phpunit\MockeryTestCase;
class BlockTest extends MockeryTestCase
{
protected function setUp()
{
$mock = Mockery::mock(Configuration::class);
$mock->shouldReceive('get')->andReturnUsing(function ($arg) { /* … */ });
}
}
PHPUnit config example (modules/gamification/phpunit.xml):
<phpunit bootstrap="tests/autoload.php">
<testsuites>
<testsuite name="Unit tests"><directory>tests/unit/</directory></testsuite>
<testsuite name="Functional tests"><directory>tests/functional/</directory></testsuite>
</testsuites>
<logging>
<log type="coverage-clover" target="build/clover.xml"/>
</logging>
</phpunit>
Mocking
Framework:
- Mockery (in modules that test, e.g.
ps_facetedsearch)
Pattern:
$mock = Mockery::mock(Configuration::class);
$mock->shouldReceive('get')->andReturn('value');
Static Analysis
PHPStan:
- Configured in 40+ PrestaShop modules via
prestashop/php-dev-tools - Standard config —
modules/<module>/tests/phpstan/phpstan.neon:
includes:
- %currentWorkingDirectory%/vendor/prestashop/php-dev-tools/phpstan/ps-module-extension.neon
parameters:
paths:
- ../../<module>.php
level: 5
- No project-root PHPStan config.
PHP-CS-Fixer:
- Some module
composer.jsonscripts reference it:"lint": ["php-cs-fixer fix --no-interaction --dry-run --diff"] - No project-root config.
Coverage
- No project-wide coverage target
modules/gamification/phpunit.xmlwrites Clover output tobuild/clover.xml- No CI enforcement detected
Test Types
Unit tests: Present in some PS modules (modules/gamification/tests/unit/).
Functional tests: Present in modules/gamification/tests/functional/, modules/ps_facetedsearch/tests/php/.
E2E: None detected.
Inferred Testing Strategy for This Project
Custom code (modules/crosssellpro/, modules/caraty/, import-product.php, buy-by-phone.php) is tested manually in browser:
- Verify cross-sell carousel renders on cart page (
/cart) and checkout summary - Verify "add to cart" works for products without combinations
- Verify products with combinations link to product detail page
- Smoke-test admin via
iadmin/ - No regression suite — every change is risk
If adding tests in the future:
- Use PrestaShop's
prestashop/php-dev-toolspackage per-module pattern - Place under
modules/crosssellpro/tests/mirroring PS conventions - Mock
Db,Context,Modulecore dependencies via Mockery
Testing analysis: 2026-05-10 Update when test patterns change