Skip to content

Commit ac071fe

Browse files
authored
Add smoke & functional tests (#2)
* Remove HomeController * Uncomment the passwordStrength for UserRegistrationDto * Maildev is now required to up php container * Remove security to get a user * Only admins can see email address of user * Put user default password in UserFixture instead of Factory and change it * Add smoke & functionnal tests - Add smoke & functionnal tests - Add test-pack component - Add Monolog (avoid having exceptions line in phpunit text) - Add tests directory to phpstan - Ignore tests/bootstrap.php in php-cs-fixer - Add dama/doctrine-test-bundle - Add http-client component - Update Makefile to handle tests tasks * test-install instead of ci-install... * Add missing templates directory to php dockerfile * fix phpstan errors * Remove push & pull_request on 'on' * Use clock to generate the datetime of signedUri * Throw 400 if hash is expired or invalid and 410 if user is already validated * Update routing config to handle test, dev & prod env default_uri * Add more tests for Registration
1 parent d2ee286 commit ac071fe

32 files changed

Lines changed: 3133 additions & 125 deletions

.env.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# define your env variables for the test env here
2+
KERNEL_CLASS='App\Kernel'
3+
APP_SECRET='$ecretf0rt3st'
4+
FIXTURES_SIZE=none

.github/workflows/ci.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Execute CI tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request: ~
8+
9+
jobs:
10+
test-smoke:
11+
name: Run smoke tests
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Install the project for test environment
18+
run: make test-install
19+
20+
- name: Run smoke tests
21+
run: make test-smoke
22+
23+
test-functional:
24+
name: Run functional tests
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v4
29+
30+
- name: Install the project for test environment
31+
run: make test-install
32+
33+
- name: Run functional tests
34+
run: make test-functional

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ compose.override.yaml
1515
###> lexik/jwt-authentication-bundle ###
1616
/config/jwt/*.pem
1717
###< lexik/jwt-authentication-bundle ###
18+
19+
###> phpunit/phpunit ###
20+
/.phpunit.cache/
21+
###< phpunit/phpunit ###

.php-cs-fixer.dist.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
$finder = (new PhpCsFixer\Finder())
44
->in(__DIR__)
55
->exclude('var')
6+
->notPath([
7+
'tests/bootstrap.php',
8+
])
69
;
710

811
return (new PhpCsFixer\Config())

Makefile

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ RUN_PHP_ALONE=$(DOCKER_COMPOSE) run --no-deps --rm $(DOCKER_PHP_CONTAINER)
99
COMPOSER=$(EXEC_PHP) composer
1010
CONSOLE=$(EXEC_PHP) bin/console
1111

12+
test-%: RUN_PHP=$(DOCKER_COMPOSE) run --rm --env APP_ENV=test --env XDEBUG_MODE=off $(DOCKER_PHP_CONTAINER)
13+
test-%: CONSOLE=$(RUN_PHP) bin/console
14+
test-%: COMPOSER=$(RUN_PHP) composer
15+
1216
##
1317
###--------------#
1418
### Docker #
@@ -54,8 +58,9 @@ start: up ## Alias for up
5458
start-all: up-all ## Alias for up-all
5559

5660
install: pull compose.override.yaml up vendor db-schema-force generate-keypair db-fixtures ## Install the project
61+
test-install: pull vendor generate-keypair db-create db-schema-force db-fixtures ## Install the project for test environment.
5762

58-
.PHONY: up stop down pull sh build bash start start-all install
63+
.PHONY: up stop down pull sh build bash start start-all install test-install
5964

6065
##
6166
###----------------#
@@ -105,6 +110,27 @@ db-execute-down: ## Execute the latest migration versions down manually.
105110
.PHONY: db-create db-drop db-migrate db-validate db-schema db-schema-force db-diff db-update
106111
.PHONY: db-fixtures fixtures db-execute-up db-execute-down
107112

113+
##
114+
###-------------#
115+
### Tests #
116+
###-------------#
117+
##
118+
119+
test-smoke: ## Run smoke tests
120+
$(RUN_PHP) bin/phpunit --no-extensions --testsuite smoke
121+
122+
test-debug: ## Run tests with debug group/tags
123+
$(RUN_PHP) bin/phpunit --group debug
124+
125+
test-functional: ## Run functional tests
126+
$(RUN_PHP) bin/phpunit --testsuite functional
127+
128+
tests: test-smoke test-functional ## Execute all tests
129+
ts: test-smoke ## Alias for test-smoke
130+
tf: test-functional ## Alias for test-functional
131+
132+
.PHONY: test-smoke test-debug tests test-functional ts tf
133+
108134
##
109135
###-----------------#
110136
### Q&A tools #

bin/phpunit

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
if (!ini_get('date.timezone')) {
5+
ini_set('date.timezone', 'UTC');
6+
}
7+
8+
if (is_file(dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit')) {
9+
if (PHP_VERSION_ID >= 80000) {
10+
require dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit';
11+
} else {
12+
define('PHPUNIT_COMPOSER_INSTALL', dirname(__DIR__).'/vendor/autoload.php');
13+
require PHPUNIT_COMPOSER_INSTALL;
14+
PHPUnit\TextUI\Command::main();
15+
}
16+
} else {
17+
if (!is_file(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php')) {
18+
echo "Unable to find the `simple-phpunit.php` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
19+
exit(1);
20+
}
21+
22+
require dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php';
23+
}

compose.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ services:
3333
depends_on:
3434
postgres:
3535
condition: service_healthy
36+
maildev:
37+
condition: service_started
3638
volumes:
3739
- "./:/var/www:rw"
3840
environment:

composer.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"symfony/framework-bundle": "7.2.*",
4343
"symfony/intl": "7.2.*",
4444
"symfony/mailer": "7.2.*",
45+
"symfony/monolog-bundle": "^3.10",
4546
"symfony/property-access": "7.2.*",
4647
"symfony/property-info": "7.2.*",
4748
"symfony/runtime": "7.2.*",
@@ -52,12 +53,17 @@
5253
"symfony/yaml": "7.2.*"
5354
},
5455
"require-dev": {
56+
"dama/doctrine-test-bundle": "^8.3",
5557
"doctrine/doctrine-fixtures-bundle": "^4.1",
5658
"phpstan/extension-installer": "^1.4.3",
5759
"phpstan/phpstan": "^2.1.17",
5860
"phpstan/phpstan-doctrine": "^2.0.3",
5961
"phpstan/phpstan-strict-rules": "^2.0.4",
6062
"phpstan/phpstan-symfony": "^2.0.6",
63+
"phpunit/phpunit": "^12.2",
64+
"symfony/browser-kit": "7.2.*",
65+
"symfony/css-selector": "7.2.*",
66+
"symfony/http-client": "7.2.*",
6167
"symfony/maker-bundle": "^1.63",
6268
"symfony/stopwatch": "7.2.*",
6369
"symfony/web-profiler-bundle": "7.2.*",

0 commit comments

Comments
 (0)