-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-tests.sh
More file actions
executable file
·88 lines (77 loc) · 2.89 KB
/
Copy pathrun-tests.sh
File metadata and controls
executable file
·88 lines (77 loc) · 2.89 KB
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
87
88
#!/bin/bash
# run-tests.sh
# Define color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to display help message
usage() {
echo -e "${GREEN}Usage:${NC} $0 [OPTIONS]"
echo "Run specified WordPress tests."
echo ""
echo -e "${YELLOW}Options:${NC}"
echo " --help Display this help and exit."
echo " --test-case=TestCase Run all tests in the specified test case."
echo " --test-method=TestMethod Run a specific test method within the specified test case (requires --test-case)."
echo ""
echo "Without any options, the default behavior is to run all tests."
exit 1
}
# Initialize parameters
TESTCASE=""
TESTMETHOD=""
# Parse command-line arguments
while [ "$1" != "" ]; do
case "$1" in
--test-case=* )
TESTCASE="${1#*=}"
;;
--test-method=* )
TESTMETHOD="${1#*=}"
;;
--help )
usage
;;
* )
echo -e "${RED}Unknown option: $1${NC}"
usage
;;
esac
shift
done
# Ensure the script stops on first error
set -e
if [ -z "$TESTCASE" ] && [ -z "$TESTMETHOD" ]; then
echo -e "${GREEN}✅ No specific test or test case provided. Running all tests.${NC}"
elif [ -n "$TESTCASE" ] && [ -z "$TESTMETHOD" ]; then
echo -e "${GREEN}✅ Running specific test case: $TESTCASE${NC}"
elif [ -n "$TESTCASE" ] && [ -n "$TESTMETHOD" ]; then
echo -e "${GREEN}✅ Running specific test method: $TESTCASE::$TESTMETHOD${NC}"
else
echo -e "${RED}❌ Invalid options supplied. --test-method requires --test-case.${NC}"
echo -e "${GREEN}Usage: $0 [OPTIONS]${NC}"
exit 1
fi
# Navigate to the script directory
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$DIR"
# Try to Install WordPress.
docker-compose run --rm -T wpcli db reset --yes > /dev/null 2>&1
docker-compose run --rm -T wpcli core install --url=http://localhost:8000 --title=phpnomadTests --admin_user=admin --admin_password=admin --admin_email=ad@min.com > /dev/null 2>&1
# Function to run tests based on provided options
run_tests() {
if [ -z "$TESTCASE" ] && [ -z "$TESTMETHOD" ]; then
docker-compose exec -T wordpress bash -c "cd /var/www/html && phpunit -c /var/www/html/tests/phpunit.xml"
elif [ -n "$TESTCASE" ] && [ -z "$TESTMETHOD" ]; then
docker-compose exec -T wordpress bash -c "cd /var/www/html && phpunit -c /var/www/html/tests/phpunit.xml --filter $TESTCASE"
elif [ -n "$TESTCASE" ] && [ -n "$TESTMETHOD" ]; then
docker-compose exec -T wordpress bash -c "cd /var/www/html && phpunit -c /var/www/html/tests/phpunit.xml --filter $TESTCASE::$TESTMETHOD"
else
echo -e "${RED}❌ Invalid options supplied. --test-method requires --test-case.${NC}"
echo -e "${GREEN}Usage: $0 [OPTIONS]${NC}"
exit 1
fi
}
# Call the function to run the tests
run_tests