Skip to content
Open
135 changes: 135 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
name: CI - PHPUnit Tests

on:
pull_request:
types: [opened, synchronize, reopened, labeled]
branches:
- '**'

jobs:
tests:
name: Tests - ${{ matrix.module }} (PS ${{ matrix.ps-version }})
runs-on: ubuntu-latest
if: contains(github.event.pull_request.labels.*.name, 'ready to review')

strategy:
fail-fast: false
matrix:
include:
- module: ps17
ps-version: '1.7.7.0'
php-version: '7.2'
- module: ps8
ps-version: '8.1.5'
php-version: '8.1'
- module: ps9
ps-version: '9.0.0'
php-version: '8.4'

services:
mysql:
image: mariadb:10.9.4
env:
MYSQL_ROOT_PASSWORD: prestashop
MYSQL_DATABASE: prestashop
options: >-
--health-cmd="mysqladmin ping -h127.0.0.1 -uroot -pprestashop --silent"
--health-interval=10s
--health-timeout=5s
--health-retries=5

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Pull PrestaShop Docker image
run: docker pull prestashop/prestashop:${{ matrix.ps-version }}

- name: Start PrestaShop container
run: |
docker run -tid --rm \
--name prestashop-${{ matrix.module }} \
--network ${{ job.container.network }} \
-e DB_SERVER=mysql \
-e DB_NAME=prestashop \
-e DB_USER=root \
-e DB_PASSWD=prestashop \
-e PS_INSTALL_AUTO=1 \
prestashop/prestashop:${{ matrix.ps-version }}

- name: Wait for PrestaShop to be ready
run: |
timeout 60 bash -c 'until docker exec prestashop-${{ matrix.module }} test -f /var/www/html/config/config.inc.php 2>/dev/null || docker exec prestashop-${{ matrix.module }} test -f /var/www/html/app/config/parameters.php 2>/dev/null; do sleep 2; done' || true
sleep 5

- name: Copy module to PrestaShop
run: |
docker cp ${{ matrix.module }}/. prestashop-${{ matrix.module }}:/var/www/html/modules/ps_checkout/

- name: Install Composer
run: |
docker exec prestashop-${{ matrix.module }} bash -c "curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer"

- name: Install Composer dependencies in container
run: |
docker exec prestashop-${{ matrix.module }} bash -c "cd /var/www/html/modules/ps_checkout && composer install --no-interaction --prefer-dist"

- name: Copy monorepo directories to module vendor
run: |
docker exec prestashop-${{ matrix.module }} bash -c "mkdir -p /var/www/html/modules/ps_checkout/vendor/invertus"
docker cp api/. prestashop-${{ matrix.module }}:/var/www/html/modules/ps_checkout/vendor/invertus/api/
docker cp core/. prestashop-${{ matrix.module }}:/var/www/html/modules/ps_checkout/vendor/invertus/core/
docker cp infrastructure/. prestashop-${{ matrix.module }}:/var/www/html/modules/ps_checkout/vendor/invertus/infrastructure/
docker cp presentation/. prestashop-${{ matrix.module }}:/var/www/html/modules/ps_checkout/vendor/invertus/presentation/
docker cp utility/. prestashop-${{ matrix.module }}:/var/www/html/modules/ps_checkout/vendor/invertus/utility/

- name: Run Infrastructure Unit Tests
run: |
docker exec prestashop-${{ matrix.module }} bash -c "cd /var/www/html/modules/ps_checkout && php vendor/bin/phpunit \
--configuration=vendor/invertus/infrastructure/tests/phpunit.xml \
--bootstrap=vendor/invertus/infrastructure/tests/bootstrap.php"

- name: Run Utility Unit Tests
run: |
docker exec prestashop-${{ matrix.module }} bash -c "cd /var/www/html/modules/ps_checkout && php vendor/bin/phpunit \
--configuration=vendor/invertus/utility/tests/phpunit.xml \
--bootstrap=vendor/invertus/utility/tests/bootstrap.php"

- name: Run Core Unit Tests
run: |
docker exec prestashop-${{ matrix.module }} bash -c "cd /var/www/html/modules/ps_checkout && php vendor/bin/phpunit \
--configuration=vendor/invertus/core/tests/phpunit.xml \
--bootstrap=vendor/invertus/core/tests/bootstrap.php"

