feat(tests): add initial test structure and example tests

- Introduced Pest testing framework with basic test cases.
- Created TestCase and ExampleTest for unit testing.
- Updated phpunit.xml for improved test configuration.
This commit is contained in:
Jérémy Munsch 2026-11-03 16:20:14 +01:00
parent 3d50ba6ba2
commit fc267c330c
Signed by: forge-joniko
GPG key ID: D7EFE2F5CB6CC0E4
7 changed files with 253 additions and 47 deletions

17
.gitignore vendored
View file

@ -1,7 +1,16 @@
workspace.code-workspace
vendor
.phpunit.result.cache
.phpunit.cache
.vscode/launch.json
.vscode
auth.json
composer.lock
build
build/
*/temp/
.phpunit.result.cache
.phpunit.cache/
coverage/
tests/coverage/
junit.xml
coverage.xml
*-report.txt
test-output.txt
release_notes.md

View file

@ -1,26 +1,141 @@
# This file is a template, and might need editing before it works on your project.
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Composer.gitlab-ci.yml
include:
- project: "ldc-web/shared-ci"
ref: "main"
file: "lint/phpcs.yml"
- project: "ldc-web/shared-ci"
ref: "main"
file: "lint/phpstan.yml"
- project: "ldc-web/shared-ci"
ref: "main"
file: "security/composer.yml"
- project: "ldc-web/shared-ci"
ref: "main"
file: "test/test.yml"
stages:
- lint
- security
- test
- publish
- release
phplint:
stage: lint
image: $CI_REGISTRY/ldc-web/projets/ldc-web-images-docker/uwil-ci-8.5:latest
variables:
TEXT_REPORT: php-l-report.txt
before_script:
- composer config gitlab-token.lab.s-web.fr $CI_DEPLOY_USER $CI_DEPLOY_PASSWORD
- composer install --no-scripts --no-interaction --no-ansi --no-progress --prefer-dist
script:
- composer run-script lint:php > "$TEXT_REPORT" 2>&1; status=$?
- cat "$TEXT_REPORT"
- if [ $status -ne 0 ] || grep -qE "Parse error|Errors parsing" "$TEXT_REPORT"; then echo "PHP lint failed"; exit 1; fi
artifacts:
when: always
expose_as: "php-l report"
paths:
- php-l-report.txt
allow_failure: false
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
pint:
stage: lint
image: $CI_REGISTRY/ldc-web/projets/ldc-web-images-docker/uwil-ci-8.5:latest
variables:
PINT_REPORT: pint-report.txt
before_script:
- composer config gitlab-token.lab.s-web.fr $CI_DEPLOY_USER $CI_DEPLOY_PASSWORD
- composer install --no-scripts --no-interaction --no-ansi --no-progress --prefer-dist
script:
- vendor/bin/pint --test > "$PINT_REPORT" 2>&1; status=$?
- cat "$PINT_REPORT"
- if [ $status -ne 0 ] || grep -qE "ERROR|ERRORS|ERROR:" "$PINT_REPORT"; then echo "Pint reported errors"; exit 1; fi
artifacts:
when: always
expose_as: "pint report"
paths:
- pint-report.txt
allow_failure: false
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
pest:
stage: test
image: $CI_REGISTRY/ldc-web/projets/ldc-web-images-docker/uwil-ci-8.5:latest
variables:
JUNIT_REPORT: junit.xml
TEXT_REPORT: test-output.txt
COVERAGE_REPORT: coverage.xml
before_script:
- composer config gitlab-token.lab.s-web.fr $CI_DEPLOY_USER $CI_DEPLOY_PASSWORD
- composer install --no-scripts --no-interaction --no-ansi --no-progress --prefer-dist
script:
- rm -f "$JUNIT_REPORT" "$COVERAGE_REPORT"
- composer run-script test:coverage -- --min=85 > "$TEXT_REPORT" 2>&1; status=$?
- cat "$TEXT_REPORT"
- if [ -f "$COVERAGE_REPORT" ]; then echo "Coverage report generated $COVERAGE_REPORT"; else echo "No coverage report found"; fi
- exit $status
artifacts:
when: always
expose_as: "pest report"
paths:
- junit.xml
- test-output.txt
- coverage.xml
reports:
junit: junit.xml
allow_failure: false
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
# Publishes a tag/branch to Composer Packages of the current project
package-publish:
image: curlimages/curl:latest
stage: build
image: $CI_REGISTRY/ldc-web/projets/ldc-web-images-docker/uwil-ci-8.5:latest
stage: publish
variables:
URL: "$CI_SERVER_PROTOCOL://$CI_SERVER_HOST:$CI_SERVER_PORT/api/v4/projects/$CI_PROJECT_ID/packages/composer?job_token=$CI_JOB_TOKEN"
script:
# Check that the tag is on the main branch
- git fetch origin main
- |
if ! git branch -r --contains "$CI_COMMIT_SHA" | grep -q "origin/main"; then
echo "Erreur : Le tag $CI_COMMIT_TAG n'a pas été créé sur la branche main !"
exit 1
fi
# Publish Composer package
- insecure=$([ "$CI_SERVER_PROTOCOL" = "http" ] && echo "--insecure" || echo "")
- response=$(curl -s -w "\n%{http_code}" $insecure --data tag=$CI_COMMIT_TAG $URL)
- code=$(echo "$response" | tail -n 1)
- body=$(echo "$response" | head -n 1)
# Output state information
- if [ $code -eq 201 ]; then
echo "Package created - Code $code - $body";
- |
response=$(curl -s -w "\n%{http_code}" $insecure --data tag=$CI_COMMIT_TAG $URL)
code=$(echo "$response" | tail -n 1)
body=$(echo "$response" | head -n 1)
if [ $code -eq 201 ]; then
echo "Package created - Code $code - $body"
else
echo "Could not create package - Code $code - $body";
exit 1;
echo "Could not create package - Code $code - $body"
exit 1
fi
rules:
- if: '$CI_COMMIT_TAG =~ /^\d+.\d+.\d+/'
- if: '$CI_COMMIT_TAG =~ /^v?\d+\.\d+\.\d+/'
release:
stage: release
image: registry.gitlab.com/gitlab-org/cli:latest
needs:
- job: package-publish
rules:
- if: '$CI_COMMIT_TAG =~ /^v?\d+\.\d+\.\d+/'
before_script:
- |
tag_clean=$(echo "$CI_COMMIT_TAG" | sed 's/^v//')
sed -n "/## .*\[v\?${tag_clean}\]/,/## .*\[/p" CHANGELOG.md | sed '$d' > release_notes.md || true
if [ ! -s release_notes.md ]; then
echo "Release $CI_COMMIT_TAG du package uwil/storage-laravel." > release_notes.md
fi
script:
- echo "Création de la release $CI_COMMIT_TAG via glab CLI..."
release:
name: "Release $CI_COMMIT_TAG"
tag_name: "$CI_COMMIT_TAG"
ref: "$CI_COMMIT_TAG"
description: "./release_notes.md"

View file

@ -18,7 +18,8 @@
"laravel/pint": "^1.29",
"php-parallel-lint/php-parallel-lint": "^1.4",
"slevomat/coding-standard": "^8.22",
"pestphp/pest": "^5.3"
"pestphp/pest": "^5.3",
"orchestra/testbench": "^11.3"
},
"autoload": {
"psr-4": {
@ -27,7 +28,7 @@
},
"autoload-dev": {
"psr-4": {
"Uwil\\Storage\\Tests\\": "tests"
"Uwil\\Storage\\Tests\\": "tests/"
}
},
"extra": {
@ -41,7 +42,16 @@
}
},
"scripts": {
"test": "vendor/bin/pest"
"analyze": "./vendor/bin/phpstan analyse",
"format": "./vendor/bin/pint",
"lint": "./vendor/bin/phpcs && ./vendor/bin/pint --test",
"lint:fix": "./vendor/bin/phpcbf && ./vendor/bin/pint",
"lint:php": "./vendor/bin/parallel-lint --exclude vendor .",
"lint:phpcs": "./vendor/bin/phpcs",
"lint:phpstan": "./vendor/bin/phpstan analyse",
"lint:pint": "./vendor/bin/pint --test",
"test": "./vendor/bin/pest",
"test:coverage": "./vendor/bin/pest --log-junit=junit.xml --coverage --coverage-html=tests/coverage --coverage-clover=coverage.xml"
},
"config": {
"allow-plugins": {

View file

@ -1,25 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/13.4/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/coverage.xml"/>
</report>
</coverage>
<testsuites>
<testsuite name="Package">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
</php>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/13.4/phpunit.xsd"
bootstrap="vendor/autoload.php"
backupGlobals="false"
colors="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="false"
beStrictAboutOutputDuringTests="true"
cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="Feature Test Suite">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="Integration Test Suite">
<directory suffix="Test.php">./tests/Integration</directory>
</testsuite>
<testsuite name="Unit Test Suite">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<file>./src/StorageServiceProvider.php</file>
</exclude>
</source>
<php>
<env name="APP_ENV" value="testing"/>
<env name="APP_KEY" value="base64:6Cu/ozUs8DpKDquFeVu+dVAvuhVmZvOqYo8CXIG5SO8="/>
<env name="CACHE_STORE" value="array"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
</php>
</phpunit>

7
tests/Pest.php Normal file
View file

@ -0,0 +1,7 @@
<?php
declare(strict_types=1);
use Uwil\Storage\Tests\TestCase;
uses(TestCase::class)->in(__DIR__);

42
tests/TestCase.php Normal file
View file

@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace Uwil\Storage\Tests;
use Orchestra\Testbench\TestCase as Orchestra;
use Uwil\Storage\StorageServiceProvider;
abstract class TestCase extends Orchestra
{
#[\Override]
protected function setUp(): void
{
parent::setUp();
}
#[\Override]
protected function getPackageProviders($app): array
{
return [
StorageServiceProvider::class,
];
}
#[\Override]
protected function defineEnvironment($app): void
{
$app['config']->set('database.default', 'testing');
$app['config']->set('database.connections.testing', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]);
$app['config']->set('storage-service.default', 'local');
$app['config']->set('storage-service.eligibleDisks', ['local']);
$app['config']->set('storage-service.allowedExtensions', [
'jpg', 'jpeg', 'png', 'gif', 'pdf', 'txt', 'doc', 'docx', 'csv', 'mp4', 'webm',
]);
}
}

View file

@ -0,0 +1,7 @@
<?php
declare(strict_types=1);
test('it boots application correctly', function () {
expect(app())->not->toBeNull();
});