Skip to content

Commit 6d5834f

Browse files
committed
Add |./start.sh -tests| option
1 parent ebf5aa9 commit 6d5834f

5 files changed

Lines changed: 74 additions & 55 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ Then switch to a new branch where you will work on the patch you want to propose
7171
```bash
7272
git checkout -b my_new_branch
7373
```
74-
- Launch unit tests:
74+
- Launch PHP-cs-fixer, unit and functional tests:
7575
```bash
76-
php vendor/atoum/atoum/bin/atoum -d tests/units/
76+
start.sh -tests
7777
```
7878
- Update dependencies with composer:
7979
```bash

start.sh

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,58 @@
33
# Use 'start.sh -remote' if you want to access the server from another machine (or a VM)
44
SERVER="localhost:8082"
55

6+
SUPPORTED_COMMANDS=(
7+
'-help'
8+
'-remote'
9+
'-tests'
10+
'-tests-server'
11+
)
12+
613
if [ $# -gt 0 ]
714
then
8-
if [ $1 = '-remote' ]
9-
then
10-
SERVER="0.0.0.0:8082"
11-
elif [ $1 = '-help' ]
15+
supported_command=false
16+
for command in ${SUPPORTED_COMMANDS[@]};
17+
do
18+
if [ "${command}" == "$1" ];
19+
then
20+
supported_command=true
21+
break
22+
fi
23+
done
24+
if [ "${supported_command}" = false ];
1225
then
13-
echo "Usage: start.sh (PHP web server will be listening to localhost:8082)"
14-
echo "Usage: start.sh -remote (PHP web server will be listening to 0.0.0.0:8082 and accessible from the outside)"
15-
echo "Additional parameters will be ignored."
16-
exit 1
17-
else
1826
echo "Unknown parameter \`${1}\`. Type \`start.sh -help\` to know what the valid parameters are."
27+
exit 1
1928
fi
2029
fi
2130

31+
if [ $# -gt 0 ] && [ $1 = '-help' ]
32+
then
33+
echo "Usage: start.sh (PHP web server will be listening to localhost:8082)"
34+
echo "Usage: start.sh -remote (PHP web server will be listening to 0.0.0.0:8082 and accessible from the outside)"
35+
echo "Usage: start.sh -tests (Run all the unit and functional tests and check PHP syntax with PHP-cs-fixer)"
36+
echo "Usage: start.sh -tests-server (Internal use — Run PHP web server listening to localhost:8083)"
37+
echo "Additional parameters will be ignored."
38+
exit 1
39+
fi
40+
2241
./app/scripts/dev-setup.sh
2342

43+
case "$1" in
44+
-remote)
45+
SERVER="0.0.0.0:8082"
46+
;;
47+
-tests)
48+
php ./vendor/atoum/atoum/bin/atoum -d tests/units/
49+
php ./tests/functional/api.php
50+
php ./tests/functional/pages.php
51+
vendor/bin/php-cs-fixer --diff --dry-run -v fix
52+
exit 1
53+
;;
54+
-tests-server)
55+
SERVER="localhost:8083"
56+
;;
57+
esac
58+
2459
echo -e $(tput setaf 2; tput bold)"Launching PHP development server (php -S ${SERVER} -t web/ app/inc/router.php)"$(tput sgr0)
2560
php -S ${SERVER} -t web/ app/inc/router.php

tests/functional/api.php

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,6 @@
11
<?php
2-
define('INSTALL_ROOT', realpath(__DIR__ . '/../../') . '/');
32

4-
// We always work with UTF8 encoding
5-
mb_internal_encoding('UTF-8');
6-
7-
// Make sure we have a timezone set
8-
date_default_timezone_set('Europe/Paris');
9-
10-
require __DIR__ . '/../../vendor/autoload.php';
11-
12-
// Set an environment variable so that the instance will use content from test files
13-
putenv("AUTOMATED_TESTS=true");
14-
15-
// Launch PHP dev server in the background
16-
chdir(INSTALL_ROOT);
17-
exec('./start.sh -remote > /dev/null 2>&1 & echo $!', $output);
18-
19-
// We will need the pid to kill it, beware, this is the pid of the bash process started with start.sh
20-
$pid = $output[0];
21-
22-
// Pause to let time for the dev server to launch in the background
23-
sleep(3);
3+
include 'includes/init.php';
244

255
$paths = [
266
['', 400, '{"error":"No service requested"}'],
@@ -44,7 +24,7 @@
4424

4525
$obj = new \pchevrel\Verif('Check API HTTP responses');
4626
$obj
47-
->setHost('localhost:8082')
27+
->setHost('localhost:8083')
4828
->setPathPrefix('api/');
4929

5030
$check = function ($object, $paths) {

tests/functional/includes/init.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
define('INSTALL_ROOT', realpath(__DIR__ . '/../../../') . '/');
4+
5+
// We always work with UTF8 encoding
6+
mb_internal_encoding('UTF-8');
7+
8+
// Make sure we have a timezone set
9+
date_default_timezone_set('Europe/Paris');
10+
11+
require __DIR__ . '/../../../vendor/autoload.php';
12+
13+
// Set an environment variable so that the instance will use content from test files
14+
putenv("AUTOMATED_TESTS=true");
15+
16+
// Launch PHP dev server in the background
17+
chdir(INSTALL_ROOT);
18+
exec('./start.sh -tests-server > /dev/null 2>&1 & echo $!', $output);
19+
20+
// We will need the pid to kill it, beware, this is the pid of the bash process started with start.sh
21+
$pid = $output[0];
22+
23+
// Pause to let time for the dev server to launch in the background
24+
sleep(3);

tests/functional/pages.php

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,6 @@
11
<?php
2-
define('INSTALL_ROOT', realpath(__DIR__ . '/../../') . '/');
32

4-
// We always work with UTF8 encoding
5-
mb_internal_encoding('UTF-8');
6-
7-
// Make sure we have a timezone set
8-
date_default_timezone_set('Europe/Paris');
9-
10-
require __DIR__ . '/../../vendor/autoload.php';
11-
12-
// Set an environment variable so that the instance will use content from test files
13-
putenv("AUTOMATED_TESTS=true");
14-
15-
// Launch PHP dev server in the background
16-
chdir(INSTALL_ROOT);
17-
exec('./start.sh -remote > /dev/null 2>&1 & echo $!', $output);
18-
19-
// We will need the pid to kill it, beware, this is the pid of the bash process started with start.sh
20-
$pid = $output[0];
21-
22-
// Pause to let time for the dev server to launch in the background
23-
sleep(3);
3+
include 'includes/init.php';
244

255
$paths = [
266
['channelcomparizon/', 200, 'Compare strings from channel to channel', 'Key'],
@@ -39,7 +19,7 @@
3919

4020
$obj = new \pchevrel\Verif('Check public pages HTTP responses and content');
4121
$obj
42-
->setHost('localhost:8082')
22+
->setHost('localhost:8083')
4323
->setPathPrefix('');
4424

4525
$check = function ($object, $paths) {

0 commit comments

Comments
 (0)