mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-11 01:14:01 +02:00
PHP7 Singleton
This commit is contained in:
@@ -4,32 +4,19 @@ namespace DesignPatterns\Creational\Singleton\Tests;
|
||||
|
||||
use DesignPatterns\Creational\Singleton\Singleton;
|
||||
|
||||
/**
|
||||
* SingletonTest tests the singleton pattern.
|
||||
*/
|
||||
class SingletonTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testUniqueness()
|
||||
{
|
||||
$firstCall = Singleton::getInstance();
|
||||
$this->assertInstanceOf('DesignPatterns\Creational\Singleton\Singleton', $firstCall);
|
||||
$secondCall = Singleton::getInstance();
|
||||
|
||||
$this->assertInstanceOf('DesignPatterns\Creational\Singleton\Singleton', $firstCall);
|
||||
$this->assertSame($firstCall, $secondCall);
|
||||
}
|
||||
|
||||
public function testNoConstructor()
|
||||
{
|
||||
$obj = Singleton::getInstance();
|
||||
|
||||
$refl = new \ReflectionObject($obj);
|
||||
$meth = $refl->getMethod('__construct');
|
||||
$this->assertTrue($meth->isPrivate());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \DesignPatterns\Creational\Singleton\SingletonPatternViolationException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNoCloneAllowed()
|
||||
{
|
||||
@@ -39,13 +26,11 @@ class SingletonTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
/**
|
||||
* @expectedException \DesignPatterns\Creational\Singleton\SingletonPatternViolationException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNoSerializationAllowed()
|
||||
{
|
||||
$obj1 = Singleton::getInstance();
|
||||
$serialized = serialize($obj1);
|
||||
$obj2 = unserialize($serialized);
|
||||
unserialize($serialized);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user