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

experiment: add tests for /modules/miguel/orders.php #6

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
43 changes: 41 additions & 2 deletions .github/scripts/build-zip.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,54 @@
#!/usr/bin/env bash

set -e

# Function to remove space after the first PHPDoc comment
remove_space_after_phpdoc() {
file="$1"
echo "Removing space after PHPDoc comment in $file"

# Check if the file exists
if [ ! -f "$file" ]; then
echo "File $file does not exist."
exit 1
fi

# Find the first PHPdoc and remove spaces after it
perl -CSD -i -pe 'BEGIN{undef $/;} s/\*\/\n\n/*\/\n/smg;' "$file"
}

tmpdir=$(mktemp -d)
ignore=".git .github .idea .vscode .gitignore .php-cs-fixer.dist.php .php-cs-fixer.cache composer.* tests run doc vendor vendor2 docker-compose.yml docker-compose.test.yml Makefile *.zip"
result="$(PWD)/miguel.zip"
ignore=".git .github .idea .vscode .gitignore .php-cs-fixer.dist.php .php-cs-fixer.cache composer.lock assets tests run doc vendor2 docker-compose.yml docker-compose.test.yml Makefile *.zip"
result="$(pwd)/miguel.zip"

rm -rf "$result"

mkdir -p $tmpdir/miguel
rsync -a --exclude=.git --exclude=run --exclude=vendor --exclude=vendor2 "." "${tmpdir}/miguel/"

pushd $tmpdir > /dev/null
if [[ -f "miguel/composer.json" ]]; then
pushd miguel > /dev/null
composer install

composer exec autoindex
cp src/index.php .

composer exec header-stamp -- --license=assets/license-header.txt --exclude=.github,node_modules,vendor,tests,_dev,run,composer.json

for file in $(find . -type f -name "*.php" ! -path "./vendor/*"); do
remove_space_after_phpdoc "$file"
done
cat index.php

composer exec php-cs-fixer fix -- --using-cache=no

rm -rf vendor/

composer install --no-dev
popd > /dev/null
fi

for i in $ignore; do
rm -rf miguel/$i
done
Expand Down
83 changes: 45 additions & 38 deletions .github/workflows/php_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,6 @@ permissions:
checks: write

jobs:
header-stamp:
name: Check license headers
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP 8.2
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'

- name: Cache vendor folder
uses: actions/cache@v4
with:
path: vendor
key: php-${{ hashFiles('composer.lock') }}

- name: Cache composer folder
uses: actions/cache@v4
with:
path: ~/.composer/cache
key: php-composer-cache

- run: composer install

- name: Run Header Stamp in Dry Run mode
run: php vendor/bin/header-stamp --license=LICENSE.txt --exclude=.github,node_modules,vendor,tests,_dev,run,composer.json --dry-run
php-linter:
name: PHP Syntax check 7.1|7.2|7.3|7.4|8.0|8.1|8.2
runs-on: ubuntu-latest
Expand Down Expand Up @@ -120,24 +92,18 @@ jobs:
# PrestaShop v1.7.8.x
- php-version: '7.1'
prestashop-version: '1.7.8.x'
phpunit-version: '^7.5'
- php-version: '7.4'
prestashop-version: '1.7.8.x'
phpunit-version: '^7.5'
# PrestaShop v8.0.x
- php-version: '7.2'
prestashop-version: '8.0.x'
phpunit-version: '^8'
- php-version: '8.1'
prestashop-version: '8.0.x'
phpunit-version: '^9'
# PrestaShop v8.1.x
- php-version: '7.2'
prestashop-version: '8.1.x'
phpunit-version: '^8'
- php-version: '8.1'
prestashop-version: '8.1.x'
phpunit-version: '^9'
services:
mysql:
image: mysql:5.7
Expand All @@ -155,9 +121,24 @@ jobs:
with:
php-version: ${{ matrix.php-version }}
coverage: xdebug
tools: composer:v2, phpunit:${{ matrix.phpunit-version }}
tools: composer:v2
extensions: gd, mbstring, zip, mcrypt, pdo_mysql, dom

- name: Cache vendor folder
uses: actions/cache@v4
with:
path: vendor
key: php-${{ hashFiles('composer.lock') }}

- name: Cache composer folder
uses: actions/cache@v4
with:
path: ~/.composer/cache
key: php-composer-cache

- name: Composer install
run: composer install --prefer-dist --no-progress --no-ansi --no-interaction

- name: Test MySQL Connection
uses: nick-fields/retry@v3
with:
Expand All @@ -181,8 +162,34 @@ jobs:
env:
MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}

- name: Create module folder
run: mkdir -p vendor2/PrestaShop/modules/miguel
- name: Install module
run: |
bash .github/scripts/build-zip.sh

rm -rf vendor2/PrestaShop/modules/miguel
unzip -q miguel.zip -d vendor2/PrestaShop/modules/

ls -al vendor2/PrestaShop/modules/
php vendor2/PrestaShop/bin/console prestashop:module install miguel

rm -r vendor2/PrestaShop/modules/miguel/vendor
cp -r tests vendor2/PrestaShop/modules/miguel/
pushd vendor2/PrestaShop/modules/miguel/
composer install --prefer-dist --no-progress --no-ansi --no-interaction
popd
ls -al vendor2/PrestaShop/modules/miguel/

- name: Run PHPUnit
run: phpunit -c ./tests/Unit/phpunit.xml
run: |
php -d xdebug.auto_trace=ON -d xdebug.trace_output_dir=mytracedir/ vendor/bin/phpunit -c ./tests/Unit/phpunit.xml || true
if [ -d mytracedir ]; then
ls -al mytracedir
for file in mytracedir/*; do
echo "File: $file"
cat $file
done

echo "Xdebug trace files found"
exit 1
fi
working-directory: vendor2/PrestaShop/modules/miguel
2 changes: 1 addition & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

/** @var \Symfony\Component\Finder\Finder $finder */
$finder = $config->setUsingCache(true)->getFinder();
$finder->in(__DIR__)->exclude(['vendor', 'run']);
$finder->in(__DIR__)->exclude(['vendor', 'vendor2', 'run', 'tests']);

return $config;
13 changes: 0 additions & 13 deletions tests/Unit/DatabaseTestCase.php → assets/license-header.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?php
/**
* 2024 Servantes
*
Expand All @@ -12,15 +11,3 @@
* @copyright 2022 - 2024 Servantes
* @license LICENSE.txt
*/

use PHPUnit\Framework\TestCase;

class DatabaseTestCase extends TestCase
{
protected function setUp(): void
{
parent::setUp();

\MiguelSettings::reset();
}
}
18 changes: 16 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
{
"author": "Servantes",
"license": "MIT",
"type": "prestashop-module",
"require": {
"php": ">=7.1.0"
},
"require-dev": {
"prestashop/php-dev-tools": "^4.3",
"phpunit/phpunit": "^9"
"prestashop/php-dev-tools": "^4.3 || ^3.16",
"phpunit/phpunit": "^7 || ^8 || ^9",
"prestashop/autoindex": "^2.1 || ^1",
"friendsofphp/php-cs-fixer": "^3.52 || ^2",
"lchrusciel/api-test-case": "^5.3 || ^4.1"
},
"autoload": {
"psr-4": {
"Miguel\\": "src/",
"Tests\\": "tests/"
},
"classmap": ["miguel.php"]
},
"config": {
"prepend-autoloader": false
}
}
Loading