Skip to content

Commit 8775a0f

Browse files
Merge pull request #10 from assertwell/release/v0.1.0
Version 0.1.0
2 parents bb017e2 + 93b6614 commit 8775a0f

28 files changed

+940
-1590
lines changed

.editorconfig

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
# This file is for unifying the coding style for different editors and IDEs
22
# editorconfig.org
33

4-
# PHP PSR-2 Coding Standards
5-
# http://www.php-fig.org/psr/psr-2/
4+
# PHP PSR-12 Coding Standards
5+
# http://www.php-fig.org/psr/psr-12/
66

77
root = true
88

99
[*]
1010
charset = utf-8
11+
end_of_line = lf
1112
insert_final_newline = true
1213
trim_trailing_whitespace = true
1314

14-
[*.php]
15-
end_of_line = lf
15+
[*.{php,json}]
1616
indent_style = space
1717
indent_size = 4
18+
19+
[*.md]
20+
indent_style = tab

.gitattributes

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/.* export-ignore
2+
phpstan.* export-ignore
3+
phpunit.* export-ignore
4+
README.md export-ignore
5+
tests export-ignore
File renamed without changes.

.github/CONTRIBUTING.md

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Contributing to PHPUnit Global State
2+
3+
Thank you for your interest in contributing to [the assertwell/phpunit-global-state](https://github.com/assertwell/phpunit-global-state) library.
4+
5+
6+
## Code of Conduct
7+
8+
Please note that this project is released with [a Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.
9+
10+
11+
## Installing a development version
12+
13+
This project uses [Composer](https://getcomposer.org) to manage dependencies. You may install everything you need to get started by cloning the repository and running:
14+
15+
```sh
16+
$ composer install
17+
```
18+
19+
If you plan to work with any of the Runkit-based traits, you'll also need to ensure that Runkit7 is installed in your environment. This can be accomplished easily via [the stevegrunwell/runkit7-installer package](https://github.com/stevegrunwell/runkit7-installer), which is provided as a development dependency to this project:
20+
21+
```sh
22+
$ sudo vendor/bin/install-runkit.sh
23+
```
24+
25+
26+
### Running tests
27+
28+
Once the project's dependencies have been installed, you may execute the library's test suites by running any of the following:
29+
30+
```sh
31+
# Run all unit tests and check coding standards
32+
$ composer test
33+
34+
# Run only the PHPUnit test suite(s)
35+
$ composer test:unit
36+
37+
# Check coding standards
38+
$ composer test:standards
39+
```
40+
41+
It is expected that every pull request will include relevant unit tests.
42+
43+
44+
### Generating code coverage
45+
46+
Code coverage may be generated for the project by running the following:
47+
48+
```sh
49+
$ composer test:coverage
50+
```
51+
52+
This will generate HTML code coverage reports in the `tests/coverage` directory.
53+
54+
55+
## Coding Standards
56+
57+
The project strives to adhere to [the PSR-12 coding standards](https://www.php-fig.org/psr/psr-12/), and includes an `.editorconfig` file to help with enforcement.
58+
59+
It's recommended that you [install an EditorConfig plugin for your editor of choice](https://editorconfig.org/) if you plan to contribute code.
60+
61+
62+
### PHP Compatibility
63+
64+
Given that WordPress is one of the main reasons for creating this library, PHP compatibility requirements should match that of the platform (currently PHP 5.6 or newer).
65+
66+
Once PHP 5.6 is dropped as a requirement for WordPress, [this library will aim to quickly add typehints supported in PHP 7.x](https://github.com/assertwell/phpunit-global-state/issues/8) and other PHP 7-specific niceties.
67+
68+
69+
## Branching Model
70+
71+
This project uses [the "GitFlow" branching strategy](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow):
72+
73+
* `develop` represents the latest development code, and serves as the basis for all branches.
74+
* `master` represents the latest stable release.
75+
76+
77+
### Example
78+
79+
Let's say you want to add a new `StateOfTheWorld` trait to the project.
80+
81+
First, you would create a new branch to house your work, using `develop` as a base:
82+
83+
```sh
84+
$ git checkout -b feature/state-of-the-world develop
85+
```
86+
87+
Then, in your branch, create the trait in `src/StateOfTheWorld.php` and corresponding test class in `tests/StateOfTheWorldTest.php`, using the existing files as templates.
88+
89+
When you're satisfied with the new trait, commit your changes and open a new pull request against the `develop` branch of the upstream repository.
90+
91+
### Tagging releases
92+
93+
When a new release is ready to be tagged, a `release/vX.X.X` branch will be created using `develop` as its base, then the `CHANGELOG.md` file should be updated with all significant changes in the release.
94+
95+
The release branch should then be pushed to GitHub and a pull request opened against the `master` branch for review.
96+
97+
Once merged, a new release should be created based on the `master` branch, using the format of `vX.X.X` (e.g. "v1.2.3") and containing the contents of the changelog for that release.
98+
99+
Finally, the `master` branch should be merged into `develop`, ensuring the code from the release branch is represented there.

.github/workflows/coding-standards.yml

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
name: Coding standards
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
- master
8+
pull_request:
49

510
jobs:
611
build:
712
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
php: [7.4]
816

917
steps:
1018
- uses: actions/checkout@v2
@@ -17,9 +25,9 @@ jobs:
1725
uses: actions/cache@v2
1826
with:
1927
path: vendor
20-
key: ${{ runner.os }}-node-${{ hashFiles('**/composer.lock') }}
28+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
2129
restore-keys: |
22-
${{ runner.os }}-node-
30+
${{ runner.os }}-composer-
2331
2432
- name: Install dependencies
2533
if: steps.composer-cache.outputs.cache-hit != 'true'
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Static code analysis
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
- master
8+
pull_request:
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
php: [7.4]
16+
17+
steps:
18+
- uses: actions/checkout@v2
19+
20+
- name: Validate composer.json and composer.lock
21+
run: composer validate
22+
23+
- name: Cache Composer packages
24+
id: composer-cache
25+
uses: actions/cache@v2
26+
with:
27+
path: vendor
28+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
29+
restore-keys: |
30+
${{ runner.os }}-composer-
31+
32+
- name: Install dependencies
33+
if: steps.composer-cache.outputs.cache-hit != 'true'
34+
run: composer update --prefer-dist --no-progress --no-suggest
35+
36+
- name: Perform static code analysis
37+
run: composer test:analysis

.github/workflows/unit-tests.yml

+22-7
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,48 @@
11
name: Unit tests
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
- master
8+
pull_request:
49

510
jobs:
611
build:
712
runs-on: ubuntu-latest
813
strategy:
914
matrix:
10-
php: [7.0, 7.1, 7.2, 7.3, 7.4]
15+
php: [5.6, 7.0, 7.1, 7.2, 7.3, 7.4]
1116
fail-fast: true
1217

1318
steps:
1419
- uses: actions/checkout@v2
1520

21+
- name: Configure PHP environment
22+
uses: shivammathur/setup-php@v2
23+
with:
24+
php-version: ${{ matrix.php }}
25+
tools: pecl
26+
extensions: runkit, runkit7-alpha
27+
1628
- name: Validate composer.json and composer.lock
1729
run: composer validate
18-
30+
1931
- name: Cache Composer packages
2032
id: composer-cache
2133
uses: actions/cache@v2
2234
with:
2335
path: vendor
24-
key: ${{ runner.os }}-node-${{ hashFiles('**/composer.lock') }}
36+
key: ${{ runner.os }}-php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
2537
restore-keys: |
26-
${{ runner.os }}-node-
38+
${{ runner.os }}-php${{ matrix.php }}-composer-
39+
40+
- name: Remove PHPStan
41+
run: composer remove --dev phpstan/phpstan --no-update
2742

28-
- name: Install dependencies
43+
- name: Install Composer dependencies
2944
if: steps.composer-cache.outputs.cache-hit != 'true'
30-
run: composer install --prefer-dist --no-progress --no-suggest
45+
run: composer update --prefer-dist --no-progress --no-suggest
3146

3247
- name: Run test suite
3348
run: composer test:unit

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
composer.lock
12
tests/coverage
23
vendor
34
.phpunit.result.cache

.phpcs.xml.dist

+21
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,29 @@
1515
<!-- Use PSR-12 as a base. -->
1616
<rule ref="PSR12" />
1717

18+
<!-- The distributed code should be compatible with PHP 5.6 and newer. -->
19+
<config name="testVersion" value="5.6-" />
20+
<rule ref="PHPCompatibility" />
21+
22+
<!--
23+
Each of the traits will likely have a private array property that contains the global data
24+
to be restored, but we don't want to risk this conflicting with other properties that users
25+
might define in their tests.
26+
27+
As a result, we'll use the convention of `private $_somePropertyName`, but the underscore is
28+
*not* meant to indicate visibility, but rather to avoid conflict.
29+
-->
30+
<rule ref="PSR2.Classes.PropertyDeclaration.Underscore">
31+
<exclude-pattern>src/*.php</exclude-pattern>
32+
</rule>
33+
1834
<!-- Test methods may use snake_case. -->
1935
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
2036
<exclude-pattern>tests</exclude-pattern>
2137
</rule>
38+
39+
<!-- Don't require visibility on constants, as that's unsupported in PHP 7.0. -->
40+
<rule ref="PSR12.Properties.ConstantVisibility.NotFound">
41+
<exclude-pattern>tests/*</exclude-pattern>
42+
</rule>
2243
</ruleset>

CHANGELOG.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+
7+
## [Unreleased]
8+
9+
Initial public release of the package, with the following traits:
10+
11+
* [`AssertWell\PHPUnitGlobalState\Constants`](docs/Constants.md)
12+
* [`AssertWell\PHPUnitGlobalState\EnvironmentVariables`](docs/EnvironmentVariables.md)
13+
* [`AssertWell\PHPUnitGlobalState\GlobalVariables`](docs/GlobalVariables.md)
14+
15+
16+
[Unreleased]: https://github.com/assertwell/phpunit-global-state/compare/master...develop

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,11 @@ Of course, we might want a constant's original value to be restored after our te
5757

5858
The library offers a number of traits, based on the type of global state that might need to be manipulated.
5959

60+
* [Constants](docs/Constants.md) (requires Runkit7)
6061
* [Environment Variables](docs/EnvironmentVariables.md)
6162
* [Global Variables](docs/GlobalVariables.md)
63+
64+
65+
## Contributing
66+
67+
If you're interested in contributing to the library, [please review our contributing guidelines](.github/CONTRIBUTING.md).

composer.json

+16-6
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@
2121
"source": "https://github.com/assertwell/phpunit-global-state/"
2222
},
2323
"require": {
24-
"php": ">=7.0"
24+
"php": ">=5.6"
2525
},
2626
"require-dev": {
27-
"phpunit/phpunit": "^8.3",
27+
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
28+
"phpcompatibility/php-compatibility": "^9.3",
29+
"phpstan/phpstan": "^0.12",
2830
"squizlabs/php_codesniffer": "^3.5",
29-
"stevegrunwell/runkit7-installer": "^1.1"
31+
"stevegrunwell/runkit7-installer": "^1.1",
32+
"symfony/phpunit-bridge": "^5.1"
3033
},
3134
"suggest": {
3235
"stevegrunwell/runkit7-installer": "Streamline installation of Runkit7"
@@ -48,20 +51,27 @@
4851
},
4952
"scripts": {
5053
"test": [
51-
"@test:unit"
54+
"@test:unit",
55+
"@test:standards",
56+
"@test:analysis"
57+
],
58+
"test:analysis": [
59+
"phpstan analyse"
5260
],
5361
"test:coverage": [
54-
"phpdbg -qrr -d memory_limit=-1 ./vendor/bin/phpunit --colors=always --testdox --coverage-html=tests/coverage"
62+
"phpdbg -qrr -d memory_limit=-1 ./vendor/bin/simple-phpunit --colors=always --testdox --coverage-html=tests/coverage"
5563
],
5664
"test:standards": [
5765
"phpcs"
5866
],
5967
"test:unit": [
60-
"phpunit --testdox --colors=always"
68+
"simple-phpunit --testdox --colors=always"
6169
]
6270
},
6371
"scripts-descriptions": {
72+
"test:analysis": "Perform static code analysis.",
6473
"test:coverage": "Generate HTML code coverage reports in tests/coverage/.",
74+
"test:standards": "Check coding standards.",
6575
"test:unit": "Run unit tests for the library."
6676
}
6777
}

0 commit comments

Comments
 (0)