mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-05-29 18:09:22 +02:00
Merge remote-tracking branch 'Trismegiste/unit-test-for-singleton'
This commit is contained in:
commit
5b8293d801
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns;
|
||||
namespace DesignPatterns\Singleton;
|
||||
|
||||
/**
|
||||
* Singleton pattern
|
||||
|
34
Tests/Singleton/SingletonTest.php
Normal file
34
Tests/Singleton/SingletonTest.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* DesignPatternPHP
|
||||
*/
|
||||
|
||||
namespace DesignPatterns\Tests\Singleton;
|
||||
|
||||
use DesignPatterns\Singleton\Singleton;
|
||||
|
||||
/**
|
||||
* SingletonTest tests the singleton pattern
|
||||
*/
|
||||
class SingletonTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testUniqueness()
|
||||
{
|
||||
$firstCall = Singleton::getInstance();
|
||||
$this->assertInstanceOf('DesignPatterns\Singleton\Singleton', $firstCall);
|
||||
$secondCall = Singleton::getInstance();
|
||||
$this->assertSame($firstCall, $secondCall);
|
||||
}
|
||||
|
||||
public function testNoConstructor()
|
||||
{
|
||||
$obj = Singleton::getInstance();
|
||||
|
||||
$refl = new \ReflectionObject($obj);
|
||||
$meth = $refl->getMethod('__construct');
|
||||
$this->assertTrue($meth->isPrivate());
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user