Skip to content

Commit e2df0d8

Browse files
Merge pull request #154 from alma/devx/dex-943-send-phpunit-tests-to-reportportal
[DEX-943] Send phpunit tests to Report Portal
2 parents 4a0a710 + a20e4be commit e2df0d8

4 files changed

Lines changed: 91 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ jobs:
5959
string=': void'
6060
grep -r -l "$string" tests/ | xargs sed -i "s/$string//g"
6161
62+
- name: Set ReportPortal configuration
63+
# ReportPortal agent only works for PHP 7.1, 7.2, 7.3 and 7.4
64+
if: (github.ref_name == 'main' || github.ref_name == 'develop') && vars.REPORT_PORTAL_ENABLED == 'true' && contains(fromJson('["7.1", "7.2", "7.3", "7.4"]'), matrix.php)
65+
run: ./tests/reportportal/reportportal_conf.sh
66+
env:
67+
REPORT_PORTAL_API_KEY: ${{ secrets.REPORT_PORTAL_API_KEY }}
68+
REPORT_PORTAL_ENDPOINT: ${{ vars.REPORT_PORTAL_ENDPOINT }}
69+
PHP_VERSION: ${{ matrix.php }}
70+
6271
- name: PHPUnit
6372
run: |
6473
case ${{ matrix.php }} in
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
312c312
2+
< $result = self::$client->post('v1/' . self::$projectName . '/launch', array(
3+
---
4+
> $result = self::$client->post('v2/' . self::$projectName . '/launch', array(
5+
337c337
6+
< $result = self::$client->put('v1/' . self::$projectName . '/launch/' . self::$launchID . '/finish', array(
7+
---
8+
> $result = self::$client->put('v2/' . self::$projectName . '/launch/' . self::$launchID . '/finish', array(
9+
358c358
10+
< $result = self::$client->put('v1/' . self::$projectName . '/launch/' . self::$launchID . '/stop', array(
11+
---
12+
> $result = self::$client->put('v2/' . self::$projectName . '/launch/' . self::$launchID . '/stop', array(
13+
383c383
14+
< $result = self::$client->post('v1/' . self::$projectName . '/item', array(
15+
---
16+
> $result = self::$client->post('v2/' . self::$projectName . '/item', array(
17+
425c425
18+
< $result = self::$client->post('v1/' . self::$projectName . '/log', array(
19+
---
20+
> $result = self::$client->post('v2/' . self::$projectName . '/log', array(
21+
478c478
22+
< 'v1/' . self::$projectName . '/log',
23+
---
24+
> 'v2/' . self::$projectName . '/log',
25+
500c500
26+
< $result = self::$client->put('v1/' . self::$projectName . '/item/' . $itemID, array(
27+
---
28+
> $result = self::$client->put('v2/' . self::$projectName . '/item/' . $itemID, array(
29+
507c507,508
30+
< 'status' => $status
31+
---
32+
> 'status' => $status,
33+
> 'launchUuid' => self::$launchID
34+
544c545
35+
< $result = self::$client->post('v1/' . self::$projectName . '/item/' . $parentItemID, array(
36+
---
37+
> $result = self::$client->post('v2/' . self::$projectName . '/item/' . $parentItemID, array(
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
3+
# exit if REPORT_PORTAL_API_KEY or REPORT_PORTAL_ENDPOINT is not set
4+
if [ -z "$REPORT_PORTAL_API_KEY" ] || [ -z "$REPORT_PORTAL_ENDPOINT" ]; then
5+
echo "Please set REPORT_PORTAL_API_KEY and REPORT_PORTAL_ENDPOINT environment variables"
6+
exit 1
7+
fi
8+
9+
# Remove /api/v1 or api/v2 from REPORT_PORTAL_ENDPOINT (reportportal/agent-php-PHPUnit requires only host)
10+
export REPORT_PORTAL_HOST=${REPORT_PORTAL_ENDPOINT/\/api\/v[12]/}
11+
12+
# Add secrets values in tests/reportportal_phpunit_conf_template.xml
13+
# Following environment variables are used:
14+
# REPORT_PORTAL_API_KEY
15+
# REPORT_PORTAL_HOST
16+
# PHP_VERSION
17+
envsubst < tests/reportportal/reportportal_phpunit_conf_template.xml > tests/reportportal/reportportal_phpunit_conf.xml
18+
19+
# Add conf for ReportPortal extension in phpunit.ci.xml
20+
# Inserts content of file tests/reportportal_phpunit_conf.xml before </phpunit> end tag in phpunit.ci.xml
21+
sed -i $'/<\/phpunit>/{e cat tests/reportportal/reportportal_phpunit_conf.xml\n}' phpunit.ci.xml
22+
23+
# Add ReportPortal extension to composer.json
24+
# reportportal/phpunit has no stable version, so we set minimum stability to dev only when running tests
25+
composer config minimum-stability dev
26+
# This is not supported by all versions of PHP, so we need to install it separately
27+
composer require --dev reportportal/phpunit
28+
29+
# Patch reportportal/basic to make it compatible with api/v2
30+
# Patch content:
31+
# * Replace api/v1 (hardcoded in reportportal/basic) by api/v2
32+
# * Add launchUuid to finishItem method (otherwise all tests will be marked as "interrupted")
33+
patch vendor/reportportal/basic/src/service/ReportPortalHTTPService.php tests/reportportal/ReportPortalHTTPService.php.patch
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<listeners>
2+
<listener class="agentPHPUnit" file="vendor/reportportal/phpunit/src/agentPHPUnit.php">
3+
<arguments>
4+
<string>${REPORT_PORTAL_API_KEY}</string>
5+
<string>${REPORT_PORTAL_HOST}</string>
6+
<string>integrations</string>
7+
<string>.000+00:00</string>
8+
<string>alma-php-client PHPUnit tests</string>
9+
<string>PHP version: ${PHP_VERSION}</string>
10+
</arguments>
11+
</listener>
12+
</listeners>

0 commit comments

Comments
 (0)