Skip to content

Commit e846bbb

Browse files
committed
Run test suite on Windows
1 parent 59730c4 commit e846bbb

9 files changed

+64
-55
lines changed

.travis.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,27 @@ matrix:
1616
- php: 7.3
1717
- php: 7.4
1818
- php: hhvm-3.18
19-
install: composer require phpunit/phpunit:^5 --dev --no-interaction # requires legacy phpunit
2019
- name: Mac OS X
2120
os: osx
2221
language: generic
2322
before_install:
2423
- curl -s http://getcomposer.org/installer | php
2524
- mv composer.phar /usr/local/bin/composer
25+
- name: Windows
26+
os: windows
27+
language: bash
28+
before_install:
29+
- choco install php
30+
- choco install composer
31+
- export PATH="$(powershell -Command '("Process", "Machine" | % { [Environment]::GetEnvironmentVariable("PATH", $_) -Split ";" -Replace "\\$", "" } | Select -Unique | % { cygpath $_ }) -Join ":"')"
32+
- php -r "file_put_contents(php_ini_loaded_file(),'extension_dir=ext'.PHP_EOL,FILE_APPEND);"
33+
- php -r "file_put_contents(php_ini_loaded_file(),'extension=sockets'.PHP_EOL,FILE_APPEND);"
34+
install:
35+
- composer install
2636
allow_failures:
2737
- php: hhvm-3.18
2838
- os: osx
39+
- os: windows
2940

3041
sudo: false
3142

tests/FunctionalSecureServerTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
use React\Socket\SecureConnector;
1111
use React\Socket\ServerInterface;
1212
use React\Socket\SecureServer;
13-
use React\Socket\TcpServer;
1413
use React\Socket\TcpConnector;
14+
use React\Socket\TcpServer;
1515

