ClosureUsesThisRule produces false positive with Prophecy will()
还没有人认领这个 Issue。
评估
调研方向
Start with the supplied PHPUnit and Prophecy reproducer and inspect the implementation of ClosureUsesThisRule. Confirm that the closure passed to Prophecy's will() is analyzed with the correct $this context, then use the example as a regression test whose expected result is no false positive.
由索引模型根据 Issue 内容生成。
描述
If you replace $that by $this in the closure of the following, the test will fail.
At runtime, the type of $this is \Prophecy\Prophecy\ObjectProphecy and the type of $that is MyTest.
<?php
declare(strict_types=1);
// Requires phpunit/phpunit, phpspec/prophecy and phpspec/prophecy-phpunit
namespace foo;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
class MyTarget
{
public function run(string $input): string
{
return $input;
}
}
class MyTest extends TestCase
{
use ProphecyTrait;
private array $stuff = ['foo' => 'bar'];
public function testMyMock(): void
{
$prophecy = $this->prophesize(MyTarget::class);
$that = $this;
$prophecy->run(Argument::type('string'))->will(
function (array $args) use ($that): string {
return $that->stuff[$args[0]] ?? $args[0];
}
);
$target = $prophecy->reveal();
$result = $target->run('foo');
self::assertSame('bar', $result);
}
}
- 主要语言
- PHP
- 星标
- 709
- 派生
- 62
- 平均合并
- 5 天 19 小时
- 30 天内合并 PR
- 3
环境准备
我们还没有检查这个项目的环境配置文件。先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
phpstan/phpstan-strict-rules 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 48/100
phpstan/phpstan-strict-rules#317 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 48/100
phpstan/phpstan-strict-rules#316 · 3 条评论 ·
-
难度 3/5 1-2 天 新手友好度 52/100
phpstan/phpstan-strict-rules#298 · 2 条评论 · 1 个 reaction ·
-
难度 3/5 1-2 天 新手友好度 45/100
phpstan/phpstan-strict-rules#289 · 1 条评论 ·
-
bug
难度 4/5 3-5 天 新手友好度 35/100
phpstan/phpstan-strict-rules#283 · 6 条评论 ·
查看 phpstan/phpstan-strict-rules 的全部 Issue
相似的 Issue
-
[Type] Bug
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
coollabsio/coolify#12016 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
woocommerce/woocommerce-gateway-stripe#6008 ·
维护者通常 1 天内回复
-
product / auth product / databases product / sites product / vcs
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
backend enhancement good first issue php
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复