init
This commit is contained in:
103
vendor/react/socket/tests/TimeoutConnectorTest.php
vendored
Executable file
103
vendor/react/socket/tests/TimeoutConnectorTest.php
vendored
Executable file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace React\Tests\Socket;
|
||||
|
||||
use React\Socket\TimeoutConnector;
|
||||
use React\Promise;
|
||||
use React\EventLoop\Factory;
|
||||
|
||||
class TimeoutConnectorTest extends TestCase
|
||||
{
|
||||
public function testRejectsOnTimeout()
|
||||
{
|
||||
$promise = new Promise\Promise(function () { });
|
||||
|
||||
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
|
||||
$connector->expects($this->once())->method('connect')->with('google.com:80')->will($this->returnValue($promise));
|
||||
|
||||
$loop = Factory::create();
|
||||
|
||||
$timeout = new TimeoutConnector($connector, 0.01, $loop);
|
||||
|
||||
$timeout->connect('google.com:80')->then(
|
||||
$this->expectCallableNever(),
|
||||
$this->expectCallableOnce()
|
||||
);
|
||||
|
||||
$loop->run();
|
||||
}
|
||||
|
||||
public function testRejectsWhenConnectorRejects()
|
||||
{
|
||||
$promise = Promise\reject(new \RuntimeException());
|
||||
|
||||
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
|
||||
$connector->expects($this->once())->method('connect')->with('google.com:80')->will($this->returnValue($promise));
|
||||
|
||||
$loop = Factory::create();
|
||||
|
||||
$timeout = new TimeoutConnector($connector, 5.0, $loop);
|
||||
|
||||
$timeout->connect('google.com:80')->then(
|
||||
$this->expectCallableNever(),
|
||||
$this->expectCallableOnce()
|
||||
);
|
||||
|
||||
$loop->run();
|
||||
}
|
||||
|
||||
public function testResolvesWhenConnectorResolves()
|
||||
{
|
||||
$promise = Promise\resolve();
|
||||
|
||||
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
|
||||
$connector->expects($this->once())->method('connect')->with('google.com:80')->will($this->returnValue($promise));
|
||||
|
||||
$loop = Factory::create();
|
||||
|
||||
$timeout = new TimeoutConnector($connector, 5.0, $loop);
|
||||
|
||||
$timeout->connect('google.com:80')->then(
|
||||
$this->expectCallableOnce(),
|
||||
$this->expectCallableNever()
|
||||
);
|
||||
|
||||
$loop->run();
|
||||
}
|
||||
|
||||
public function testRejectsAndCancelsPendingPromiseOnTimeout()
|
||||
{
|
||||
$promise = new Promise\Promise(function () { }, $this->expectCallableOnce());
|
||||
|
||||
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
|
||||
$connector->expects($this->once())->method('connect')->with('google.com:80')->will($this->returnValue($promise));
|
||||
|
||||
$loop = Factory::create();
|
||||
|
||||
$timeout = new TimeoutConnector($connector, 0.01, $loop);
|
||||
|
||||
$timeout->connect('google.com:80')->then(
|
||||
$this->expectCallableNever(),
|
||||
$this->expectCallableOnce()
|
||||
);
|
||||
|
||||
$loop->run();
|
||||
}
|
||||
|
||||
public function testCancelsPendingPromiseOnCancel()
|
||||
{
|
||||
$promise = new Promise\Promise(function () { }, function () { throw new \Exception(); });
|
||||
|
||||
$connector = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
|
||||
$connector->expects($this->once())->method('connect')->with('google.com:80')->will($this->returnValue($promise));
|
||||
|
||||
$loop = Factory::create();
|
||||
|
||||
$timeout = new TimeoutConnector($connector, 0.01, $loop);
|
||||
|
||||
$out = $timeout->connect('google.com:80');
|
||||
$out->cancel();
|
||||
|
||||
$out->then($this->expectCallableNever(), $this->expectCallableOnce());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user