Skip to content

Commit

Permalink
Merge pull request #17 from assertwell/feature/functions-trait
Browse files Browse the repository at this point in the history
Define the Functions trait
  • Loading branch information
stevegrunwell authored Nov 22, 2020
2 parents e8a9571 + 510b10e commit fd0476c
Show file tree
Hide file tree
Showing 20 changed files with 868 additions and 160 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MyTestClass extends TestCase

### Introduction to Runkit

Some of the traits will rely on [Runkit7](https://www.php.net/runkit7), a port of PHP's runkit designed to work in PHP 7.x, to rewrite code at runtime (a.k.a. "monkey-patching").
Some of the traits will rely on [Runkit7], a port of PHP's runkit designed to work in PHP 7.x, to rewrite code at runtime (a.k.a. "monkey-patching").

For example, once a PHP constant is defined, it will normally have that value until the PHP process ends. Under normal circumstances, that's great: it prevents the value from being accidentally overwritten and/or tampered with.

Expand All @@ -46,7 +46,7 @@ var_dump(SOME_CONSTANT)
#=> string(10) "some value"

// Now, re-define the constant.
runkit_constant_redefine('SOME_CONSTANT', 'some other value');
runkit7_constant_redefine('SOME_CONSTANT', 'some other value');
var_dump(SOME_CONSTANT)
#=> string(16) "some other value"
```
Expand All @@ -57,11 +57,14 @@ Of course, we might want a constant's original value to be restored after our te

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

* [Constants](docs/Constants.md) (requires Runkit7)
* [Constants](docs/Constants.md) (requires [Runkit7])
* [Environment Variables](docs/EnvironmentVariables.md)
* [Functions](docs/Functions.md) (requires [Runkit7])
* [Global Variables](docs/GlobalVariables.md)


## Contributing

If you're interested in contributing to the library, [please review our contributing guidelines](.github/CONTRIBUTING.md).

[Runkit7]: docs/Runkit.md
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"phpcompatibility/php-compatibility": "^9.3",
"phpstan/phpstan": "^0.12",
"squizlabs/php_codesniffer": "^3.5",
"stevegrunwell/runkit7-installer": "^1.1",
"stevegrunwell/runkit7-installer": "^1.2",
"symfony/phpunit-bridge": "^5.1"
},
"suggest": {
Expand All @@ -42,7 +42,10 @@
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"files": [
"tests/stubs/functions.php"
]
},
"config": {
"preferred-install": "dist",
Expand Down
68 changes: 42 additions & 26 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 1 addition & 8 deletions docs/Constants.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,8 @@

Some applications — especially WordPress — will use [PHP constants](https://www.php.net/manual/en/language.constants.php) for configuration that should not be edited directly through the <abbr title="User Interface">UI</abbr>.

Normally, a constant cannot be redefined or removed once defined; however, [the runkit7 extension](https://www.php.net/manual/en/book.runkit7) exposes functions to modify normally immutable constructs.
Normally, a constant cannot be redefined or removed once defined; however, [the runkit7 extension](Runkit.md) exposes functions to modify normally immutable constructs.

If runkit functions are unavailable, the `Constants` trait will automatically skip tests that rely on this functionality.

In order to install runkit7 in your development and CI environments, you may use [the installer bundled with this repo](https://github.com/stevegrunwell/runkit7-installer):

```sh
$ sudo ./vendor/bin/install-runkit.sh
```

## Methods

Expand Down
Loading

0 comments on commit fd0476c

Please sign in to comment.