Skip to content

Commit

Permalink
Setup tests; refs #1835
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed May 18, 2024
1 parent b96effe commit df6445a
Show file tree
Hide file tree
Showing 4 changed files with 239 additions and 0 deletions.
130 changes: 130 additions & 0 deletions .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ on:
- 'feature/*'
- 'hotfix/*'
- 'release/*'
tags:
- '*'
pull_request:
# Enable manual run
workflow_dispatch:

concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true

jobs:
lint:
Expand Down Expand Up @@ -85,3 +93,125 @@ jobs:
run: |
cd galette-core/galette/plugins/plugin-paypal
../../vendor/bin/docheader --docheader=../../../.docheader check lib ./*.php
unit-tests:
runs-on: ubuntu-latest

strategy:
matrix:
include:
#always tests higher stable php version with lower db version
#enable coverage on higher stable php version with higher postrgesql version
#lower php version
- { php-version: "8.1", db-image: "mysql:5.7", coverage: none, always: false }
- { php-version: "8.1", db-image: "mysql:8.1", coverage: none, always: false }
- { php-version: "8.1", db-image: "mariadb:10.4", coverage: none, always: false }
- { php-version: "8.1", db-image: "mariadb:11", coverage: none, always: false }
- { php-version: "8.1", db-image: "postgres:11", coverage: none, always: false }
- { php-version: "8.1", db-image: "postgres:16", coverage: none, always: false }
#higher stable php version
- { php-version: "8.3", db-image: "mysql:5.7", coverage: none, always: true }
- { php-version: "8.3", db-image: "mysql:8.1", coverage: none, always: false }
- { php-version: "8.3", db-image: "mariadb:10.4", coverage: none, always: true }
- { php-version: "8.3", db-image: "mariadb:11", coverage: none, always: false }
- { php-version: "8.3", db-image: "postgres:11", coverage: none, always: true }
- { php-version: "8.3", db-image: "postgres:16", coverage: none, always: true }
fail-fast: false

env:
skip: ${{ matrix.always == false && (github.event_name == 'pull_request' || github.repository != 'galette/galette-paypal' || !(github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags'))) }}
DB: ${{ matrix.db-image }}

services:
# Label used to access the service container
db:
# Docker Hub image
image: ${{ matrix.db-image }}
# Provide env variables for both mysql and pgsql
env:
POSTGRES_USER: galette_tests
POSTGRES_PASSWORD: g@l3tte
POSTGRES_DB: galette_tests
MYSQL_USER: galette_tests
MYSQL_PASSWORD: g@l3tte
MYSQL_ROOT_PASSWORD: g@l3tte
MYSQL_DATABASE: galette_tests
# Open network ports for both mysql and pgsql
ports:
- 3306:3306
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd="bash -c 'if [[ -n $(command -v pg_isready) ]]; then pg_isready; else if [[ -n $(command -v mysqladmin) ]]; then mysqladmin ping; else mariadb-admin ping; fi fi'"
--health-interval=10s
--health-timeout=5s
--health-retries=10
name: PHP ${{ matrix.php-version }} ${{ matrix.db-image }} ${{ (matrix.always == false && (github.event_name == 'pull_request' || github.repository != 'galette/galette' || !(github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags')))) && ' (skipped)' || matrix.coverage == 'xdebug' && ' (with coverage)' || ''}}

steps:
- name: PHP
if: env.skip != 'true'
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
tools: composer, pecl
coverage: ${{ matrix.coverage }}
extensions: apcu
ini-values: apc.enable_cli=1

- name: "Show versions"
if: env.skip != 'true'
run: |
php --version
composer --version
echo "node $(node --version)"
echo "npm $(npm --version)"
docker exec ${{ job.services.db.id }} bash -c "if [[ -n \$(command -v psql) ]]; then psql --version; else if [[ -n \$(command -v mysql) ]]; then mysql --version; else mariadb --version; fi fi"
- name: Checkout Galette core
if: env.skip != 'true'
uses: actions/checkout@v4
with:
repository: galette/galette
path: galette-core
fetch-depth: 1
ref: develop

- name: Checkout plugin
uses: actions/checkout@v4
with:
path: galette-core/galette/plugins/plugin-paypal

- name: "Restore dependencies cache"
if: env.skip != 'true'
uses: actions/cache@v4
with:
path: |
~/.composer/cache/
~/.npm/_cacache/
key: "${{ runner.os }}-galette-${{ matrix.php-version }}-${{ hashFiles('galette/composer.lock', 'package-lock.json') }}"
restore-keys: |
${{ runner.os }}-galette-${{ matrix.php-version }}-
- name: Install dependencies
if: env.skip != 'true'
run: |
cd galette-core
bin/install_deps
- name: Init for PostgreSQL
env:
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
run: |
PGPASSWORD=g@l3tte psql -d galette_tests -a -f galette-core/galette/install/scripts/pgsql.sql -U galette_tests -h localhost
PGPASSWORD=g@l3tte psql -d galette_tests -a -f galette-core/galette/plugins/plugin-paypal/scripts/pgsql.sql -U galette_tests -h localhost
if: env.skip != 'true' && startsWith(matrix.db-image, 'postgres')

- name: Init for MariaDB
run: |
mysql -e 'create database IF NOT EXISTS galette_tests;' -u galette_tests --password=g@l3tte -h 127.0.0.1 -P 3306
mysql -e 'use galette_tests; source galette-core/galette/install/scripts/mysql.sql;' -u galette_tests --password=g@l3tte -h 127.0.0.1 -P 3306
mysql -e 'use galette_tests; source galette-core/galette/plugins/plugin-paypal/scripts/mysql.sql;' -u galette_tests --password=g@l3tte -h 127.0.0.1 -P 3306
if: env.skip != 'true' && (startsWith(matrix.db-image, 'mysql') || startsWith(matrix.db-image, 'mariadb'))
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.exvim*
dist/
tempcache/
tests/coverage/
76 changes: 76 additions & 0 deletions tests/GalettePaypal/tests/units/Paypal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

/**
* Copyright © 2003-2024 The Galette Team
*
* This file is part of Galette (https://galette.eu).
*
* Galette is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Galette is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*/

