hyperf / hyperf/hyperf

[QUESTION] Code coverage with proxy class

Open
#6,691 7 comments 3 reactions 0 assignees View on GitHub
question
Dominant language
PHP
Stars
6.9k
Forks
1.3k
Avg merge
4h 21m
Merged PRs (30d)
4

Description

Hi!
Hyperf creates proxy classes when starting, for correct operation. However, when running tests with code coverage, some classes are not used during testing. For example:
```php
service->execute();
}
}
```

Proxy class
```php
__handlePropertyHandler(__CLASS__);
}

#[Inject]
private ServiceInterface $service;

#[GetMapping('')]
public function serviceExecute(): string
{
return $this->service->execute();
}
}
```
When running the tests the proxy class is used instead of the original class, because the ClassLoader.php map classes to proxies.
Which results in invalid code coverage.

Versions:
Hyperf 3.1
PHP 8.3
PHPUnit 10.5
Xdebug 3.3

Command:
```bash
php -dxdebug.mode=coverage ./vendor/bin/co-phpunit --prepend test/bootstrap.php -c phpunit.xml --colors=always
```

PHPUnit XML
```xml



./test/Unit













app

```

I found a similar link on stackoverflow
https://stackoverflow.com/questions/78079124/how-to-do-unit-coverage-reporting-in-php-using-proxy-classes

I don't know how to solve this problem.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.