Skip to content

Commit d2d7c52

Browse files
committed
Re-enabled package Codacy integration and re-added the coverage badge
- Added support for running unit tests and generating coverage report on Github Actions - Separated Github Actions for tests running on Linux from those running on Windows and MacOS - Upgraded PHPUnit version to support generating coverage on PHP8 - Added the code coverage badge to the repository once more
1 parent 304b145 commit d2d7c52

File tree

4 files changed

+74
-9
lines changed

4 files changed

+74
-9
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Test Package on Linux and push coverage results to Codacy
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
matrix:
15+
os: [ubuntu-latest]
16+
php: [7.3, 7.4, 8.0]
17+
18+
env:
19+
CODACY_PROJECT_TOKEN: ${{ secrets.CodacyProjectToken }}
20+
21+
steps:
22+
- uses: actions/checkout@v2
23+
24+
- name: Validate composer.json and composer.lock
25+
run: composer validate --strict
26+
27+
- name: Cache Composer packages
28+
id: composer-cache
29+
uses: actions/cache@v2
30+
with:
31+
path: vendor
32+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
33+
restore-keys: |
34+
${{ runner.os }}-php-
35+
36+
- name: Install dependencies
37+
run: composer install --prefer-dist --no-progress
38+
39+
- name: Check PHP INI file ownership and permissions
40+
run: |
41+
XDEBUG_INI=$(php --ini | grep xdebug.ini | awk '{print $NF}')
42+
XDEBUG_INI="${XDEBUG_INI%,}"
43+
ls -l "$XDEBUG_INI"
44+
45+
- name: Set up sudo for use in changing PHP INI file permissions
46+
run: |
47+
sudo apt-get update
48+
sudo apt-get install -y sudo
49+
50+
- name: Set up Xdebug for code coverage
51+
run: |
52+
XDEBUG_INI=$(php --ini | grep xdebug.ini | awk '{print $NF}')
53+
XDEBUG_INI="${XDEBUG_INI%,}"
54+
sudo chmod a+w "$XDEBUG_INI"
55+
echo "xdebug.mode=coverage" >> "$XDEBUG_INI"
56+
echo "xdebug.start_with_request=yes" >> "$XDEBUG_INI"
57+
echo "xdebug.client_host=host.docker.internal" >> "$XDEBUG_INI"
58+
echo "xdebug.client_port=9003" >> "$XDEBUG_INI"
59+
echo "xdebug.output_dir=/coverage" >> "$XDEBUG_INI"
60+
echo "XDEBUG_MODE=coverage" >> $GITHUB_ENV
61+
62+
- name: Run test suite & generate coverage report
63+
run: composer run test-and-generate-clover-coverage
64+
65+
- name: Upload code coverage report to codacy
66+
run: bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r build/coverage.xml

.github/workflows/php.yml renamed to .github/workflows/test-windows-macos.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: PHP Composer
1+
name: Test Package on Windows and MacOS
22

33
on:
44
push:
@@ -12,8 +12,8 @@ jobs:
1212
runs-on: ${{ matrix.os }}
1313
strategy:
1414
matrix:
15-
os: [ubuntu-latest, windows-latest, macos-latest]
16-
php: [7.3, 7.4, 8.0]
15+
os: [ windows-latest, macos-latest ]
16+
php: [ 7.3, 7.4, 8.0 ]
1717

1818
steps:
1919
- uses: actions/checkout@v2
@@ -33,8 +33,5 @@ jobs:
3333
- name: Install dependencies
3434
run: composer install --prefer-dist --no-progress
3535

36-
# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
37-
# Docs: https://getcomposer.org/doc/articles/scripts.md
38-
3936
- name: Run test suite
4037
run: composer run test

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# PHP GraphQL OQM
22
![Build Status](https://github.com/mghoneimy/php-graphql-oqm/actions/workflows/php.yml/badge.svg)
3+
[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/426f75816a2d43d3a2a5df4f13b15f6b)](https://app.codacy.com/gh/mghoneimy/php-graphql-oqm/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
34

45
This package utilizes the introspection feature of GraphQL APIs to generate a set of classes that map to the structure
56
of the API schema. The generated classes can then be used in a very simple and intuitive way to query the API server.

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@
3838
"gmostafa/php-graphql-client": "^1.12"
3939
},
4040
"require-dev": {
41-
"phpunit/phpunit": "^7.5|^8.0",
42-
"codacy/coverage": "^1.4",
41+
"phpunit/phpunit": "^7.5|^9",
4342
"ext-json": "*"
4443
},
4544
"scripts": {
46-
"test": "phpunit tests/ --whitelist src/ --coverage-clover build/coverage/xml"
45+
"test": "phpunit tests/",
46+
"test-and-generate-clover-coverage": "phpunit tests/ --whitelist src/ --coverage-clover build/coverage.xml",
47+
"test-and-generate-text-coverage": "phpunit tests/ --whitelist src/ --coverage-text=build/coverage.txt"
4748
}
4849
}

0 commit comments

Comments
 (0)