Codeception / Codeception/AspectMock
Error when mocking built-in function with pass-by-reference argument and argument with default value (PHP 8)
- Dominant language
- PHP
- Stars
- 784
- Forks
- 132
- PR merge metrics
- No merged PRs in 30d
Description
This is for AspectMock 4.1.1.
During our migration from PHP 7.4 to PHP 8.1, we've encountered this pattern a few times:
When our PHP-Unit tests mock a PHP built-in function that has at least one argument passed by reference and one argument with a default value, the mock fails with the error `ParseError: syntax error, unexpected token "=", expecting ")"`.
The stack track looks like this:
```
/tmp/flockoipmSG:4
/petabox/www/common/vendor/codeception/aspect-mock/src/AspectMock/Core/Mocker.php:275
/petabox/www/common/vendor/codeception/aspect-mock/src/AspectMock/Core/Registry.php:38
/petabox/www/common/vendor/codeception/aspect-mock/src/AspectMock/Test.php:248
```
Examining the temporary file reveals the problem:
```
$ cat /tmp/flockoipmSG
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at AspectMock/Core/Mocker.php:275 and trace how built-in function signatures are turned into the temporary wrapper; Registry.php:38 and Test.php:248 show the surrounding call path. Reproduce with PHP 8.1 using flock, system, stream_socket_client, or stream_select, then verify that generated declarations parse without duplicate defaults and the mocked calls still work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100