Skip to content

Add a feature to create mocks - #1

Merged
dacap merged 4 commits into
igarastudio:mainfrom
martincapello:add-mock-unmock
Feb 27, 2026
Merged

Add a feature to create mocks #1
dacap merged 4 commits into
igarastudio:mainfrom
martincapello:add-mock-unmock

Conversation

@martincapello

@martincapello martincapello commented Feb 26, 2026

Copy link
Copy Markdown
Member

This PR adds the possibility to create mocks by monkey patching functions, classes, etc. by using Patchwork.

How it works:
When mocks are used, a new temporal script is created in the same location as the main script that was going to be executed by the php-cgi command. This temporal script has the mocks definitions and it includes the original main script. Then it is the temporal script the one that gets executed.

Something to take into account is that given that Patchwork is not autoloaded by composer it needs to by included in the php code, so it was needed to add a new 'patchwork' option that must contains the path to the Patchwork.php file so we can use it when generating the temporal script.

@martincapello
martincapello requested a review from dacap February 26, 2026 18:28
Comment thread src/Visit.php
['REQUEST_METHOD' => $method,
'REQUEST_URI' => $path,
'SCRIPT_NAME' => '/index.php',
'SCRIPT_NAME' => basename($script),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll merge this PR as it is, the SCRIPT_NAME includes the slash in our case (as it comes from nginx in this way), but it doesn't make any difference for us

Image

@dacap
dacap merged commit 4af327e into igarastudio:main Feb 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants