mirror of
https://github.com/danog/amp.git
synced 2024-11-27 12:35:02 +01:00
Merge pull request #89 from async-interop/state
Rename fetch/storeState to get/setState
This commit is contained in:
commit
dff456ce83
12
src/Loop.php
12
src/Loop.php
@ -307,15 +307,15 @@ final class Loop
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function storeState($key, $value)
|
||||
public static function setState($key, $value)
|
||||
{
|
||||
$driver = self::$driver ?: self::get();
|
||||
$driver->storeState($key, $value);
|
||||
$driver->setState($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches information stored bound to the loop. Stored information is package private. Packages MUST NOT retrieve
|
||||
* the stored state of other packages.
|
||||
* Gets information stored bound to the loop. Stored information is package private. Packages MUST NOT retrieve the
|
||||
* stored state of other packages.
|
||||
*
|
||||
* Therefore packages SHOULD use the following prefix to keys: `vendor.package.`
|
||||
*
|
||||
@ -323,10 +323,10 @@ final class Loop
|
||||
*
|
||||
* @return mixed previously stored value or null if it doesn't exist
|
||||
*/
|
||||
public static function fetchState($key)
|
||||
public static function getState($key)
|
||||
{
|
||||
$driver = self::$driver ?: self::get();
|
||||
return $driver->fetchState($key);
|
||||
return $driver->getState($key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -194,7 +194,7 @@ abstract class Driver
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
final public function storeState($key, $value)
|
||||
final public function setState($key, $value)
|
||||
{
|
||||
if ($value === null) {
|
||||
unset($this->registry[$key]);
|
||||
@ -204,8 +204,8 @@ abstract class Driver
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches information stored bound to the loop. Stored information is package private. Packages MUST NOT retrieve
|
||||
* the stored state of other packages.
|
||||
* Gets information stored bound to the loop. Stored information is package private. Packages MUST NOT retrieve the
|
||||
* stored state of other packages.
|
||||
*
|
||||
* Therefore packages SHOULD use the following prefix to keys: `vendor.package.`
|
||||
*
|
||||
@ -213,7 +213,7 @@ abstract class Driver
|
||||
*
|
||||
* @return mixed previously stored value or null if it doesn't exist
|
||||
*/
|
||||
final public function fetchState($key)
|
||||
final public function getState($key)
|
||||
{
|
||||
return isset($this->registry[$key]) ? $this->registry[$key] : null;
|
||||
}
|
||||
|
@ -2,31 +2,29 @@
|
||||
|
||||
namespace Interop\Async\Loop;
|
||||
|
||||
class RegistryTest extends \PHPUnit_Framework_TestCase
|
||||
class LoopStateTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $registry;
|
||||
private $loop;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->registry = $this->getMockForAbstractClass(Driver::class);
|
||||
$this->loop = $this->getMockForAbstractClass(Driver::class);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function defaultsToNull()
|
||||
{
|
||||
$this->assertNull($this->registry->fetchState("foobar"));
|
||||
$this->assertNull($this->loop->getState("foobar"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideValues
|
||||
*/
|
||||
public function fetchesStoredValue($value)
|
||||
public function getsPreviouslySetValue($value)
|
||||
{
|
||||
$this->assertNull($this->registry->fetchState("foobar"));
|
||||
$this->registry->storeState("foobar", $value);
|
||||
|
||||
$this->assertSame($value, $this->registry->fetchState("foobar"));
|
||||
$this->loop->setState("foobar", $value);
|
||||
$this->assertSame($value, $this->loop->getState("foobar"));
|
||||
}
|
||||
|
||||
public function provideValues()
|
Loading…
Reference in New Issue
Block a user