Fixed wrong implementation of Singleton Pattern

This commit is contained in:
Marius Bogdan
2015-12-12 22:44:19 +01:00
parent dab22757a7
commit df060dab97
3 changed files with 37 additions and 4 deletions

View File

@@ -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);
}
}