定制 phptailors/singleton-testing 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

phptailors/singleton-testing

最新稳定版本:1.0.1

Composer 安装命令:

composer require phptailors/singleton-testing

包简介

Singleton testing helpers

README 文档

README

PHPUnit Composer Require Checker BC Check Psalm PHP CS Fixer

phptailors/singleton-testing

PHPUnit extension for testing implementations of phptailors/singleton-interface.

Installation

composer require --dev "phptailors/singleton-testing:^1.0"
composer require --dev "phpunit/phpunit"

Usage

<?php

use PHPUnit\Framework\TestCase;
use Tailors\Testing\Lib\Singleton\AssertIsSingletonTrait;

final class MySingletonTest extends TestCase
{
    use AssertIsSingletonTrait;

    public function testMySingletonIsSingleton(): void
    {
        $this->assertIsSingleton(MySingleton::class);
    }
}

How a class is tested

The following tests are performed by assertIsSingleton($class):

  1. Assert that the the provided string $class is a class.
  2. Assert that $class has private constructor.
  3. Assert that $class has public static method getInstance().
  4. Assert that $class::getInstance() is callable.
  5. Assert that $class::getInstance() returns an instance of $class.
  6. Assert that $class::getInstance() is idempotent.
  7. Assert that $class is not cloneable.
  8. Assert that it throws Tailors\Lib\Singleton\SingletonException on unserialize().

The name of the getInstance() method may be customized, for example:

    $this->assertIsSingleton(MySingleton::class, getInstance: "getSingleInstance")

will use getSingleInstance instead of getInstance.

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2026-03-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固