Skip to content

Commit bb017e2

Browse files
Merge pull request #1 from assertwell/feature/github-workflows
WIP: Execute unit tests using GitHub workflows
2 parents d64cb54 + 2f3c93a commit bb017e2

File tree

6 files changed

+320
-96
lines changed

6 files changed

+320
-96
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Coding standards
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v2
11+
12+
- name: Validate composer.json and composer.lock
13+
run: composer validate
14+
15+
- name: Cache Composer packages
16+
id: composer-cache
17+
uses: actions/cache@v2
18+
with:
19+
path: vendor
20+
key: ${{ runner.os }}-node-${{ hashFiles('**/composer.lock') }}
21+
restore-keys: |
22+
${{ runner.os }}-node-
23+
24+
- name: Install dependencies
25+
if: steps.composer-cache.outputs.cache-hit != 'true'
26+
run: composer install --prefer-dist --no-progress --no-suggest
27+
28+
- name: Run coding standards checks
29+
run: composer test:standards

.github/workflows/unit-tests.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Unit tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
php: [7.0, 7.1, 7.2, 7.3, 7.4]
11+
fail-fast: true
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
16+
- name: Validate composer.json and composer.lock
17+
run: composer validate
18+
19+
- name: Cache Composer packages
20+
id: composer-cache
21+
uses: actions/cache@v2
22+
with:
23+
path: vendor
24+
key: ${{ runner.os }}-node-${{ hashFiles('**/composer.lock') }}
25+
restore-keys: |
26+
${{ runner.os }}-node-
27+
28+
- name: Install dependencies
29+
if: steps.composer-cache.outputs.cache-hit != 'true'
30+
run: composer install --prefer-dist --no-progress --no-suggest
31+
32+
- name: Run test suite
33+
run: composer test:unit

.phpcs.xml.dist

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="assertwell/phpunit-global-state">
3+
<description>Coding standards for assertwell/phpunit-global-state.</description>
4+
5+
<arg value="sp" />
6+
<arg name="basepath" value="./" />
7+
<arg name="colors" />
8+
<arg name="extensions" value="php" />
9+
<arg name="parallel" value="8" />
10+
11+
<!-- Only scan PHP files that belong to the app. -->
12+
<file>src</file>
13+
<file>tests</file>
14+
15+
<!-- Use PSR-12 as a base. -->
16+
<rule ref="PSR12" />
17+
18+
<!-- Test methods may use snake_case. -->
19+
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
20+
<exclude-pattern>tests</exclude-pattern>
21+
</rule>
22+
</ruleset>

composer.json

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "assertwell/phpunit-global-state",
3-
"description": "Tools for safely manipulating global state in tests",
3+
"description": "Tools for testing applications that depend on global state with PHPUnit",
44
"keywords": [
55
"env",
66
"environment variables",
@@ -24,7 +24,12 @@
2424
"php": ">=7.0"
2525
},
2626
"require-dev": {
27-
"phpunit/phpunit": "^8.3"
27+
"phpunit/phpunit": "^8.3",
28+
"squizlabs/php_codesniffer": "^3.5",
29+
"stevegrunwell/runkit7-installer": "^1.1"
30+
},
31+
"suggest": {
32+
"stevegrunwell/runkit7-installer": "Streamline installation of Runkit7"
2833
},
2934
"autoload": {
3035
"psr-4": {
@@ -42,11 +47,21 @@
4247
"optimize-autoloader": true
4348
},
4449
"scripts": {
45-
"code-coverage": [
50+
"test": [
51+
"@test:unit"
52+
],
53+
"test:coverage": [
4654
"phpdbg -qrr -d memory_limit=-1 ./vendor/bin/phpunit --colors=always --testdox --coverage-html=tests/coverage"
55+
],
56+
"test:standards": [
57+
"phpcs"
58+
],
59+
"test:unit": [
60+
"phpunit --testdox --colors=always"
4761
]
4862
},
4963
"scripts-descriptions": {
50-
"code-coverage": "Generate HTML code coverage reports in tests/coverage/."
64+
"test:coverage": "Generate HTML code coverage reports in tests/coverage/.",
65+
"test:unit": "Run unit tests for the library."
5166
}
5267
}

0 commit comments

Comments
 (0)