突变体未被PHP感染的测试覆盖
我正在进行一些突变测试(“感染/感染”:“^0.26.1”
),出于某些未知的原因,PHP感染声称即使有单位测试书面,也没有涵盖测试那里。
这是感染所指出的错误:
1) /opt/www/app/Infrastructure/Http/Resources/Mobile/PaymentMethods/PaymentMethodsCollection.php:34 [M] ArrayItemRemoval
--- Original
+++ New
@@ @@
$paymentMethods = PaymentMethodsResource::collection($collection['PaymentMethods'] ?? []);
$balance = BalanceResource::make(
$collection['Balance'] ?? ['balance' => '0.00', 'withdraw_balance' => '0.00', 'withdraw_balance_from_credits' => '0.00']
);
$defaultPaymentMethod = DefaultPaymentMethodResource::make($collection['DefaultPaymentMethod'] ?? null);
- return ['data' => ['PaymentMethods' => $paymentMethods, 'Balance' => $balance, 'DefaultPaymentMethod' => $defaultPaymentMethod]];
+ return [];
}
}
这是涵盖这种情况的单位测试:
/**
* @dataProvider dataProvider
*/
public function testToArray($input, $output): void
{
$this->service = new PaymentMethodsCollection($input);
$result = $this->service->toArray();
$this->assertNotEmpty($result);
$this->assertArrayHasKey('data', $result);
$this->assertArrayHasKey('PaymentMethods', $result['data']);
$this->assertArrayHasKey('Balance', $result['data']);
$this->assertArrayHasKey('DefaultPaymentMethod', $result['data']);
$this->assertInstanceOf(ResourceCollection::class,
$result['data']['PaymentMethods']
);
$this->assertInstanceOf(BalanceResource::class,
$result['data']['Balance']
);
$this->assertInstanceOf(DefaultPaymentMethodResource::class,
$result['data']['DefaultPaymentMethod']
);
}
如果我隔离运行单元测试,则输出是:
Payment Methods Collection (Test\Unit\Infrastructure\Http\Resources\Mobile\PaymentMethods\PaymentMethodsCollection)
✔ To array with only·balance·empty
✔ To array with full·empty
✔ To array with only·default·payment·method·empty
✔ To array with only·payments·methods·empty
✔ To array with filled
Time: 00:01.257, Memory: 28.00 MB
OK (5 tests, 45 assertions)
SEGUEconfiguração会感染:
{
"$schema": "vendor/infection/infection/resources/schema.json",
"source": {
"directories": [
"app"
]
},
"tmpDir": "tmp",
"logs": {
"text": "test/reports/infection/infection.log",
"html": "test/reports/infection/infection.html"
},
"mutators": {
"@default": true,
"@function_signature": false
},
"testFramework":"phpunit",
"testFrameworkOptions": "--testsuite=Unit",
"phpUnit": {
"configDir": "test/Infection"
}
}
为什么php感染声称不涵盖它?
我看不到的问题在哪里?
“未覆盖”的概念是,当单位测试不涵盖这种情况并使突变体活着时,对吗?
I'm running some mutation tests ("infection/infection": "^0.26.1"
) and for some unknown reason PHP Infection claims that there are tests that are not covered even with the unit tests written there.
Here is the error alleged by Infection:
1) /opt/www/app/Infrastructure/Http/Resources/Mobile/PaymentMethods/PaymentMethodsCollection.php:34 [M] ArrayItemRemoval
--- Original
+++ New
@@ @@
$paymentMethods = PaymentMethodsResource::collection($collection['PaymentMethods'] ?? []);
$balance = BalanceResource::make(
$collection['Balance'] ?? ['balance' => '0.00', 'withdraw_balance' => '0.00', 'withdraw_balance_from_credits' => '0.00']
);
$defaultPaymentMethod = DefaultPaymentMethodResource::make($collection['DefaultPaymentMethod'] ?? null);
- return ['data' => ['PaymentMethods' => $paymentMethods, 'Balance' => $balance, 'DefaultPaymentMethod' => $defaultPaymentMethod]];
+ return [];
}
}
Here is the unit test covering such a scenario:
/**
* @dataProvider dataProvider
*/
public function testToArray($input, $output): void
{
$this->service = new PaymentMethodsCollection($input);
$result = $this->service->toArray();
$this->assertNotEmpty($result);
$this->assertArrayHasKey('data', $result);
$this->assertArrayHasKey('PaymentMethods', $result['data']);
$this->assertArrayHasKey('Balance', $result['data']);
$this->assertArrayHasKey('DefaultPaymentMethod', $result['data']);
$this->assertInstanceOf(ResourceCollection::class,
$result['data']['PaymentMethods']
);
$this->assertInstanceOf(BalanceResource::class,
$result['data']['Balance']
);
$this->assertInstanceOf(DefaultPaymentMethodResource::class,
$result['data']['DefaultPaymentMethod']
);
}
If I run the unit tests in isolation, the output is:
Payment Methods Collection (Test\Unit\Infrastructure\Http\Resources\Mobile\PaymentMethods\PaymentMethodsCollection)
✔ To array with only·balance·empty
✔ To array with full·empty
✔ To array with only·default·payment·method·empty
✔ To array with only·payments·methods·empty
✔ To array with filled
Time: 00:01.257, Memory: 28.00 MB
OK (5 tests, 45 assertions)
Segue a configuração do Infection:
{
"$schema": "vendor/infection/infection/resources/schema.json",
"source": {
"directories": [
"app"
]
},
"tmpDir": "tmp",
"logs": {
"text": "test/reports/infection/infection.log",
"html": "test/reports/infection/infection.html"
},
"mutators": {
"@default": true,
"@function_signature": false
},
"testFramework":"phpunit",
"testFrameworkOptions": "--testsuite=Unit",
"phpUnit": {
"configDir": "test/Infection"
}
}
Why is PHP Infection claiming it is not covered?
Where is the problem that I'm not seeing?
The concept of "not covered" is when the unit test doesn't cover that scenario and leaves the mutant alive, correct?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论