mirror of
https://github.com/danog/amp.git
synced 2024-11-30 04:29:08 +01:00
b197b2c07d
This also ensures that potential throwing in the callback will be handled inside a potential error handler instead of immediately falling through.
47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Interop\Async\Loop\Test;
|
|
|
|
use Interop\Async\Loop;
|
|
|
|
class LoopTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
protected function setUp() {
|
|
Loop::setFactory(null);
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
* @expectedException \RuntimeException
|
|
* @expectedExceptionMessage new factory while running isn't allowed
|
|
*/
|
|
public function setFactoryFailsIfRunning() {
|
|
$driver = new DummyDriver;
|
|
|
|
$factory = $this->getMockBuilder(Loop\DriverFactory::class)->getMock();
|
|
$factory->method("create")->willReturn($driver);
|
|
|
|
Loop::setFactory($factory);
|
|
|
|
Loop::execute(function () use ($factory) {
|
|
Loop::setFactory($factory);
|
|
});
|
|
}
|
|
|
|
/** @test */
|
|
public function executeStackReturnsScopedDriver() {
|
|
$driver1 = new DummyDriver;
|
|
$driver2 = new DummyDriver;
|
|
|
|
Loop::execute(function () use ($driver1, $driver2) {
|
|
$this->assertSame($driver1, Loop::get());
|
|
|
|
Loop::execute(function () use ($driver2) {
|
|
$this->assertSame($driver2, Loop::get());
|
|
}, $driver2);
|
|
|
|
$this->assertSame($driver1, Loop::get());
|
|
}, $driver1);
|
|
}
|
|
}
|