Skip to content

Commit

Permalink
Add tests & README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
maks-rafalko committed Jan 17, 2020
1 parent a9b14b5 commit 02f9f90
Show file tree
Hide file tree
Showing 6 changed files with 2,020 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
/.idea
/.php_cs.cache
/vendor/
.phpunit.result.cache
infection.log
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Infection - Include Interceptor Stream Wrapper

It's a [Stream Wrapper](https://www.php.net/manual/en/book.stream.php) that wraps a [`file://`](https://www.php.net/manual/en/wrappers.file.php) protocol and allows overriding content of any (auto) loaded file, including files autoloaded by Composer package manager.

## How it works

If you want to replace the content of the file whenever it's loaded (by executing `include '/path/to/file.php`, by calling `file_get_contents('/path/to/file.php')`, etc.), you need to register `IncludeInterceptor` _before_ loading original file:

```php
use Infection\StreamWrapper\IncludeInterceptor;

IncludeInterceptor::intercept('/path/to/original_file.php', '/path/to/replacement_file.php');
IncludeInterceptor::enable();
```

After enabling `IncludeInterceptor`, content of the `replacement_file.php` will be loaded instead of content of the `original_file.php`.

## Use cases

* This Stream Wrapper is used to replace the original file with the Mutant in [Infection](http://infection.github.io) Mutation Testing Framework
* The same approach is used in the [`dg/bypass-finals`](https://github.com/dg/bypass-finals/) package that allows to mock `final` classes, by overriding original content and removing `final` keyword in runtime

## Infection - Mutation Testing Framework

Please read documentation here: [infection.github.io](http://infection.github.io)

Twitter: [@infection_php](http://twitter.com/infection_php)
10 changes: 9 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@
"Infection\\StreamWrapper\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Infection\\Tests\\StreamWrapper\\": "tests/"
}
},
"config": {
"platform": {
"php": "7.2.9"
},
"sort-packages": true
},
"require": {}
"require": {},
"require-dev": {
"phpunit/phpunit": "^8.5"
}
}
Loading

0 comments on commit 02f9f90

Please sign in to comment.