承接 talkinnl/dont-leak 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

PHP Composer and unittest

ARCHIVED, NO LONGER NEEDED.

This package is no longer needed, since PHPUnit now destructs the TestCase instances during the run.

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-04-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固