phptailors / singleton-testing
There is no license information available for the latest version (1.0.1) of this package.
Singleton testing helpers
1.0.1
2026-03-27 12:54 UTC
Requires
- php: >=8.0
- phptailors/phpunit-methods: >=1.0.0
- phptailors/singleton-interface: ^1.0
Requires (Dev)
This package is auto-updated.
Last update: 2026-03-27 12:55:40 UTC
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.