Skip to content

Stream Wrapper: Include Interceptor. Allows to replace included (autoloaded) file with another one.

License

Notifications You must be signed in to change notification settings

infection/include-interceptor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

c083331 · May 3, 2024

History

31 Commits
Jan 9, 2023
Jan 29, 2020
Aug 9, 2021
Aug 9, 2021
Jan 28, 2020
Jan 29, 2020
Jan 29, 2020
Jan 28, 2020
Jan 29, 2020
Jan 29, 2020
May 3, 2024
Jan 9, 2023
Jan 29, 2020
Jan 17, 2020
Jan 29, 2020

Repository files navigation

Build Status Coverage Status

Infection - Include Interceptor Stream Wrapper

It's a Stream Wrapper that wraps a file:// protocol and allows overriding content of any (auto) loaded file, including files autoloaded by Composer package manager.

Installation

composer require infection/include-interceptor

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:

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 Mutation Testing Framework
  • The same approach is used in the 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

Twitter: @infection_php