[QUESTION] Code coverage with proxy class
- 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
Assessment
This issue has not been assessed yet.