- name: Run Presentation Unit Tests
run: |
docker exec prestashop-${{ matrix.module }} bash -c "cd /var/www/html/modules/ps_checkout && php vendor/bin/phpunit \
--configuration=vendor/invertus/presentation/tests/phpunit.xml \
--bootstrap=vendor/invertus/presentation/tests/bootstrap.php"

- name: Install module and Create testing database for Integration tests
run: |
docker exec prestashop-${{ matrix.module }} bash -c "cd /var/www/html && php bin/console prestashop:module install ps_checkout"
docker exec prestashop-${{ matrix.module }} bash -c "cd /var/www/html/modules/ps_checkout && php -d display_errors=1 -d error_reporting=E_ALL tests/create-test-database.php"

- name: Run Infrastructure Integration Tests
run: |
docker exec prestashop-${{ matrix.module }} bash -c "cd /var/www/html/modules/ps_checkout && php vendor/bin/phpunit \
--configuration=vendor/invertus/infrastructure/tests/phpunit-integration.xml \
--bootstrap=vendor/invertus/infrastructure/tests/bootstrap-integration.php"

- name: Run Core Integration Tests
run: |
docker exec prestashop-${{ matrix.module }} bash -c "cd /var/www/html/modules/ps_checkout && php vendor/bin/phpunit \
--configuration=vendor/invertus/core/tests/phpunit-integration.xml \
--bootstrap=vendor/invertus/core/tests/bootstrap-integration.php"

- name: Run Module Integration Tests
run: |
docker exec prestashop-${{ matrix.module }} bash -c "cd /var/www/html/modules/ps_checkout && php vendor/bin/phpunit \
--configuration=tests/phpunit-integration.xml \
--bootstrap=tests/bootstrap-integration.php"

- name: Cleanup
if: always()
run: docker stop prestashop-${{ matrix.module }} || true
3 changes: 2 additions & 1 deletion core/tests/Unit/PayPal/OAuth/OAuthServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class OAuthServiceTest extends TestCase
/** @var StreamInterface|MockObject */
private $stream;

private OAuthService $oauthService;
/** @var OAuthService */
private $oauthService;

protected function setUp(): void
{
Expand Down
6 changes: 5 additions & 1 deletion core/tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,9 @@
}

if (!defined('_PS_VERSION_')) {
define('_PS_VERSION_', AppKernel::VERSION);
if (class_exists('AppKernel')) {
define('_PS_VERSION_', AppKernel::VERSION);
} else {
define('_PS_VERSION_', '1.7');
}
}
35 changes: 13 additions & 22 deletions core/tests/create-test-database.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
<?php

$rootDirectory = __DIR__ . '/../../../../../';
$projectDir = __DIR__ . '/../../../';
$rootDirectory = __DIR__ . '/../../../../../../';
$projectDir = __DIR__ . '/../../../../';

require_once $projectDir . 'vendor/autoload.php';
require_once $rootDirectory . 'config/config.inc.php';

if (file_exists($rootDirectory . 'vendor/autoload.php')) {
require_once $rootDirectory . 'vendor/autoload.php';
}

if (file_exists($rootDirectory . 'autoload.php')) {
require_once $rootDirectory . 'autoload.php';
}

// Source database details
$sourceHost = '172.26.0.2';
$sourceUser = _DB_USER_;
$sourcePassword = _DB_PASSWD_;
$sourceDatabase = _DB_NAME_;
$sourceHost = defined('_DB_SERVER_') ? _DB_SERVER_ : 'mysql';
$sourceUser = defined('_DB_USER_') ? _DB_USER_ : 'root';
$sourcePassword = defined('_DB_PASSWD_') ? _DB_PASSWD_ : 'prestashop';
$sourceDatabase = defined('_DB_NAME_') ? _DB_NAME_ : 'prestashop';

// Target (new) database details
$targetDatabase = 'test_' . $sourceDatabase;

$createDatabaseCommand = "mysql -h$sourceHost -u$sourceUser -p$sourcePassword -e 'DROP DATABASE IF EXISTS `" . $targetDatabase . '`; CREATE DATABASE `' . $targetDatabase . "`'";
$importCommand = "mysqldump -h$sourceHost -u" . $sourceUser . " -p'" . $sourcePassword . "' " . $sourceDatabase . " | mysql -h$sourceHost -u " . $sourceUser . " --password='" . $sourcePassword . "' " . $targetDatabase;

