Error when mocking built-in function with pass-by-reference argument and argument with default value (PHP 8)
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 42/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- php
- Ambito
- testing-qa
Direzione di ricerca
Parti da AspectMock/Core/Mocker.php:275 e traccia il modo in cui le firme delle funzioni integrate vengono trasformate nel wrapper temporaneo; Registry.php:38 e Test.php:248 mostrano il percorso di chiamata circostante. Riproduci il problema con PHP 8.1 usando flock, system, stream_socket_client o stream_select, quindi verifica che le dichiarazioni generate vengano analizzate senza valori predefiniti duplicati e che le chiamate mockate continuino a funzionare.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
<?php
namespace Atomic;
if (!function_exists('Atomic\flock')) {
function flock($p0, int $p1, &$p2 = null=NULL) {
$args = [];
switch(count(func_get_args())) {
case 3: $args = [$p0, $p1, &$p2]; break;
case 2: $args = [$p0, $p1]; break;
case 1: $args = [$p0]; break;
}
if (($__am_res = __amock_before_func('Atomic','flock', $args)) !== __AM_CONTINUE__) {
return $__am_res;
}
return call_user_func_array('flock', $args);
}
}
The function declaration has two default values for an argument (function flock($p0, int $p1, &$p2 = null=NULL).
Other functions which have given us this problem are:
system()stream_socket_client()stream_select()
The last one is interesting because, unlike the others, the passed-by-reference arguments don't have default values. Only the final argument does:
stream_select(
?array &$read,
?array &$write,
?array &$except,
?int $seconds,
?int $microseconds = null
): int|false
That's what leads me to believe the problem is the existence of both in the function signature, but not necessarily that a single argument needs to be both pass-by-reference and have a default value for this to fail.
We don't see this under PHP 7.4, so I assume this related to the PHP version.
- Lingua principale
- PHP
- Stelle
- 784
- Fork
- 132
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Codeception/AspectMock
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 35/100
Codeception/AspectMock#208 · 2 commenti · 5 reazioni ·
-
AspectMock не мокает объект Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 25/100
Codeception/AspectMock#206 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
Codeception/AspectMock#203 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 35/100
Codeception/AspectMock#202 · 5 commenti · 2 reazioni ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
Codeception/AspectMock#196 · 1 commento ·
Tutte le issue di Codeception/AspectMock
Issue simili
-
Solved site promotion gate fails on runner PHP patch drift (expects 8.2.33, runner installs 8.2.34) Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
Automattic/blocks-engine#2161 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
Automattic/static-site-importer#1824 ·
-
[Chore] Keep one viget-block-generator skill and replicate it, instead of four tracked copies Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Cannot reset column width Aperta0. Needs triage bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
0. Needs triage 35-feedback bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100