mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-07 23:46:52 +02:00
PHP7 Registry
This commit is contained in:
@@ -9,12 +9,33 @@ class RegistryTest extends \PHPUnit_Framework_TestCase
|
||||
public function testSetAndGetLogger()
|
||||
{
|
||||
$key = Registry::LOGGER;
|
||||
$object = new \StdClass();
|
||||
$logger = new \stdClass();
|
||||
|
||||
Registry::set($key, $object);
|
||||
$actual = Registry::get($key);
|
||||
Registry::set($key, $logger);
|
||||
$storedLogger = Registry::get($key);
|
||||
|
||||
$this->assertEquals($object, $actual);
|
||||
$this->assertInstanceOf('StdClass', $actual);
|
||||
$this->assertSame($logger, $storedLogger);
|
||||
$this->assertInstanceOf('stdClass', $storedLogger);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testThrowsExceptionWhenTryingToSetInvalidKey()
|
||||
{
|
||||
Registry::set('foobar', new \stdClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* notice @runInSeparateProcess here: without it, a previous test might have set it already and
|
||||
* testing would not be possible. That's why you should implement Dependency Injection where an
|
||||
* injected class may easily be replaced by a mockup
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testThrowsExceptionWhenTryingToGetNotSetKey()
|
||||
{
|
||||
Registry::get(Registry::LOGGER);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user