phptailors/singleton-testing
最新稳定版本:1.0.1
Composer 安装命令:
composer require phptailors/singleton-testing
包简介
Singleton testing helpers
README 文档
README
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):
- Assert that the the provided string
$classis a class. - Assert that
$classhas private constructor. - Assert that
$classhas public static methodgetInstance(). - Assert that
$class::getInstance()is callable. - Assert that
$class::getInstance()returns an instance of$class. - Assert that
$class::getInstance()is idempotent. - Assert that
$classis not cloneable. - 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
其他信息
- 授权协议: Unknown
- 更新时间: 2026-03-27