2016-05-15 14:02:04 +02:00
|
|
|
<?php
|
|
|
|
|
2016-05-15 17:24:53 +02:00
|
|
|
namespace Interop\Async;
|
2016-05-15 14:02:04 +02:00
|
|
|
|
2016-05-16 11:33:58 +02:00
|
|
|
class RegistryTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2016-05-15 14:02:04 +02:00
|
|
|
use Registry;
|
|
|
|
|
2016-05-16 11:33:58 +02:00
|
|
|
protected function setUp()
|
|
|
|
{
|
2016-05-15 14:02:04 +02:00
|
|
|
self::$registry = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @expectedException \RuntimeException
|
|
|
|
*/
|
2016-05-16 11:33:58 +02:00
|
|
|
public function fetchfailsOutsideOfLoop()
|
|
|
|
{
|
2016-05-15 14:02:04 +02:00
|
|
|
self::fetchState("foobar");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @expectedException \RuntimeException
|
|
|
|
*/
|
2016-05-16 11:33:58 +02:00
|
|
|
public function storefailsOutsideOfLoop()
|
|
|
|
{
|
2016-05-15 14:02:04 +02:00
|
|
|
self::fetchState("store");
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @test */
|
2016-05-16 11:33:58 +02:00
|
|
|
public function defaultsToNull()
|
|
|
|
{
|
2016-05-15 14:02:04 +02:00
|
|
|
// emulate we're in an event loop…
|
|
|
|
self::$registry = [];
|
|
|
|
$this->assertNull(self::fetchState("foobar"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider provideValues
|
|
|
|
*/
|
2016-05-16 11:33:58 +02:00
|
|
|
public function fetchesStoredValue($value)
|
|
|
|
{
|
2016-05-15 14:02:04 +02:00
|
|
|
// emulate we're in an event loop…
|
|
|
|
self::$registry = [];
|
|
|
|
|
|
|
|
$this->assertNull(self::fetchState("foobar"));
|
|
|
|
self::storeState("foobar", $value);
|
|
|
|
|
|
|
|
$this->assertSame($value, self::fetchState("foobar"));
|
|
|
|
}
|
|
|
|
|
2016-05-16 11:33:58 +02:00
|
|
|
public function provideValues()
|
|
|
|
{
|
2016-05-15 14:02:04 +02:00
|
|
|
return [
|
|
|
|
["string"],
|
|
|
|
[42],
|
|
|
|
[1.001],
|
|
|
|
[true],
|
|
|
|
[false],
|
|
|
|
[null],
|
|
|
|
[new \StdClass],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|