测试红线覆盖 PHPUnit

问题描述

我为 PHP Trait 类编写测试。当我在 PHPStorm IDE 上运行覆盖率测试时,它在编辑器行号上显示一些红线,并在这样的覆盖率测试行上给我 76% 的结果

enter image description here

我的问题是如何在这些行上进行测试,这样我才能得到 100% 行的结果

这是我的测试代码

响应.PHP

<?PHP

trait Response {
    /**
     * Failed to login response.
     *
     * @return array
     */
    public function FailedLogin(): array
    {
        return [
            'code'    => 401,'message' => 'Failed to login',];
    }   
}

ResponseTest.PHP

<?PHP

use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class ResponseTest extends TestCase
{
    /**
     * @var MockObject|Response|null
     */
    private ?MockObject $mock;

    protected function setUp(): void
    {
        $this->mock = $this->getMockForTrait(Response::class);
    }

    /**
     * @test
     */
    public function it_correct_output_Failed_login()
    {
        $response = $this->mock->FailedLogin();

        $this->assertResponse($response,401,'Failed to login');
    }
    
    /**
     * Assert response.
     *
     * @param  array  $response
     * @param  int  $code
     * @param  null  $message
     */
    private function assertResponse(array $response,$code = 200,$message = null)
    {
        $this->assertIsArray($response);
        $this->assertArrayHasKey('code',$response);
        $this->assertArrayHasKey('message',$response);
        $this->assertContains($code,$response);
        $this->assertContains($message,$response);
    }

    protected function tearDown(): void
    {
        $this->mock = null;
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...