PHP7 Registry

This commit is contained in:
Dominik Liebler
2016-09-23 10:47:24 +02:00
parent 281714cd58
commit 46e8d3cbe6
3 changed files with 49 additions and 22 deletions

View File

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