mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-09-25 22:09:23 +02:00
Fixed wrong implementation of Singleton Pattern
This commit is contained in:
@@ -26,4 +26,25 @@ class SingletonTest extends \PHPUnit_Framework_TestCase
|
||||
$meth = $refl->getMethod('__construct');
|
||||
$this->assertTrue($meth->isPrivate());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \DesignPatterns\Creational\Singleton\SingletonPatternViolationException
|
||||
* @return void
|
||||
*/
|
||||
public function testNoCloneAllowed()
|
||||
{
|
||||
$obj1 = Singleton::getInstance();
|
||||
$obj2 = clone $obj1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \DesignPatterns\Creational\Singleton\SingletonPatternViolationException
|
||||
* @return void
|
||||
*/
|
||||
public function testNoSerializationAllowed()
|
||||
{
|
||||
$obj1 = Singleton::getInstance();
|
||||
$serialized = serialize($obj1);
|
||||
$obj2 = unserialize($serialized);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user