From 18b09979d69833053416e874a48e5a68b0ede1c7 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Sun, 7 Jan 2024 22:12:29 +0100 Subject: [PATCH 1/8] Introduce a tests bootstrap file --- phpunit.xml.dist | 2 +- tests/bootstrap.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 tests/bootstrap.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 79b48462d..6cdcea71c 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -4,7 +4,7 @@ xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd" backupGlobals="false" colors="true" - bootstrap="vendor/autoload.php" + bootstrap="tests/bootstrap.php" > diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 000000000..d21c14df8 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,3 @@ + Date: Sun, 7 Jan 2024 22:15:17 +0100 Subject: [PATCH 2/8] Clean the tests cache only --- GNUmakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GNUmakefile b/GNUmakefile index 56b09638b..053308cea 100755 --- a/GNUmakefile +++ b/GNUmakefile @@ -15,7 +15,7 @@ help: ## Display this help menu @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' clean: ## Clear the application cache - rm -rf var/cache/* + rm -rf var/cache/test install: ## Install wallabag with the latest version @./scripts/install.sh $(ENV) From 3e403b84d3794436c8221d318742eb3a28b242fe Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Sun, 7 Jan 2024 22:15:55 +0100 Subject: [PATCH 3/8] Move tests cache clean to the bootstrap file --- GNUmakefile | 7 ++----- tests/bootstrap.php | 4 ++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 053308cea..378cfa7d5 100755 --- a/GNUmakefile +++ b/GNUmakefile @@ -14,9 +14,6 @@ endif help: ## Display this help menu @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' -clean: ## Clear the application cache - rm -rf var/cache/test - install: ## Install wallabag with the latest version @./scripts/install.sh $(ENV) @@ -34,7 +31,7 @@ build: ## Run webpack @yarn install @yarn build:$(ENV) -prepare: clean ## Prepare database for testsuite +prepare: ## Prepare database for testsuite ifdef DB cp app/config/tests/parameters_test.$(DB).yml app/config/parameters_test.yml endif @@ -57,6 +54,6 @@ endif deploy: ## Deploy wallabag @bundle exec cap staging deploy -.PHONY: help clean prepare install fixtures update build test release deploy run dev +.PHONY: help prepare install fixtures update build test release deploy run dev .DEFAULT_GOAL := install diff --git a/tests/bootstrap.php b/tests/bootstrap.php index d21c14df8..ab7b163e3 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,3 +1,7 @@ remove(__DIR__ . '/../var/cache/test'); From c35aa6407977edfa189b37e20e8c0c10c8ffb61f Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Sun, 7 Jan 2024 22:21:04 +0100 Subject: [PATCH 4/8] Move prepare database commands to CI workflow --- .github/workflows/continuous-integration.yml | 12 ++++++++++-- GNUmakefile | 3 --- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 43b45fe9b..172f40324 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -74,7 +74,11 @@ jobs: composer-options: "--optimize-autoloader --prefer-dist" - name: "Prepare database" - run: "make prepare DB=${{ matrix.database }}" + run: | + cp app/config/tests/parameters_test.${{ matrix.database }}.yml app/config/parameters_test.yml + php bin/console doctrine:database:drop --force --env=test + php bin/console doctrine:database:create --env=test + php bin/console doctrine:migrations:migrate --no-interaction --env=test -vv - name: "Prepare fixtures" run: "make fixtures" @@ -145,7 +149,11 @@ jobs: composer-options: "--optimize-autoloader --prefer-dist" - name: "Prepare database" - run: "make prepare DB=${{ matrix.database }}" + run: | + cp app/config/tests/parameters_test.${{ matrix.database }}.yml app/config/parameters_test.yml + php bin/console doctrine:database:drop --force --env=test + php bin/console doctrine:database:create --env=test + php bin/console doctrine:migrations:migrate --no-interaction --env=test -vv - name: "Prepare fixtures" run: "make fixtures" diff --git a/GNUmakefile b/GNUmakefile index 378cfa7d5..403551e08 100755 --- a/GNUmakefile +++ b/GNUmakefile @@ -32,9 +32,6 @@ build: ## Run webpack @yarn build:$(ENV) prepare: ## Prepare database for testsuite -ifdef DB - cp app/config/tests/parameters_test.$(DB).yml app/config/parameters_test.yml -endif -php bin/console doctrine:database:drop --force --env=test php bin/console doctrine:database:create --env=test php bin/console doctrine:migrations:migrate --no-interaction --env=test -vv From 4a4b584a46d9ea0c47995cf1ac15203e95403ee5 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Sun, 7 Jan 2024 22:29:51 +0100 Subject: [PATCH 5/8] Move prepare database commands to the bootstrap file --- .github/workflows/continuous-integration.yml | 16 ++++--------- GNUmakefile | 9 ++----- tests/bootstrap.php | 25 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 172f40324..ca38ff098 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -73,12 +73,8 @@ jobs: with: composer-options: "--optimize-autoloader --prefer-dist" - - name: "Prepare database" - run: | - cp app/config/tests/parameters_test.${{ matrix.database }}.yml app/config/parameters_test.yml - php bin/console doctrine:database:drop --force --env=test - php bin/console doctrine:database:create --env=test - php bin/console doctrine:migrations:migrate --no-interaction --env=test -vv + - name: "Prepare database configuration" + run: cp app/config/tests/parameters_test.${{ matrix.database }}.yml app/config/parameters_test.yml - name: "Prepare fixtures" run: "make fixtures" @@ -148,12 +144,8 @@ jobs: with: composer-options: "--optimize-autoloader --prefer-dist" - - name: "Prepare database" - run: | - cp app/config/tests/parameters_test.${{ matrix.database }}.yml app/config/parameters_test.yml - php bin/console doctrine:database:drop --force --env=test - php bin/console doctrine:database:create --env=test - php bin/console doctrine:migrations:migrate --no-interaction --env=test -vv + - name: "Prepare database configuration" + run: cp app/config/tests/parameters_test.${{ matrix.database }}.yml app/config/parameters_test.yml - name: "Prepare fixtures" run: "make fixtures" diff --git a/GNUmakefile b/GNUmakefile index 403551e08..dd3a2dba1 100755 --- a/GNUmakefile +++ b/GNUmakefile @@ -31,15 +31,10 @@ build: ## Run webpack @yarn install @yarn build:$(ENV) -prepare: ## Prepare database for testsuite - -php bin/console doctrine:database:drop --force --env=test - php bin/console doctrine:database:create --env=test - php bin/console doctrine:migrations:migrate --no-interaction --env=test -vv - fixtures: ## Load fixtures into database php bin/console doctrine:fixtures:load --no-interaction --env=test -test: prepare fixtures ## Launch wallabag testsuite +test: fixtures ## Launch wallabag testsuite XDEBUG_MODE=off php -dmemory_limit=-1 bin/phpunit -v release: ## Create a package. Need a VERSION parameter (eg: `make release VERSION=master`). @@ -51,6 +46,6 @@ endif deploy: ## Deploy wallabag @bundle exec cap staging deploy -.PHONY: help prepare install fixtures update build test release deploy run dev +.PHONY: help install fixtures update build test release deploy run dev .DEFAULT_GOAL := install diff --git a/tests/bootstrap.php b/tests/bootstrap.php index ab7b163e3..76ba2f059 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,7 +1,32 @@ remove(__DIR__ . '/../var/cache/test'); + +(new Process([ + 'php', + __DIR__ . '/../bin/console', + 'doctrine:database:drop', + '--force', + '--env=test', +]))->run(); + +(new Process([ + 'php', + __DIR__ . '/../bin/console', + 'doctrine:database:create', + '--env=test', +]))->mustRun(); + +(new Process([ + 'php', + __DIR__ . '/../bin/console', + 'doctrine:migrations:migrate', + '--no-interaction', + '--env=test', + '-vv', +]))->mustRun(); From 99ad390144fcd433c9846bf83b64203180aa8d23 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Sun, 7 Jan 2024 22:33:20 +0100 Subject: [PATCH 6/8] Move loading fixtures to the bootstrap file --- .github/workflows/continuous-integration.yml | 6 ------ GNUmakefile | 7 ++----- tests/bootstrap.php | 8 ++++++++ 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index ca38ff098..df7b4d378 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -76,9 +76,6 @@ jobs: - name: "Prepare database configuration" run: cp app/config/tests/parameters_test.${{ matrix.database }}.yml app/config/parameters_test.yml - - name: "Prepare fixtures" - run: "make fixtures" - - name: "Run PHPUnit" run: "php bin/phpunit -v" @@ -147,8 +144,5 @@ jobs: - name: "Prepare database configuration" run: cp app/config/tests/parameters_test.${{ matrix.database }}.yml app/config/parameters_test.yml - - name: "Prepare fixtures" - run: "make fixtures" - - name: "Run PHPUnit" run: "php bin/phpunit -v" diff --git a/GNUmakefile b/GNUmakefile index dd3a2dba1..1af36780b 100755 --- a/GNUmakefile +++ b/GNUmakefile @@ -31,10 +31,7 @@ build: ## Run webpack @yarn install @yarn build:$(ENV) -fixtures: ## Load fixtures into database - php bin/console doctrine:fixtures:load --no-interaction --env=test - -test: fixtures ## Launch wallabag testsuite +test: ## Launch wallabag testsuite XDEBUG_MODE=off php -dmemory_limit=-1 bin/phpunit -v release: ## Create a package. Need a VERSION parameter (eg: `make release VERSION=master`). @@ -46,6 +43,6 @@ endif deploy: ## Deploy wallabag @bundle exec cap staging deploy -.PHONY: help install fixtures update build test release deploy run dev +.PHONY: help install update build test release deploy run dev .DEFAULT_GOAL := install diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 76ba2f059..dce05cf6a 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -30,3 +30,11 @@ require __DIR__ . '/../vendor/autoload.php'; '--env=test', '-vv', ]))->mustRun(); + +(new Process([ + 'php', + __DIR__ . '/../bin/console', + 'doctrine:fixtures:load', + '--no-interaction', + '--env=test', +]))->mustRun(); From 369e7b6e045d52ff5dcc04b1e22fa75f799fd8ab Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Sun, 7 Jan 2024 22:47:00 +0100 Subject: [PATCH 7/8] Show the output of commands in the bootstrap file --- tests/bootstrap.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index dce05cf6a..a84eb8700 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -13,14 +13,18 @@ require __DIR__ . '/../vendor/autoload.php'; 'doctrine:database:drop', '--force', '--env=test', -]))->run(); +]))->run(function ($type, $buffer) { + echo $buffer; +}); (new Process([ 'php', __DIR__ . '/../bin/console', 'doctrine:database:create', '--env=test', -]))->mustRun(); +]))->mustRun(function ($type, $buffer) { + echo $buffer; +}); (new Process([ 'php', @@ -29,7 +33,9 @@ require __DIR__ . '/../vendor/autoload.php'; '--no-interaction', '--env=test', '-vv', -]))->mustRun(); +]))->mustRun(function ($type, $buffer) { + echo $buffer; +}); (new Process([ 'php', @@ -37,4 +43,6 @@ require __DIR__ . '/../vendor/autoload.php'; 'doctrine:fixtures:load', '--no-interaction', '--env=test', -]))->mustRun(); +]))->mustRun(function ($type, $buffer) { + echo $buffer; +}); From bd537a54fe2d7f9b60c48a6f62c2d242d9f02f36 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Tue, 9 Jan 2024 08:10:51 +0100 Subject: [PATCH 8/8] Update documentation to favor running PHPUnit directly --- .github/CONTRIBUTING.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 95eb97d61..6e2755201 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -52,8 +52,9 @@ All pull requests need to pass the tests and the code needs match the style guid To run the tests locally run: -- when testing using Docker: `docker-compose run --rm php make test` -- otherwise: `make test` +- when testing using Docker: `docker-compose run --rm php bin/phpunit` (or `docker-compose run --rm php make test` if you + prefer using `make`) +- otherwise: `bin/phpunit` (or `make test`) To run the PHP formatter: