2016-05-15 14:02:04 +02:00
|
|
|
<?php
|
|
|
|
|
2017-03-12 11:21:44 +01:00
|
|
|
namespace Amp\Test\Loop;
|
2016-05-24 10:37:25 +02:00
|
|
|
|
2017-03-15 08:40:58 +01:00
|
|
|
use Amp\Loop;
|
2020-11-01 16:43:21 +01:00
|
|
|
use Amp\Loop\DriverFoundation;
|
2017-03-12 11:21:44 +01:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2017-03-10 21:31:57 +01:00
|
|
|
|
2018-06-18 20:00:01 +02:00
|
|
|
class DriverStateTest extends TestCase
|
|
|
|
{
|
2020-11-01 16:43:21 +01:00
|
|
|
private DriverFoundation $loop;
|
2016-05-15 14:02:04 +02:00
|
|
|
|
2020-09-26 19:34:39 +02:00
|
|
|
protected function setUp(): void
|
2018-06-18 20:00:01 +02:00
|
|
|
{
|
2020-11-01 16:43:21 +01:00
|
|
|
$this->loop = $this->getMockForAbstractClass(DriverFoundation::class);
|
2016-05-15 14:02:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @test */
|
2020-09-26 19:34:39 +02:00
|
|
|
public function defaultsToNull(): void
|
2018-06-18 20:00:01 +02:00
|
|
|
{
|
2016-08-06 14:49:08 +02:00
|
|
|
$this->assertNull($this->loop->getState("foobar"));
|
2016-05-15 14:02:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider provideValues
|
|
|
|
*/
|
2020-09-26 19:34:39 +02:00
|
|
|
public function getsPreviouslySetValue($value): void
|
2018-06-18 20:00:01 +02:00
|
|
|
{
|
2016-08-06 14:49:08 +02:00
|
|
|
$this->loop->setState("foobar", $value);
|
|
|
|
$this->assertSame($value, $this->loop->getState("foobar"));
|
2016-05-15 14:02:04 +02:00
|
|
|
}
|
|
|
|
|
2017-03-15 08:40:58 +01:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider provideValues
|
|
|
|
*/
|
2020-09-26 19:34:39 +02:00
|
|
|
public function getsPreviouslySetValueViaAccessor($value): void
|
2018-06-18 20:00:01 +02:00
|
|
|
{
|
2017-03-15 08:40:58 +01:00
|
|
|
Loop::setState("foobar", $value);
|
|
|
|
$this->assertSame($value, Loop::getState("foobar"));
|
|
|
|
}
|
|
|
|
|
2020-09-26 19:34:39 +02:00
|
|
|
public function provideValues(): array
|
2018-06-18 20:00:01 +02:00
|
|
|
{
|
2016-05-15 14:02:04 +02:00
|
|
|
return [
|
|
|
|
["string"],
|
|
|
|
[42],
|
|
|
|
[1.001],
|
|
|
|
[true],
|
|
|
|
[false],
|
|
|
|
[null],
|
|
|
|
[new \StdClass],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|