Skip to content

Commit d66deb9

Browse files
authored
Testing improvements and add integration test matrix script (#183)
1 parent 0300971 commit d66deb9

File tree

6 files changed

+137
-6
lines changed

6 files changed

+137
-6
lines changed

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"require-dev": {
2828
"guzzlehttp/guzzle": "^7.0",
29-
"phpunit/phpunit": "*",
29+
"phpunit/phpunit": "^9.5 || ^10.0 || ^11.0 || ^12.0",
3030
"phpstan/phpstan": "^2.1"
3131
},
3232
"suggest": {
@@ -45,5 +45,9 @@
4545
},
4646
"config": {
4747
"preferred-install": "dist"
48+
},
49+
"scripts": {
50+
"test": "./scripts/phpunit.sh",
51+
"int": "./scripts/integration-test.sh"
4852
}
4953
}

phpunit.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
colors="true"
4+
bootstrap="vendor/autoload.php"
5+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd">
36
<testsuites>
47
<testsuite name="Microsoft Dynamics SDK Test Suite">
58
<directory>tests</directory>
69
</testsuite>
710
</testsuites>
8-
<!-- <logging>
9-
<log type="coverage-html" target="coverage/report" charset="UTF-8" yui="true" highlight="true" lowUpperBound="50" highLowerBound="80"/>
10-
</logging> -->
1111
<source>
1212
<include>
1313
<directory suffix=".php">src</directory>
@@ -16,4 +16,4 @@
1616
<directory suffix=".php">src/Model</directory>
1717
</exclude>
1818
</source>
19-
</phpunit>
19+
</phpunit>

phpunit10.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
colors="true"
4+
bootstrap="vendor/autoload.php"
5+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd">
6+
<testsuites>
7+
<testsuite name="Microsoft Dynamics SDK Test Suite">
8+
<directory>tests</directory>
9+
</testsuite>
10+
</testsuites>
11+
<source>
12+
<include>
13+
<directory suffix=".php">src</directory>
14+
</include>
15+
<exclude>
16+
<directory suffix=".php">src/Model</directory>
17+
</exclude>
18+
</source>
19+
</phpunit>

phpunit9.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
colors="true"
4+
bootstrap="vendor/autoload.php"
5+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd">
6+
<testsuites>
7+
<testsuite name="Microsoft Dynamics SDK Test Suite">
8+
<directory>tests</directory>
9+
</testsuite>
10+
</testsuites>
11+
<coverage>
12+
<include>
13+
<directory suffix=".php">src</directory>
14+
</include>
15+
<exclude>
16+
<directory suffix=".php">src/Model</directory>
17+
</exclude>
18+
</coverage>
19+
</phpunit>

scripts/integration-test.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
3+
# Integration test script that runs tests against multiple PHP versions using Laravel Herd
4+
5+
# Array of PHP versions matching our GitHub Actions matrix
6+
PHP_VERSIONS=("7.4" "8.0" "8.1" "8.2" "8.3" "8.4")
7+
8+
# Colors for output
9+
GREEN='\033[0;32m'
10+
RED='\033[0;31m'
11+
YELLOW='\033[1;33m'
12+
NC='\033[0m' # No Color
13+
14+
echo "Starting integration tests across PHP versions..."
15+
echo "=============================================="
16+
17+
# Track overall success
18+
OVERALL_SUCCESS=true
19+
20+
# Iterate through each PHP version
21+
for VERSION in "${PHP_VERSIONS[@]}"; do
22+
echo ""
23+
echo -e "${YELLOW}Testing PHP $VERSION${NC}"
24+
echo "------------------------------"
25+
26+
# Switch PHP version using Herd
27+
echo "Switching to PHP $VERSION..."
28+
herd use php@$VERSION
29+
30+
if [ $? -ne 0 ]; then
31+
echo -e "${RED}Failed to switch to PHP $VERSION${NC}"
32+
OVERALL_SUCCESS=false
33+
continue
34+
fi
35+
36+
# Verify PHP version
37+
CURRENT_VERSION=$(php -v | head -n 1)
38+
echo "Current PHP: $CURRENT_VERSION"
39+
40+
# Update composer dependencies for this PHP version
41+
echo "Updating composer dependencies..."
42+
composer update --quiet
43+
44+
if [ $? -ne 0 ]; then
45+
echo -e "${RED}Failed to update dependencies for PHP $VERSION${NC}"
46+
OVERALL_SUCCESS=false
47+
continue
48+
fi
49+
50+
# Run tests
51+
echo "Running tests..."
52+
composer test
53+
54+
if [ $? -eq 0 ]; then
55+
echo -e "${GREEN}✓ Tests passed for PHP $VERSION${NC}"
56+
else
57+
echo -e "${RED}✗ Tests failed for PHP $VERSION${NC}"
58+
OVERALL_SUCCESS=false
59+
fi
60+
done
61+
62+
echo ""
63+
echo "=============================================="
64+
if [ "$OVERALL_SUCCESS" = true ]; then
65+
echo -e "${GREEN}All integration tests passed!${NC}"
66+
exit 0
67+
else
68+
echo -e "${RED}Some integration tests failed!${NC}"
69+
exit 1
70+
fi

scripts/phpunit.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
# Detect PHPUnit version and use appropriate configuration file
4+
5+
# Get PHPUnit version
6+
PHPUNIT_VERSION=$(vendor/bin/phpunit --version | grep -oP 'PHPUnit \K[0-9]+' || echo "0")
7+
8+
# Choose config file based on version
9+
if [ "$PHPUNIT_VERSION" -ge "10" ]; then
10+
CONFIG_FILE="phpunit10.xml"
11+
elif [ "$PHPUNIT_VERSION" -ge "9" ]; then
12+
CONFIG_FILE="phpunit9.xml"
13+
else
14+
# Fall back to phpunit9.xml for older versions
15+
CONFIG_FILE="phpunit9.xml"
16+
fi
17+
18+
# Run PHPUnit with the appropriate config
19+
vendor/bin/phpunit -c "$CONFIG_FILE" "$@"

0 commit comments

Comments
 (0)