-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphpunit
86 lines (72 loc) · 2.24 KB
/
phpunit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env bash
## Run project's PHPUnit tests.
##
## Usage: fin phpunit [arguments]
# Environment variables passed from fin:
#
# $PROJECT_ROOT - (string) absolute path to NEAREST .docksal folder
# $VIRTUAL_HOST - (string) ex. projectname.docksal
# $DOCROOT - name of the docroot folder
# $DOCKER_RUNNING - (string) "true" or "false"
path="/var/www"
phpunit_xml_path="$PROJECT_ROOT/phpunit.xml"
cd $PROJECT_ROOT
if [[ ! -f "$phpunit_xml_path" ]]; then
echo "Could not find $phpunit_xml_path"
exit 1
fi
phpunit_path="vendor/bin/phpunit"
paraunit_path="vendor/bin/paraunit"
if [[ ! -f "$phpunit_path" ]]; then
echo "Could not find $phpunit_path"
exit 1
fi
COVERAGE=false
CLEAR_LOGS=false
PARALLEL=true
args=""
while [ "$1" != "" ]; do
case $1 in
-c | --clear-logs)
CLEAR_LOGS=true
;;
--open-coverage)
COVERAGE=true
;;
-s | --force-sequential)
PARALLEL=false
;;
*)
args="$args $1"
;;
esac
shift
done
if $PARALLEL; then
if [[ ! -f "$paraunit_path" ]]; then
echo "Could not find $paraunit_path"
exit 1
fi
fi
timestamp=`date +%s`
COVERAGE_FILE="$path/$DOCROOT/sites/simpletest/coverage/coverage-${timestamp}.cov"
fin exec "mkdir -p $path/$DOCROOT/sites/simpletest/coverage"
if [ "${#args}" -eq 0 ] || $CLEAR_LOGS; then
# Clear coverage repository if the full test suite is run, meaning phpunit is
# invoked without any argument.
fin exec "rm -r $path/$DOCROOT/sites/simpletest/browser-output/Drupal_* 2> /dev/null"
fin exec "rm -r $path/$DOCROOT/sites/simpletest/coverage/* 2> /dev/null"
fin exec "rm -r $path/$DOCROOT/sites/simpletest/coverage-html/* 2> /dev/null"
fi
# Always create a dedicated coverage file for each test run. They get later
# merged together into an HTML report
if $PARALLEL; then
fin exec "XDEBUG_MODE=coverage $path/${paraunit_path} coverage -c $path ${args} --php $COVERAGE_FILE"
else
fin exec "XDEBUG_MODE=coverage $path/${phpunit_path} -c $path ${args} --coverage-php $COVERAGE_FILE"
fi
# Create the HTML report.
fin exec "phpcov merge --html $path/$DOCROOT/sites/simpletest/coverage-html $path/$DOCROOT/sites/simpletest/coverage"
if $COVERAGE; then
fin utils/open-link "http://${VIRTUAL_HOST}/sites/simpletest/coverage-html/dashboard.html"
fi