Error when mocking built-in function with pass-by-reference argument and argument with default value (PHP 8)
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 42/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- php
- 領域
- testing-qa
調査の方向性
AspectMock/Core/Mocker.php:275 から開始し、組み込み関数のシグネチャが一時ラッパーに変換される流れを追跡してください。Registry.php:38 と Test.php:248 に周辺の呼び出し経路が示されています。flock、system、stream_socket_client、または stream_select を使用して PHP 8.1 で再現し、生成された宣言がデフォルト値の重複なしでパースでき、モックされた呼び出しが引き続き動作することを確認してください。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- PHP
- スター
- 784
- フォーク
- 132
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Codeception/AspectMock のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
Codeception/AspectMock#208 · コメント 2 件 · リアクション 5 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 25/100
Codeception/AspectMock#206 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
Codeception/AspectMock#203 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 35/100
Codeception/AspectMock#202 · コメント 5 件 · リアクション 2 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
Codeception/AspectMock#196 · コメント 1 件 ·
Codeception/AspectMock の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
hector-jewell/food-delivery-system-for-restaurant-using-php#1311 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
Sylius/SyliusGridBundle#501 ·