mirror of
https://github.com/danog/amp.git
synced 2024-11-30 04:29:08 +01:00
Update for setErrorHandler() & getWatcherId + new test with stop()
This commit is contained in:
parent
e8fb7169d4
commit
2c0d6064af
@ -5,7 +5,7 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.5.0",
|
"php": ">=5.5.0",
|
||||||
"async-interop/event-loop": "^0.3",
|
"async-interop/event-loop": "^0.4|dev-master",
|
||||||
"phpunit/phpunit": "^4|^5"
|
"phpunit/phpunit": "^4|^5"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
33
src/Test.php
33
src/Test.php
@ -612,7 +612,12 @@ abstract class Test extends \PHPUnit_Framework_TestCase {
|
|||||||
/** @expectedException \Interop\Async\Loop\InvalidWatcherException */
|
/** @expectedException \Interop\Async\Loop\InvalidWatcherException */
|
||||||
function testExceptionOnEnableNonexistentWatcher()
|
function testExceptionOnEnableNonexistentWatcher()
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$this->loop->enable("nonexistentWatcher");
|
$this->loop->enable("nonexistentWatcher");
|
||||||
|
} catch (Loop\InvalidWatcherException $e) {
|
||||||
|
$this->assertEquals("nonexistentWatcher", $e->getWatcherId());
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function testSuccessOnDisableNonexistentWatcher()
|
function testSuccessOnDisableNonexistentWatcher()
|
||||||
@ -628,13 +633,23 @@ abstract class Test extends \PHPUnit_Framework_TestCase {
|
|||||||
/** @expectedException \Interop\Async\Loop\InvalidWatcherException */
|
/** @expectedException \Interop\Async\Loop\InvalidWatcherException */
|
||||||
function testExceptionOnReferenceNonexistentWatcher()
|
function testExceptionOnReferenceNonexistentWatcher()
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$this->loop->reference("nonexistentWatcher");
|
$this->loop->reference("nonexistentWatcher");
|
||||||
|
} catch (Loop\InvalidWatcherException $e) {
|
||||||
|
$this->assertEquals("nonexistentWatcher", $e->getWatcherId());
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @expectedException \Interop\Async\Loop\InvalidWatcherException */
|
/** @expectedException \Interop\Async\Loop\InvalidWatcherException */
|
||||||
function testExceptionOnUnreferenceNonexistentWatcher()
|
function testExceptionOnUnreferenceNonexistentWatcher()
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$this->loop->unreference("nonexistentWatcher");
|
$this->loop->unreference("nonexistentWatcher");
|
||||||
|
} catch (Loop\InvalidWatcherException $e) {
|
||||||
|
$this->assertEquals("nonexistentWatcher", $e->getWatcherId());
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @expectedException \Interop\Async\Loop\InvalidWatcherException */
|
/** @expectedException \Interop\Async\Loop\InvalidWatcherException */
|
||||||
@ -860,9 +875,11 @@ abstract class Test extends \PHPUnit_Framework_TestCase {
|
|||||||
function testErrorHandlerCapturesUncaughtException()
|
function testErrorHandlerCapturesUncaughtException()
|
||||||
{
|
{
|
||||||
$msg = "";
|
$msg = "";
|
||||||
$this->loop->setErrorHandler(function(\Exception $error) use (&$msg) {
|
$this->loop->setErrorHandler($f = function() {});
|
||||||
|
$oldErrorHandler = $this->loop->setErrorHandler(function(\Exception $error) use (&$msg) {
|
||||||
$msg = $error->getMessage();
|
$msg = $error->getMessage();
|
||||||
});
|
});
|
||||||
|
$this->assertEquals($d, $oldErrorHandler);
|
||||||
$this->start(function(Driver $loop) {
|
$this->start(function(Driver $loop) {
|
||||||
$loop->defer(function() {
|
$loop->defer(function() {
|
||||||
throw new \Exception("loop error");
|
throw new \Exception("loop error");
|
||||||
@ -1130,6 +1147,20 @@ abstract class Test extends \PHPUnit_Framework_TestCase {
|
|||||||
$this->assertTrue($callbackData->onWritable);
|
$this->assertTrue($callbackData->onWritable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testLoopStopPreventsTimerExecution()
|
||||||
|
{
|
||||||
|
$t = microtime(1);
|
||||||
|
$this->start(function(Driver $loop) {
|
||||||
|
$loop->delay($msDelay = 10000, function () {
|
||||||
|
$this->fail("Timer was executed despite stopped loop");
|
||||||
|
});
|
||||||
|
$loop->defer(function () use ($loop) {
|
||||||
|
$loop->stop();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
$this->assertTrue($t + 0.1 > microtime(1));
|
||||||
|
}
|
||||||
|
|
||||||
// getState and setState are final, but test it here again to be sure
|
// getState and setState are final, but test it here again to be sure
|
||||||
function testRegistry() {
|
function testRegistry() {
|
||||||
$this->assertNull($this->loop->getState("foo"));
|
$this->assertNull($this->loop->getState("foo"));
|
||||||
|
Loading…
Reference in New Issue
Block a user