public static setFactory ( Interop\Async\Loop\DriverFactory $factory = null ) | ||
$factory | Interop\Async\Loop\DriverFactory | New factory to replace the previous one. |
public static function setFactory(DriverFactory $factory = null)
{
if (self::$level > 0) {
throw new \RuntimeException("Setting a new factory while running isn't allowed!");
}
self::$factory = $factory;
// reset it here, it will be actually instantiated inside execute() or get()
self::$driver = 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); }); }