namespace GalettePaypal\tests\units;

use Galette\GaletteTestCase;

/**
* Paypal tests
*
* @author Johan Cwiklinski <johan@x-tnd.be>
*/
class Paypal extends GaletteTestCase
{
protected int $seed = 20240518135530;

/**
* Cleanup after each test method
*
* @return void
*/
public function tearDown(): void
{
$delete = $this->zdb->delete(PAYPAL_PREFIX . \GalettePaypal\Paypal::TABLE);
$this->zdb->execute($delete);
parent::tearDown();
}

/**
* Test empty
*
* @return void
*/
public function testEmpty(): void
{
$paypal = new \GalettePaypal\Paypal($this->zdb);
$this->assertSame('', $paypal->getId());

$amounts = $paypal->getAmounts($this->login);
$this->assertCount(1, $amounts);

$ctype = new \Galette\Entity\ContributionsTypes($this->zdb);
$ctype_id = $ctype->getIdByLabel('donation in money');
$this->assertSame(
[
$ctype_id => [
'name' => 'donation in money',
'amount' => null,
'extra' => false
]
],
$amounts
);
$this->assertCount(7, $paypal->getAllAmounts());
$this->assertTrue($paypal->areAmountsLoaded());
$this->assertTrue($paypal->isLoaded());
}
}
32 changes: 32 additions & 0 deletions tests/TestsBootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/**
* Copyright © 2003-2024 The Galette Team
*
* This file is part of Galette (https://galette.eu).
*
* Galette is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Galette is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* Bootstrap tests file for Galette Paypal plugin
*
* @author Johan Cwiklinski <johan@x-tnd.be>
*/

define('GALETTE_PLUGINS_PATH', __DIR__ . '/../../');
$basepath = '../../../galette/';

include_once '../../../tests/TestsBootstrap.php';
require_once __DIR__ . '/../_config.inc.php';

0 comments on commit df6445a

Please sign in to comment.