talkinnl/dont-leak
最新稳定版本:v1.0.1
Composer 安装命令:
composer require --dev talkinnl/dont-leak
包简介
Safely cleans all own Test properties to prevent phpunit memory leaks
README 文档
README
ARCHIVED, NO LONGER NEEDED.
This package is no longer needed, since PHPUnit now destructs the TestCase instances during the run.
- Initial PR by Sebastian 🔥 , PR 5861, released in PHPUnit 10.5.21 / 11.2.2.
- Final PR by me 😎 , PR 5875, released in PHPUnit 10.5.23 / 11.2.4
PHPUnit keeps all Test instance in memory for the whole run. This causes used memory to continuously increase, unless you clean up all your properties during a tearDown().
There's No Doubt you'll eventually forget this tedious task.
Installation
composer require --dev talkinnl/dont-leak
Usage
In your Test classes, add this as a very last line of your tearDown().
Maybe you'd like to always use a common parent class so you'll never forget.
protected function tearDown(): void { // Start with some of your cleanups which are still needed. // Maybe removing files made during the test etc // Always call your parents; they might get worried. :) parent::tearDown(); // Unset any properties, prevent memory leaks. DontLeak::freeOwnProperties($this); }
What does it do?
DontLeak::freeOwnProperites($object) unsets all properties reachable in your own scope of given $object, and all private properties of parent objects.
Properties defined by PHPUnit WON'T be touched.
What's next
I'd really like it if this package would be become obsolete thanks to PHPUnit changing the behaviour.
Please read, and maybe vote --> sebastianbergmann/phpunit#4705
Credits
Many suggestions of a tearDown which uses reflection to clean up exist scattered across Stack Overflow, Reddit, Github, etc.
The implementation was heavily inspired by https://gist.github.com/malarzm/e8c6141b510708e52c8535d2a13cd613 , which unsets instead of assigning null, and also clears private properties of safe parents.
统计信息
- 总下载量: 1.05k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-04-04