phptailors/singleton-testing

There is no license information available for the latest version (1.0.1) of this package.

Singleton testing helpers

Maintainers

Package info

github.com/phptailors/singleton-testing

Issues

pkg:composer/phptailors/singleton-testing

Statistics

Installs: 4

Dependents: 0

Suggesters: 0

Stars: 0

1.0.1 2026-03-27 12:54 UTC

This package is auto-updated.

Last update: 2026-03-27 12:55:40 UTC


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.