Skip to content

Commit

Permalink
Add |./start.sh -tests| option
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoChevalier committed Jan 18, 2016
1 parent ebf5aa9 commit 6d5834f
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 55 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ Then switch to a new branch where you will work on the patch you want to propose
```bash
git checkout -b my_new_branch
```
- Launch unit tests:
- Launch PHP-cs-fixer, unit and functional tests:
```bash
php vendor/atoum/atoum/bin/atoum -d tests/units/
start.sh -tests
```
- Update dependencies with composer:
```bash
Expand Down
53 changes: 44 additions & 9 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,58 @@
# Use 'start.sh -remote' if you want to access the server from another machine (or a VM)
SERVER="localhost:8082"

SUPPORTED_COMMANDS=(
'-help'
'-remote'
'-tests'
'-tests-server'
)

if [ $# -gt 0 ]
then
if [ $1 = '-remote' ]
then
SERVER="0.0.0.0:8082"
elif [ $1 = '-help' ]
supported_command=false
for command in ${SUPPORTED_COMMANDS[@]};
do
if [ "${command}" == "$1" ];
then
supported_command=true
break
fi
done
if [ "${supported_command}" = false ];
then
echo "Usage: start.sh (PHP web server will be listening to localhost:8082)"
echo "Usage: start.sh -remote (PHP web server will be listening to 0.0.0.0:8082 and accessible from the outside)"
echo "Additional parameters will be ignored."
exit 1
else
echo "Unknown parameter \`${1}\`. Type \`start.sh -help\` to know what the valid parameters are."
exit 1
fi
fi

if [ $# -gt 0 ] && [ $1 = '-help' ]
then
echo "Usage: start.sh (PHP web server will be listening to localhost:8082)"
echo "Usage: start.sh -remote (PHP web server will be listening to 0.0.0.0:8082 and accessible from the outside)"
echo "Usage: start.sh -tests (Run all the unit and functional tests and check PHP syntax with PHP-cs-fixer)"
echo "Usage: start.sh -tests-server (Internal use — Run PHP web server listening to localhost:8083)"
echo "Additional parameters will be ignored."
exit 1
fi

./app/scripts/dev-setup.sh

case "$1" in
-remote)
SERVER="0.0.0.0:8082"
;;
-tests)
php ./vendor/atoum/atoum/bin/atoum -d tests/units/
php ./tests/functional/api.php
php ./tests/functional/pages.php
vendor/bin/php-cs-fixer --diff --dry-run -v fix
exit 1
;;
-tests-server)
SERVER="localhost:8083"
;;
esac

echo -e $(tput setaf 2; tput bold)"Launching PHP development server (php -S ${SERVER} -t web/ app/inc/router.php)"$(tput sgr0)
php -S ${SERVER} -t web/ app/inc/router.php
24 changes: 2 additions & 22 deletions tests/functional/api.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
<?php
define('INSTALL_ROOT', realpath(__DIR__ . '/../../') . '/');

// We always work with UTF8 encoding
mb_internal_encoding('UTF-8');

// Make sure we have a timezone set
date_default_timezone_set('Europe/Paris');

require __DIR__ . '/../../vendor/autoload.php';

// Set an environment variable so that the instance will use content from test files
putenv("AUTOMATED_TESTS=true");

// Launch PHP dev server in the background
chdir(INSTALL_ROOT);
exec('./start.sh -remote > /dev/null 2>&1 & echo $!', $output);

// We will need the pid to kill it, beware, this is the pid of the bash process started with start.sh
$pid = $output[0];

// Pause to let time for the dev server to launch in the background
sleep(3);
include 'includes/init.php';

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

$obj = new \pchevrel\Verif('Check API HTTP responses');
$obj
->setHost('localhost:8082')
->setHost('localhost:8083')
->setPathPrefix('api/');

$check = function ($object, $paths) {
Expand Down
24 changes: 24 additions & 0 deletions tests/functional/includes/init.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

define('INSTALL_ROOT', realpath(__DIR__ . '/../../../') . '/');

// We always work with UTF8 encoding
mb_internal_encoding('UTF-8');

// Make sure we have a timezone set
date_default_timezone_set('Europe/Paris');

require __DIR__ . '/../../../vendor/autoload.php';

// Set an environment variable so that the instance will use content from test files
putenv("AUTOMATED_TESTS=true");

// Launch PHP dev server in the background
chdir(INSTALL_ROOT);
exec('./start.sh -tests-server > /dev/null 2>&1 & echo $!', $output);

// We will need the pid to kill it, beware, this is the pid of the bash process started with start.sh
$pid = $output[0];

// Pause to let time for the dev server to launch in the background
sleep(3);
24 changes: 2 additions & 22 deletions tests/functional/pages.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
<?php
define('INSTALL_ROOT', realpath(__DIR__ . '/../../') . '/');

// We always work with UTF8 encoding
mb_internal_encoding('UTF-8');

// Make sure we have a timezone set
date_default_timezone_set('Europe/Paris');

require __DIR__ . '/../../vendor/autoload.php';

// Set an environment variable so that the instance will use content from test files
putenv("AUTOMATED_TESTS=true");

// Launch PHP dev server in the background
chdir(INSTALL_ROOT);
exec('./start.sh -remote > /dev/null 2>&1 & echo $!', $output);

// We will need the pid to kill it, beware, this is the pid of the bash process started with start.sh
$pid = $output[0];

// Pause to let time for the dev server to launch in the background
sleep(3);
include 'includes/init.php';

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

$obj = new \pchevrel\Verif('Check public pages HTTP responses and content');
$obj
->setHost('localhost:8082')
->setHost('localhost:8083')
->setPathPrefix('');

$check = function ($object, $paths) {
Expand Down

0 comments on commit 6d5834f

Please sign in to comment.