1616
class FunctionalSecureServerTest extends TestCase
1717
{
@@ -549,6 +549,10 @@ public function testServerEmitsErrorForClientWithInvalidCertificate()
549549

550550
public function testEmitsErrorForServerWithEncryptedCertificateMissingPassphrase()
551551
{
552+
if (DIRECTORY_SEPARATOR === '\\') {
553+
$this->markTestSkipped('Not supported on Windows');
554+
}
555+
552556
$loop = Factory::create();
553557

554558
$server = new TcpServer(0, $loop);
@@ -569,6 +573,10 @@ public function testEmitsErrorForServerWithEncryptedCertificateMissingPassphrase
569573

570574
public function testEmitsErrorForServerWithEncryptedCertificateWithInvalidPassphrase()
571575
{
576+
if (DIRECTORY_SEPARATOR === '\\') {
577+
$this->markTestSkipped('Not supported on Windows');
578+
}
579+
572580
$loop = Factory::create();
573581

574582
$server = new TcpServer(0, $loop);

tests/FunctionalTcpServerTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ public function testEmitsConnectionWithLocalIp()
116116

117117
public function testEmitsConnectionWithLocalIpDespiteListeningOnAll()
118118
{
119+
if (DIRECTORY_SEPARATOR === '\\') {
120+
$this->markTestSkipped('Skipping on Windows due to default firewall rules');
121+
}
122+
119123
$loop = Factory::create();
120124

121125
$server = new TcpServer('0.0.0.0:0', $loop);

tests/HappyEyeBallsConnectorTest.php

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -178,52 +178,6 @@ public function testIpv6DoesntResolvesWhileIpv4DoesFirstSoIpv4Connects(array $ip
178178
$this->loop->run();
179179
}
180180

181-
public function testThatTheIpv4ConnectionWillWait100MilisecondsWhenIpv6AndIpv4ResolveSimultaniously()
182-
{
183-
$timings = array();
184-
$this->resolver->expects($this->at(0))->method('resolveAll')->with('google.com', Message::TYPE_AAAA)->will($this->returnValue(Promise\resolve(array('1:2:3:4'))));
185-
$this->resolver->expects($this->at(1))->method('resolveAll')->with('google.com', Message::TYPE_A)->will($this->returnValue(Promise\resolve(array('1.2.3.4'))));
186-
$this->tcp->expects($this->at(0))->method('connect')->with($this->equalTo('scheme://[1:2:3:4]:80/?hostname=google.com'))->will($this->returnCallback(function () use (&$timings) {
187-
$timings[Message::TYPE_AAAA] = microtime(true);
188-
189-
return new Promise\Promise(function () {});
190-
}));
191-
$this->tcp->expects($this->at(1))->method('connect')->with($this->equalTo('scheme://1.2.3.4:80/?hostname=google.com'))->will($this->returnCallback(function () use (&$timings) {
192-
$timings[Message::TYPE_A] = microtime(true);
193-
194-
return new Promise\Promise(function () {});
195-
}));
196-
197-
$this->connector->connect('scheme://google.com:80/?hostname=google.com');
198-
199-
$this->loop->run();
200-
201-
self::assertGreaterThan(0.01, $timings[Message::TYPE_A] - $timings[Message::TYPE_AAAA]);
202-
}
203-
204-
/**
205-
* @dataProvider provideIpvAddresses
206-
*/
207-
public function testAssert100MilisecondsBetweenConnectionAttempts(array $ipv6, array $ipv4)
208-
{
209-
$timings = array();
210-
$this->resolver->expects($this->at(0))->method('resolveAll')->with('google.com', Message::TYPE_AAAA)->will($this->returnValue(Promise\resolve($ipv6)));
211-
$this->resolver->expects($this->at(1))->method('resolveAll')->with('google.com', Message::TYPE_A)->will($this->returnValue(Promise\resolve($ipv4)));
212-
$this->tcp->expects($this->any())->method('connect')->with($this->stringContains(':80/?hostname=google.com'))->will($this->returnCallback(function () use (&$timings) {
213-
$timings[] = microtime(true);
214-
215-
return new Promise\Promise(function () {});
216-
}));
217-
218-
$this->connector->connect('scheme://google.com:80/?hostname=google.com');
219-
220-
$this->loop->run();
221-
222-
for ($i = 0; $i < (count($timings) - 1); $i++) {
223-
self::assertGreaterThan(0.01, $timings[$i + 1] - $timings[$i]);
224-
}
225-
}
226-
227181
/**
228182
* @dataProvider provideIpvAddresses
229183
*/

tests/IntegrationTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ function ($e) use (&$wait) {
175175
if ($wait) {
176176
Block\sleep(0.2, $loop);
177177
if ($wait) {
178-
$this->fail('Connection attempt did not fail');
178+
Block\sleep(2.0, $loop);
179+
if ($wait) {
180+
$this->fail('Connection attempt did not fail');
181+
}
179182
}
180183
}
181184
unset($promise);

tests/TcpConnectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class TcpConnectorTest extends TestCase
1313
{
14-
const TIMEOUT = 0.1;
14+
const TIMEOUT = 5.0;
1515

1616
/**
1717
* @test

tests/TcpServerTest.php

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
use React\EventLoop\Factory;
77
use React\Socket\TcpServer;
88
use React\Stream\DuplexResourceStream;
9+
use React\Promise\Promise;
910

1011
class TcpServerTest extends TestCase
1112
{
13+
const TIMEOUT = 5.0;
14+
1215
private $loop;
1316
private $server;
1417
private $port;
@@ -33,13 +36,18 @@ public function setUp()
3336
/**
3437
* @covers React\Socket\TcpServer::handleConnection
3538
*/
36-
public function testConnection()
39+
public function testServerEmitsConnectionEventForNewConnection()
3740
{
3841
$client = stream_socket_client('tcp://localhost:'.$this->port);
3942

40-
$this->server->on('connection', $this->expectCallableOnce());
43+
$server = $this->server;
44+
$promise = new Promise(function ($resolve) use ($server) {
45+
$server->on('connection', $resolve);
46+
});
4147

42-
$this->tick();
48+
$connection = Block\await($promise, $this->loop, self::TIMEOUT);
49+
50+
$this->assertInstanceOf('React\Socket\ConnectionInterface', $connection);
4351
}
4452

4553
/**
@@ -270,7 +278,9 @@ public function testEmitsErrorWhenAcceptListenerFails()
270278
$server->on('error', $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException')));
271279

272280
$this->assertNotNull($listener);
273-
$listener(false);
281+
$socket = stream_socket_server('tcp://127.0.0.1:0');
282+
fclose($socket);
283+
$listener($socket);
274284
}
275285

276286
/**
@@ -295,8 +305,21 @@ public function tearDown()
295305
}
296306
}
297307

308+
/**
309+
* This methods runs the loop for "one tick"
310+
*
311+
* This is prone to race conditions and as such somewhat unreliable across
312+
* different operating systems. Running the loop until the expected events
313+
* fire is the preferred alternative.
314+
*
315+
* @deprecated
316+
*/
298317
private function tick()
299318
{
319+
if (DIRECTORY_SEPARATOR === '\\') {
320+
$this->markTestSkipped('Not supported on Windows');
321+
}
322+
300323
Block\sleep(0, $this->loop);
301324
}
302325
}

tests/UnixConnectorTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public function testInvalidScheme()
3030

3131
public function testValid()
3232
{
33+
if (!in_array('unix', stream_get_transports())) {
34+
$this->markTestSkipped('Unix domain sockets (UDS) not supported on your platform (Windows?)');
35+
}
36+
3337
// random unix domain socket path
3438
$path = sys_get_temp_dir() . '/test' . uniqid() . '.sock';
3539

tests/UnixServerTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,9 @@ public function testEmitsErrorWhenAcceptListenerFails()
287287
$server->on('error', $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException')));
288288

289289
$this->assertNotNull($listener);
290-
$listener(false);
290+
$socket = stream_socket_server('tcp://127.0.0.1:0');
291+
fclose($socket);
292+
$listener($socket);
291293
}
292294

293295
/**

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy