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

Docker testing setup #206

Merged
merged 35 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7b2976d
New PHP-CS-Fixer configuration
DamienHarper Aug 13, 2024
0f7cda8
rector pass #1
DamienHarper Aug 13, 2024
73bdeda
rector pass #2
DamienHarper Aug 13, 2024
dfb5971
rector pass #3
DamienHarper Aug 13, 2024
b06c86d
PHPUnit 11
DamienHarper Aug 13, 2024
004f9b7
rector pass #4 + PHPUnit covers
DamienHarper Aug 13, 2024
b2502c9
rector pass #4 + PHPUnit covers
DamienHarper Aug 14, 2024
6952dd0
CoversClass and CoversTrait
DamienHarper Aug 14, 2024
dcbcdd2
cleanup
DamienHarper Aug 14, 2024
93a0343
CoversTrait use
DamienHarper Aug 14, 2024
7c4bf9b
PHP Docker image with required extensions installed (composer, pdo_my…
DamienHarper Aug 20, 2024
dd5cc94
Makefile to ease launching tests in various configurations
DamienHarper Aug 20, 2024
bfb5478
Renamed `php` to `php-cli` and added cleanup options to `docker compo…
DamienHarper Aug 20, 2024
de4465f
Only allow specific combinations of PHP and Symfony
DamienHarper Aug 20, 2024
26d8d99
Only warn about invalid combinations
DamienHarper Aug 20, 2024
3b8a527
Moved docker files in `tools/docker` folder
DamienHarper Aug 20, 2024
bb58fc6
Help is displayed by default
DamienHarper Aug 20, 2024
213e623
Add MySQL and PostrgreSQL support
DamienHarper Aug 20, 2024
2adc2a9
Add MariaDB support
DamienHarper Aug 20, 2024
1abc578
Removed unused PHPUnit config files
DamienHarper Aug 20, 2024
f28cdf4
Named container group
DamienHarper Aug 20, 2024
b77d531
Switched from PCOV to XDEBUG for code coverage
DamienHarper Aug 20, 2024
76caf4e
PHP-CS-Fixer
DamienHarper Aug 29, 2024
807677e
Ensures phpunit is run through php-cli service
DamienHarper Aug 29, 2024
e6a814a
Add `phpstan` and `cs-fix` targets
DamienHarper Aug 29, 2024
1afafb3
Add volumes to hold tools vendors
DamienHarper Aug 29, 2024
8f935a9
Use of environment variables
DamienHarper Aug 29, 2024
744245b
Get rid of composer.lock before and after installing dependencies
DamienHarper Aug 30, 2024
12e36e0
Build image using proper PHP version
DamienHarper Aug 30, 2024
1cb6b8d
Fixed failing CI
DamienHarper Aug 30, 2024
97b95f4
Fixed failing CI (round #2)
DamienHarper Aug 30, 2024
aec99b6
Fixed failing CI (round #3)
DamienHarper Aug 30, 2024
a9d769a
Fixed failing CI (round #4)
DamienHarper Aug 30, 2024
d8f45c3
Silence common commands
DamienHarper Aug 30, 2024
53fe926
Adjusted help text
DamienHarper Aug 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions .github/workflows/ci-3.x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
mysql:
image: mysql:8
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: auditor
ports:
- 3306:3306
Expand All @@ -55,7 +55,7 @@ jobs:
--health-retries=3

postgres:
image: postgres
image: postgres:15
env:
POSTGRES_PASSWORD: password
ports:
Expand All @@ -82,6 +82,15 @@ jobs:
fail-fast: false

steps:
- name: Configure Database
run: |
if [ "${{ matrix.db }}" = "sqlite" ]; then
echo "DATABASE_URL=sqlite:///:memory:" >> $GITHUB_ENV
elif [ "${{ matrix.db }}" = "mysql" ]; then
echo "DATABASE_URL=mysql://root:[email protected]/auditor?serverVersion=8&charset=utf8mb4" >> $GITHUB_ENV
elif [ "${{ matrix.db }}" = "pgsql" ]; then
echo "DATABASE_URL=pgsql://postgres:password@localhost/auditor?serverVersion=15&charset=utf8" >> $GITHUB_ENV
fi
- name: Shutdown Ubuntu MySQL (SUDO)
run: sudo service mysql stop # Shutdown the Default MySQL, "sudo" is necessary, please do not remove it

Expand Down Expand Up @@ -114,15 +123,21 @@ jobs:

- name: Update project dependencies (5.*)
if: matrix.symfony == '5.*'
run: SYMFONY_REQUIRE="^5.4" composer update --no-progress --ansi --prefer-stable
env:
SYMFONY_REQUIRE: "^5.4"
run: composer update --no-progress --ansi --prefer-stable

- name: Update project dependencies (6.*)
if: matrix.symfony == '6.*'
run: SYMFONY_REQUIRE="^6.0" composer update --no-progress --ansi --prefer-stable
env:
SYMFONY_REQUIRE: "^6.0"
run: composer update --no-progress --ansi --prefer-stable

- name: Update project dependencies (7.*)
if: matrix.symfony == '7.*'
run: SYMFONY_REQUIRE="^7.0" composer update --no-progress --ansi --prefer-stable
env:
SYMFONY_REQUIRE: "^7.0"
run: composer update --no-progress --ansi --prefer-stable

- name: Install PHPStan
run: composer install --no-progress --ansi --working-dir=tools/phpstan
Expand All @@ -131,10 +146,13 @@ jobs:
run: composer phpstan

- name: Run tests
env:
XDEBUG_MODE: coverage
DATABASE_URL: ${{ env.DATABASE_URL }}
run: |
RAW_CODECOV_REPORT="php-${{ matrix.php }}-sf-${{ matrix.symfony }}-${{ matrix.db }}-coverage"
echo "CODECOV_REPORT=$(echo $RAW_CODECOV_REPORT | sed 's/\.\*//')" >> $GITHUB_ENV
vendor/bin/phpunit -c phpunit.${{ matrix.db }}.xml --coverage-clover=coverage.xml
vendor/bin/phpunit -c phpunit.xml --coverage-clover=coverage.xml

- name: Upload coverage file
uses: actions/upload-artifact@v3
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ tests/coverage/
.php_cs.cache
.php-cs-fixer.cache
.phpunit.result.cache
.phpunit.cache/
composer.lock
*.sqlite
50 changes: 50 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);

use PhpCsFixer\Config;
use PhpCsFixer\Finder;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;

return (new Config())
->setParallelConfig(ParallelConfigFactory::detect()) // @TODO 4.0 no need to call this manually :poop:
->setRiskyAllowed(true)
->setRules([
'@PHP82Migration' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'@DoctrineAnnotation' => true,
'@PhpCsFixer' => true,
'@PhpCsFixer:risky' => true,
'@PHPUnit100Migration:risky' => true,
// 'date_time_immutable' => true,
'general_phpdoc_annotation_remove' => [
'annotations' => [
'expectedDeprecation',
'expectedException',
'expectedExceptionMessage',
'expectedExceptionMessageRegExp',
],
],
'ordered_interfaces' => true,
'ordered_traits' => true,
'phpdoc_to_param_type' => true,
'phpdoc_to_property_type' => true,
'phpdoc_to_return_type' => true,
'regular_callable_call' => true,
'simplified_if_return' => true,
'get_class_to_class_keyword' => true,
'mb_str_functions' => true,
'modernize_strpos' => true,
'no_useless_concat_operator' => false, // TODO switch back on when the `src/Console/Application.php` no longer needs the concat
'numeric_literal_separator' => true,
'string_implicit_backslashes' => true, // https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/pull/7786
'php_unit_test_case_static_method_calls' => false,
])
->setFinder(
(new Finder())
->ignoreDotFiles(false)
->ignoreVCSIgnored(true)
->in(__DIR__.'/src')
->in(__DIR__.'/tests')
)
;
50 changes: 0 additions & 50 deletions .php-cs-fixer.php

This file was deleted.

122 changes: 122 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Default values
php ?= 8.3
sf ?= 7.1
db ?= sqlite
args ?=

# Allowed PHP and Symfony version combinations
# (PHP_VERSION;SYMFONY_VERSION)
valid_combinations = \
8.2;5.4 \
8.2;6.4 \
8.2;7.1 \
8.3;6.4 \
8.3;7.1

current_combination = $(php);$(sf)

# list of config files to provide to docker compose
compose_files = -f tools/docker/compose.yaml

# Set the DATABASE_URL and dedicated compose file based on the selected database
ifeq ($(db),mysql)
DATABASE_URL = "mysql://auditor:[email protected]:3360/auditor?serverVersion=8&charset=utf8mb4"
compose_files += -f tools/docker/compose.mysql.yaml
else ifeq ($(db),pgsql)
DATABASE_URL = "pgsql://postgres:[email protected]:5432/auditor?serverVersion=15&charset=utf8"
compose_files += -f tools/docker/compose.pgsql.yaml
else ifeq ($(db),mariadb)
DATABASE_URL = "mysql://auditor:[email protected]:3366/auditor?serverVersion=8&charset=utf8mb4"
compose_files += -f tools/docker/compose.mariadb.yaml
else ifeq ($(db),sqlite)
DATABASE_URL = "sqlite:///:memory:"
else
$(error Unknown database type: $(db))
endif

# Help target
.PHONY: help
help:
@echo "Usage: make <target> [php=<php_version>] [sf=<symfony_version>] [db=<database>] [args=<phpunit_args>]"
@echo ""
@echo "Targets:"
@echo " tests - Run the test suite using PHPUnit."
@echo " cs-fix - Run PHP-CS-Fixer to fix coding standards issues."
@echo " phpstan - Run PHPStan for static code analysis."
@echo ""
@echo "Options:"
@echo " php - PHP version to use (default: $(php)). Supported: 8.2, 8.3"
@echo " sf - Symfony version to use (default: $(sf)). Supported: 5.4, 6.4, 7.1"
@echo " db - Database type (default: $(db)). Supported: sqlite, mysql, pgsql, mariadb"
@echo " args - Additional arguments:"
$(eval $(call set_args,tests))
@echo " Defaults for 'tests' target: $(args)"
$(eval $(call set_args,phpstan))
@echo " Defaults for 'phpstan' target: $(args)"
$(eval $(call set_args,cs-fix))
@echo " Defaults for 'cs-fix' target: $(args)"
@echo ""
@echo "Examples:"
@echo " make tests php=8.2 sf=6.4 db=mysql"
@echo " make cs-fix"
@echo " make phpstan"
@echo " make tests args='--filter=TestClassName'"
@echo ""
@echo "Note: Ensure that the PHP and Symfony versions are valid combinations:"
@echo " $(valid_combinations) (PHP_VERSION;SYMFONY_VERSION)"

# Common target setup
define common_setup
@rm -f composer.lock
@PHP_VERSION=$(php) SYMFONY_VERSION=$(sf) DATABASE_URL=$(DATABASE_URL) \
sh -c "docker compose $(compose_files) run --rm --remove-orphans php-cli composer global config --no-plugins allow-plugins.symfony/flex true"
@PHP_VERSION=$(php) SYMFONY_VERSION=$(sf) \
sh -c "docker compose $(compose_files) run --rm --remove-orphans php-cli composer global require --no-progress --no-scripts --no-plugins symfony/flex --quiet"
@PHP_VERSION=$(php) SYMFONY_VERSION=$(sf) DATABASE_URL=$(DATABASE_URL) \
sh -c "docker compose $(compose_files) run --rm --remove-orphans php-cli composer install --quiet"
endef

# Run PHPUnit target
.PHONY: tests
tests: validate_matrix
$(eval $(call set_args,tests))
$(call common_setup)
PHP_VERSION=$(php) SYMFONY_VERSION=$(sf) DATABASE_URL=$(DATABASE_URL) \
sh -c "docker compose $(compose_files) run --rm --remove-orphans php-cli vendor/bin/phpunit $(args)"

# Run PHPStan target
.PHONY: phpstan
phpstan: validate_matrix
$(eval $(call set_args,phpstan))
$(call common_setup)
PHP_VERSION=$(php) SYMFONY_VERSION=$(sf) \
sh -c "docker compose $(compose_files) run --rm --remove-orphans php-cli tools/phpstan/vendor/bin/phpstan $(args)"

# Run PHP-CS-Fixer target
.PHONY: cs-fix
cs-fix: validate_matrix
$(eval $(call set_args,cs-fix))
$(call common_setup)
PHP_VERSION=$(php) SYMFONY_VERSION=$(sf) \
sh -c "docker compose $(compose_files) run --rm --remove-orphans php-cli tools/php-cs-fixer/vendor/bin/php-cs-fixer $(args)"

# Validate PHP and Symfony version matrix
validate_matrix:
@if ! echo "$(valid_combinations)" | grep -q "$(current_combination)"; then \
echo "Error: Invalid combination of PHP and Symfony versions: php=$(php), sf=$(sf)"; \
echo "Allowed combinations are:"; \
echo "(PHP_VERSION;SYMFONY_VERSION)"; \
echo "$(valid_combinations)" | tr ' ' '\n'; \
exit 1; \
fi

# Set default args for each target
define set_args
ifeq ($(1),tests)
args := --colors=always --no-coverage
else ifeq ($(1),phpstan)
args := analyse src --memory-limit=1G --ansi
else ifeq ($(1),cs-fix)
args := fix --using-cache=no --verbose --ansi
endif
endef
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
}
},
"require-dev": {
"gedmo/doctrine-extensions": "^3.0",
"doctrine/data-fixtures": "^1.5.3",
"phpunit/phpunit": "^9.0",
"gedmo/doctrine-extensions": "^3.0",
"phpunit/phpunit": "^11.0",
"symfony/var-dumper": "^5.4|^6.0|^7.0"
},
"scripts": {
"test": "php -d pcov.enabled=1 ./vendor/bin/phpunit --colors=always",
"csfixer": "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --using-cache=no --verbose --ansi",
"cs-check": "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --using-cache=no --verbose --ansi --dry-run",
"test": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --colors=always",
"cs-fix": "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --using-cache=no --verbose --ansi",
"cs-check": "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --using-cache=no --verbose --ansi --dry-run",
"phpstan": "tools/phpstan/vendor/bin/phpstan --memory-limit=1G --ansi analyse src",
"rector": "tools/rector/vendor/bin/rector",
"rector-check": "tools/rector/vendor/bin/rector --dry-run",
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ parameters:
return_type: 100
param_type: 100
property_type: 100
constant: 0

paths:
- src
Expand All @@ -17,4 +18,3 @@ parameters:
- '~Dead catch - Throwable is never thrown in the try block~'
- '~Parameter \#1 \$className of method Doctrine\\ORM\\EntityManagerInterface\:\:getClassMetadata\(\) expects class-string<object>, string given\.~'
- '~Unable to resolve the template type T in call to method Doctrine\\ORM\\EntityManagerInterface\:\:getClassMetadata\(\)~'
- '~Property DH\\Auditor\\Provider\\Doctrine\\Configuration\:\:\$(storage|auditing)Services is never read, only written\.~'
30 changes: 0 additions & 30 deletions phpunit.mariadb.xml

This file was deleted.

Loading
Loading