Skip to content

Commit 6eb8b8e

Browse files
committed
Add unit tests
1 parent a03f0a8 commit 6eb8b8e

File tree

3 files changed

+209
-1
lines changed

3 files changed

+209
-1
lines changed

Diff for: .github/workflows/ci-linux.yml

+126-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
pull_request:
1212

1313
jobs:
14-
ubuntu-latest:
14+
lint:
1515
runs-on: ubuntu-latest
1616

1717
strategy:
@@ -86,3 +86,128 @@ jobs:
8686
run: |
8787
cd galette-core/galette/plugins/plugin-auto
8888
../../vendor/bin/docheader --docheader=../../../.docheader check lib ./*.php
89+
90+
unit-tests:
91+
runs-on: ubuntu-latest
92+
93+
strategy:
94+
matrix:
95+
include:
96+
#always tests higher stable php version with lower db version
97+
#enable coverage on higher stable php version with higher postrgesql version
98+
#lower php version
99+
- { php-version: "8.1", db-image: "mysql:5.7", coverage: none, always: false }
100+
- { php-version: "8.1", db-image: "mysql:8.1", coverage: none, always: false }
101+
- { php-version: "8.1", db-image: "mariadb:10.4", coverage: none, always: false }
102+
- { php-version: "8.1", db-image: "mariadb:11", coverage: none, always: false }
103+
- { php-version: "8.1", db-image: "postgres:11", coverage: none, always: false }
104+
- { php-version: "8.1", db-image: "postgres:16", coverage: none, always: false }
105+
#higher stable php version
106+
- { php-version: "8.3", db-image: "mysql:5.7", coverage: none, always: true }
107+
- { php-version: "8.3", db-image: "mysql:8.1", coverage: none, always: false }
108+
- { php-version: "8.3", db-image: "mariadb:10.4", coverage: none, always: true }
109+
- { php-version: "8.3", db-image: "mariadb:11", coverage: none, always: false }
110+
- { php-version: "8.3", db-image: "postgres:11", coverage: none, always: true }
111+
- { php-version: "8.3", db-image: "postgres:16", coverage: none, always: true }
112+
fail-fast: false
113+
114+
env:
115+
skip: ${{ matrix.always == false && (github.event_name == 'pull_request' || github.repository != 'galette/galette-auto' || !(github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags'))) }}
116+
DB: ${{ matrix.db-image }}
117+
118+
services:
119+
# Label used to access the service container
120+
db:
121+
# Docker Hub image
122+
image: ${{ matrix.db-image }}
123+
# Provide env variables for both mysql and pgsql
124+
env:
125+
POSTGRES_USER: galette_tests
126+
POSTGRES_PASSWORD: g@l3tte
127+
POSTGRES_DB: galette_tests
128+
MYSQL_USER: galette_tests
129+
MYSQL_PASSWORD: g@l3tte
130+
MYSQL_ROOT_PASSWORD: g@l3tte
131+
MYSQL_DATABASE: galette_tests
132+
# Open network ports for both mysql and pgsql
133+
ports:
134+
- 3306:3306
135+
- 5432:5432
136+
# Set health checks to wait until postgres has started
137+
options: >-
138+
--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'"
139+
--health-interval=10s
140+
--health-timeout=5s
141+
--health-retries=10
142+
143+
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)' || ''}}
144+
145+
steps:
146+
- name: PHP
147+
if: env.skip != 'true'
148+
uses: shivammathur/setup-php@v2
149+
with:
150+
php-version: ${{ matrix.php-versions }}
151+
tools: composer, pecl
152+
coverage: ${{ matrix.coverage }}
153+
extensions: apcu
154+
ini-values: apc.enable_cli=1
155+
156+
- name: "Show versions"
157+
if: env.skip != 'true'
158+
run: |
159+
php --version
160+
composer --version
161+
echo "node $(node --version)"
162+
echo "npm $(npm --version)"
163+
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"
164+
165+
- name: Checkout Galette core
166+
if: env.skip != 'true'
167+
uses: actions/checkout@v4
168+
with:
169+
repository: galette/galette
170+
path: galette-core
171+
fetch-depth: 1
172+
ref: develop
173+
174+
- name: Checkout plugin
175+
uses: actions/checkout@v4
176+
with:
177+
path: galette-core/galette/plugins/plugin-auto
178+
179+
- name: "Restore dependencies cache"
180+
if: env.skip != 'true'
181+
uses: actions/cache@v4
182+
with:
183+
path: |
184+
~/.composer/cache/
185+
~/.npm/_cacache/
186+
key: "${{ runner.os }}-galette-${{ matrix.php-version }}-${{ hashFiles('galette/composer.lock', 'package-lock.json') }}"
187+
restore-keys: |
188+
${{ runner.os }}-galette-${{ matrix.php-version }}-
189+
190+
- name: Install dependencies
191+
if: env.skip != 'true'
192+
run: |
193+
cd galette-core
194+
bin/install_deps
195+
196+
- name: Init for PostgreSQL
197+
env:
198+
POSTGRES_HOST: localhost
199+
POSTGRES_PORT: 5432
200+
run: |
201+
PGPASSWORD=g@l3tte psql -d galette_tests -a -f galette-core/galette/install/scripts/pgsql.sql -U galette_tests -h localhost
202+
if: env.skip != 'true' && startsWith(matrix.db-image, 'postgres')
203+
204+
- name: Init for MariaDB
205+
run: |
206+
mysql -e 'create database IF NOT EXISTS galette_tests;' -u galette_tests --password=g@l3tte -h 127.0.0.1 -P 3306
207+
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
208+
if: env.skip != 'true' && (startsWith(matrix.db-image, 'mysql') || startsWith(matrix.db-image, 'mariadb'))
209+
210+
- name: Unit tests
211+
run: |
212+
cd galette-core/galette/plugins/plugin-auto
213+
../../vendor/bin/phpunit --test-suffix=.php --bootstrap tests/TestsBootstrap.php --no-coverage --process-isolation tests/GaletteAuto/

Diff for: tests/GaletteAuto/tests/units/Color.php

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/**
4+
* Copyright © 2003-2024 The Galette Team
5+
*
6+
* This file is part of Galette (https://galette.eu).
7+
*
8+
* Galette is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* Galette is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
22+
namespace GaletteAuto\tests\units;
23+
24+
use Galette\GaletteTestCase;
25+
26+
/**
27+
* Color tests
28+
*
29+
* @author Johan Cwiklinski <[email protected]>
30+
*/
31+
class Color extends GaletteTestCase
32+
{
33+
protected int $seed = 20240130141727;
34+
35+
/**
36+
* Test empty
37+
*
38+
* @return void
39+
*/
40+
public function testEmpty(): void
41+
{
42+
/** @var \Galette\Core\Plugins */
43+
global $plugins;
44+
45+
$color = new \GaletteAuto\Color($this->zdb);
46+
$this->assertSame('Color', $color->getFieldLabel());
47+
48+
$this->assertSame([], $color->getList());
49+
$this->assertSame('', $color->displayCount());
50+
}
51+
}

Diff for: tests/TestsBootstrap.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/**
4+
* Copyright © 2003-2024 The Galette Team
5+
*
6+
* This file is part of Galette (https://galette.eu).
7+
*
8+
* Galette is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* Galette is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
22+
/**
23+
* Bootstrap tests file for Galette Auto plugin
24+
*
25+
* @author Johan Cwiklinski <[email protected]>
26+
*/
27+
28+
define('GALETTE_PLUGINS_PATH', __DIR__ . '/../../');
29+
$basepath = '../../../galette/';
30+
31+
include_once '../../../tests/TestsBootstrap.php';
32+
require_once __DIR__ . '/../_config.inc.php';

0 commit comments

Comments
 (0)