echo 'Step 1: Creating New Database' . PHP_EOL;
echo shell_exec($createDatabaseCommand) . PHP_EOL;
//echo 'Step 1: Creating New Database' . PHP_EOL;
//echo shell_exec($createDatabaseCommand) . PHP_EOL;
//
//echo 'Step 2: Importing into New Database' . PHP_EOL;
//echo shell_exec($importCommand) . PHP_EOL;

echo 'Step 2: Importing into New Database' . PHP_EOL;
echo shell_exec($importCommand) . PHP_EOL;
shell_exec($createDatabaseCommand);
shell_exec($importCommand);
1 change: 0 additions & 1 deletion infrastructure/tests/bootstrap-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

if (!getenv('IS_CI')) {
define('_PS_IN_TEST_', true);
define('_DB_NAME_', 'prestashop'); // todo remove once test database is created.
}

require_once $projectDir . 'vendor/autoload.php';
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
require_once $rootDirectory . 'autoload.php';
}

if (!defined('_PS_VERSION_')) {
if (!defined('_PS_VERSION_') && class_exists('AppKernel')) {
define('_PS_VERSION_', AppKernel::VERSION);
}
10 changes: 7 additions & 3 deletions presentation/tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
$rootDirectory = __DIR__ . '/../../../../../';
$projectDir = __DIR__ . '/../../../';
$rootDirectory = __DIR__ . '/../../../../../../';
$projectDir = __DIR__ . '/../../../../';

if (!getenv('IS_CI')) {
define('_PS_IN_TEST_', true);
Expand All @@ -35,5 +35,9 @@
}

if (!defined('_PS_VERSION_')) {
define('_PS_VERSION_', AppKernel::VERSION);
if (class_exists('AppKernel')) {
define('_PS_VERSION_', AppKernel::VERSION);
} else {
define('_PS_VERSION_', '1.7');
}
}
1 change: 0 additions & 1 deletion ps17/tests/bootstrap-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

if (!getenv('IS_CI')) {
define('_PS_IN_TEST_', true);
define('_DB_NAME_', 'prestashop'); // todo remove once test database is created.
}

require_once $projectDir . 'vendor/autoload.php';
Expand Down
32 changes: 32 additions & 0 deletions ps17/tests/create-test-database.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

$rootDirectory = __DIR__ . '/../../../';
$projectDir = __DIR__ . '/../';

require_once $projectDir . 'vendor/autoload.php';
require_once $rootDirectory . 'config/config.inc.php';

if (file_exists($rootDirectory . 'vendor/autoload.php')) {
require_once $rootDirectory . 'vendor/autoload.php';
}

if (file_exists($rootDirectory . 'autoload.php')) {
require_once $rootDirectory . 'autoload.php';
}

$sourceHost = 'mysql';
$sourceUser = defined('_DB_USER_') ? _DB_USER_ : 'root';
$sourcePassword = defined('_DB_PASSWD_') ? _DB_PASSWD_ : 'prestashop';
$sourceDatabase = defined('_DB_NAME_') ? _DB_NAME_ : 'prestashop';

// Target (new) database details
$targetDatabase = 'test_' . $sourceDatabase;

$createDatabaseCommand = "mysql -h$sourceHost -u$sourceUser -p$sourcePassword -e 'DROP DATABASE IF EXISTS `" . $targetDatabase . '`; CREATE DATABASE `' . $targetDatabase . "`'";
$importCommand = "mysqldump -h$sourceHost -u" . $sourceUser . " -p'" . $sourcePassword . "' " . $sourceDatabase . " | mysql -h$sourceHost -u " . $sourceUser . " --password='" . $sourcePassword . "' " . $targetDatabase;

echo 'Step 1: Creating New Database' . PHP_EOL;
echo shell_exec($createDatabaseCommand) . PHP_EOL;

echo 'Step 2: Importing into New Database' . PHP_EOL;
echo shell_exec($importCommand) . PHP_EOL;
1 change: 0 additions & 1 deletion ps8/tests/bootstrap-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

if (!getenv('IS_CI')) {
define('_PS_IN_TEST_', true);
define('_DB_NAME_', 'prestashop'); // todo remove once test database is created.
}

require_once $projectDir . 'vendor/autoload.php';
Expand Down
32 changes: 32 additions & 0 deletions ps8/tests/create-test-database.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

$rootDirectory = __DIR__ . '/../../../';
$projectDir = __DIR__ . '/../';

require_once $projectDir . 'vendor/autoload.php';
require_once $rootDirectory . 'config/config.inc.php';

if (file_exists($rootDirectory . 'vendor/autoload.php')) {
require_once $rootDirectory . 'vendor/autoload.php';
}

if (file_exists($rootDirectory . 'autoload.php')) {
require_once $rootDirectory . 'autoload.php';
}

$sourceHost = 'mysql';
$sourceUser = defined('_DB_USER_') ? _DB_USER_ : 'root';
$sourcePassword = defined('_DB_PASSWD_') ? _DB_PASSWD_ : 'prestashop';
$sourceDatabase = defined('_DB_NAME_') ? _DB_NAME_ : 'prestashop';

// Target (new) database details
$targetDatabase = 'test_' . $sourceDatabase;

$createDatabaseCommand = "mysql -h$sourceHost -u$sourceUser -p$sourcePassword -e 'DROP DATABASE IF EXISTS `" . $targetDatabase . '`; CREATE DATABASE `' . $targetDatabase . "`'";
$importCommand = "mysqldump -h$sourceHost -u" . $sourceUser . " -p'" . $sourcePassword . "' " . $sourceDatabase . " | mysql -h$sourceHost -u " . $sourceUser . " --password='" . $sourcePassword . "' " . $targetDatabase;

echo 'Step 1: Creating New Database' . PHP_EOL;
echo shell_exec($createDatabaseCommand) . PHP_EOL;

echo 'Step 2: Importing into New Database' . PHP_EOL;
echo shell_exec($importCommand) . PHP_EOL;
1 change: 0 additions & 1 deletion ps9/tests/bootstrap-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

if (!getenv('IS_CI')) {
define('_PS_IN_TEST_', true);
define('_DB_NAME_', 'prestashop'); // todo remove once test database is created.
}

require_once $projectDir . 'vendor/autoload.php';
Expand Down
32 changes: 32 additions & 0 deletions ps9/tests/create-test-database.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

$rootDirectory = __DIR__ . '/../../../';
$projectDir = __DIR__ . '/../';

require_once $projectDir . 'vendor/autoload.php';
require_once $rootDirectory . 'config/config.inc.php';

if (file_exists($rootDirectory . 'vendor/autoload.php')) {
require_once $rootDirectory . 'vendor/autoload.php';
}

if (file_exists($rootDirectory . 'autoload.php')) {
require_once $rootDirectory . 'autoload.php';
}

$sourceHost = 'mysql';
$sourceUser = defined('_DB_USER_') ? _DB_USER_ : 'root';
$sourcePassword = defined('_DB_PASSWD_') ? _DB_PASSWD_ : 'prestashop';
$sourceDatabase = defined('_DB_NAME_') ? _DB_NAME_ : 'prestashop';

// Target (new) database details
$targetDatabase = 'test_' . $sourceDatabase;

$createDatabaseCommand = "mysql -h$sourceHost -u$sourceUser -p$sourcePassword -e 'DROP DATABASE IF EXISTS `" . $targetDatabase . '`; CREATE DATABASE `' . $targetDatabase . "`'";
$importCommand = "mysqldump -h$sourceHost -u" . $sourceUser . " -p'" . $sourcePassword . "' " . $sourceDatabase . " | mysql -h$sourceHost -u " . $sourceUser . " --password='" . $sourcePassword . "' " . $targetDatabase;

echo 'Step 1: Creating New Database' . PHP_EOL;
echo shell_exec($createDatabaseCommand) . PHP_EOL;

echo 'Step 2: Importing into New Database' . PHP_EOL;
echo shell_exec($importCommand) . PHP_EOL;
10 changes: 7 additions & 3 deletions utility/tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

$rootDirectory = __DIR__ . '/../../../../../';
$projectDir = __DIR__ . '/../../../';
$rootDirectory = __DIR__ . '/../../../../../../';
$projectDir = __DIR__ . '/../../../../';

if (!getenv('IS_CI')) {
define('_PS_IN_TEST_', true);
Expand All @@ -36,5 +36,9 @@
}

if (!defined('_PS_VERSION_')) {
define('_PS_VERSION_', AppKernel::VERSION);
if (class_exists('AppKernel')) {
define('_PS_VERSION_', AppKernel::VERSION);
} else {
define('_PS_VERSION_', '1.7');
}
}