php - 为简单功能寻找可能的代码覆盖路径
问题描述
我很难尝试覆盖特定类方法的代码覆盖的所有路径:
public function getTotalOfType(String $type) : float
{
$total = 0;
foreach($this->getCartItemsOfType($type) as $cartitem)
{
$total += $cartitem->getAmount();
}
return $total;
}
getCartItemsOfType()
只会返回一个数组 - 空的或填充购物车项目。
我目前的报道指出,我已经覆盖了两条路径,但缺少第三条。支线覆盖率100%。我的断言如下。我省略了设置:
...
@test
@covers Cart::getTotalOfType()
...
$this->assertEquals(10, $cart->getTotalOfType('shoes')); //passes
$this->assertEquals(20, $cart->getTotalOfType('jumper')); //passes
$this->assertEquals(0, $cart->getTotalOfType('does_not_exist')); //passes as type does not exist
$this->assertEquals(0, $cart->getTotalOfType('')); //passes - empty string returns 0
我错过了一种可能的排列,但似乎无法弄清楚是什么。
此功能可能的路径排列是什么?
以下是我的代码覆盖率报告的结果:
解决方案
推荐阅读
- c++ - 每次创建 C++ 文件时,VsCode 都会创建一个 .exe 文件
- javascript - How to add Service worker file in the root directory to the client application
- python - "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-wF_NKE/decorator/
- pandas - 如何在多个位置将文件中的列插入到另一个文件中
- reactjs - Webpack build Module parse failed: Unexpected token (17:2)
- bash - "Git Bash here" takes too long to start (also MSYS2 bash terminal)
- image - how can i find which color channel (RGB) is affected most in a noisy medium?
- homebrew - How to list all keg only formulas installed?
- discord.js - 如何在 discord.js 嵌入中 ping 角色
- javascript - Install vue-cli Globally or Locally