Skip to content

Commit 297f2fa

Browse files
committed
Run tests on PHPUnit 9 and clean up test suite
1 parent 0dbab58 commit 297f2fa

12 files changed

+139
-204
lines changed

.travis.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ language: php
33
# lock distro so new future defaults will not break the build
44
dist: trusty
55

6-
matrix:
6+
jobs:
77
include:
88
- php: 5.3
99
dist: precise
@@ -20,10 +20,8 @@ matrix:
2020
allow_failures:
2121
- php: hhvm-3.18
2222

23-
sudo: false
24-
2523
install:
26-
- composer install --no-interaction
24+
- composer install
2725

2826
script:
2927
- vendor/bin/phpunit --coverage-text

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
},
2929
"require-dev": {
3030
"clue/block-react": "^1.3",
31-
"phpunit/phpunit": "^7.4 || ^6.4 || ^5.0 || ^4.8.36",
31+
"phpunit/phpunit": "^9.0 || ^5.7 || ^4.8.36",
3232
"react/mysql": "^0.5.3"
3333
}
3434
}

src/Io/functions.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Returns a list of active file descriptors (may contain bogus entries)
99
*
1010
* @param string $path
11-
* @return array
11+
* @return int[]
1212
* @internal
1313
*/
1414
function fds($path = '/dev/fd')
@@ -28,6 +28,10 @@ function fds($path = '/dev/fd')
2828
\fclose($copy);
2929
}
3030
}
31+
} else {
32+
foreach ($fds as $i => $fd) {
33+
$fds[$i] = (int) $fd;
34+
}
3135
}
3236

3337
return $fds;

tests/FunctionalSshProcessConnectorTest.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ class FunctionalSshProcessConnectorTest extends TestCase
1313
private $loop;
1414
private $connector;
1515

16-
public function setUp()
16+
/**
17+
* @before
18+
*/
19+
public function setUpConnector()
1720
{
1821
$url = getenv('SSH_PROXY');
1922
if ($url === false) {
@@ -24,38 +27,29 @@ public function setUp()
2427
$this->connector = new SshProcessConnector($url, $this->loop);
2528
}
2629

27-
/**
28-
* @expectedException RuntimeException
29-
* @expectedExceptionMessage Connection to example.com:80 failed because SSH client died
30-
*/
3130
public function testConnectInvalidProxyUriWillReturnRejectedPromise()
3231
{
3332
$this->connector = new SshProcessConnector(getenv('SSH_PROXY') . '.invalid', $this->loop);
3433
$promise = $this->connector->connect('example.com:80');
3534

35+
$this->setExpectedException('RuntimeException', 'Connection to example.com:80 failed because SSH client died');
3636
\Clue\React\Block\await($promise, $this->loop, self::TIMEOUT);
3737
}
3838

39-
/**
40-
* @expectedException RuntimeException
41-
* @expectedExceptionMessage Connection to example.invalid:80 rejected:
42-
*/
4339
public function testConnectInvalidTargetWillReturnRejectedPromise()
4440
{
4541
$promise = $this->connector->connect('example.invalid:80');
4642

43+
$this->setExpectedException('RuntimeException', 'Connection to example.invalid:80 rejected:');
4744
\Clue\React\Block\await($promise, $this->loop, self::TIMEOUT);
4845
}
4946

50-
/**
51-
* @expectedException RuntimeException
52-
* @expectedExceptionMessage Connection to example.com:80 cancelled while waiting for SSH client
53-
*/
5447
public function testCancelConnectWillReturnRejectedPromise()
5548
{
5649
$promise = $this->connector->connect('example.com:80');
5750
$promise->cancel();
5851

52+
$this->setExpectedException('RuntimeException', 'Connection to example.com:80 cancelled while waiting for SSH client');
5953
\Clue\React\Block\await($promise, $this->loop, 0);
6054
}
6155

tests/FunctionalSshSocksConnectorTest.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Clue\Tests\React\SshProxy;
44

5-
use PHPUnit\Framework\TestCase;
65
use React\EventLoop\Factory;
76
use Clue\React\SshProxy\SshSocksConnector;
87

@@ -13,7 +12,10 @@ class FunctionalSshSocksConnectorTest extends TestCase
1312
private $loop;
1413
private $connector;
1514

16-
public function setUp()
15+
/**
16+
* @before
17+
*/
18+
public function setUpConnector()
1719
{
1820
$url = getenv('SSH_PROXY');
1921
if ($url === false) {
@@ -24,45 +26,39 @@ public function setUp()
2426
$this->connector = new SshSocksConnector($url, $this->loop);
2527
}
2628

27-
public function tearDown()
29+
/**
30+
* @after
31+
*/
32+
public function tearDownSSHClientProcess()
2833
{
2934
// run loop in order to shut down SSH client process again
3035
\Clue\React\Block\sleep(0.001, $this->loop);
3136
}
3237

33-
/**
34-
* @expectedException RuntimeException
35-
* @expectedExceptionMessage Connection to example.com:80 failed because SSH client process died
36-
*/
3738
public function testConnectInvalidProxyUriWillReturnRejectedPromise()
3839
{
3940
$this->connector = new SshSocksConnector(getenv('SSH_PROXY') . '.invalid', $this->loop);
4041

4142
$promise = $this->connector->connect('example.com:80');
4243

44+
$this->setExpectedException('RuntimeException', 'Connection to example.com:80 failed because SSH client process died');
4345
\Clue\React\Block\await($promise, $this->loop, self::TIMEOUT);
4446
}
4547

46-
/**
47-
* @expectedException RuntimeException
48-
* @expectedExceptionMessage Connection to tcp://example.invalid:80 failed because connection to proxy was lost
49-
*/
5048
public function testConnectInvalidTargetWillReturnRejectedPromise()
5149
{
5250
$promise = $this->connector->connect('example.invalid:80');
5351

52+
$this->setExpectedException('RuntimeException', 'Connection to tcp://example.invalid:80 failed because connection to proxy was lost');
5453
\Clue\React\Block\await($promise, $this->loop, self::TIMEOUT);
5554
}
5655

57-
/**
58-
* @expectedException RuntimeException
59-
* @expectedExceptionMessage Connection to example.com:80 cancelled while waiting for SSH client
60-
*/
6156
public function testCancelConnectWillReturnRejectedPromise()
6257
{
6358
$promise = $this->connector->connect('example.com:80');
6459
$promise->cancel();
6560

61+
$this->setExpectedException('RuntimeException', 'Connection to example.com:80 cancelled while waiting for SSH client');
6662
\Clue\React\Block\await($promise, $this->loop, 0);
6763
}
6864

tests/IntegrationSshProcessConnectorTest.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Clue\Tests\React\SshProxy;
44

55
use Clue\React\SshProxy\SshProcessConnector;
6-
use PHPUnit\Framework\TestCase;
76
use React\EventLoop\Factory;
87
use React\Socket\ConnectionInterface;
98

@@ -72,21 +71,4 @@ public function testConnectWillResolveWithConnectionThatWillEmitImmediateDataFro
7271

7372
$loop->run();
7473
}
75-
76-
protected function expectCallableOnceWith($value)
77-
{
78-
$mock = $this->createCallableMock();
79-
80-
$mock
81-
->expects($this->once())
82-
->method('__invoke')
83-
->with($value);
84-
85-
return $mock;
86-
}
87-
88-
protected function createCallableMock()
89-
{
90-
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
91-
}
9274
}

tests/Io/CompositeConnectionTest.php

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
use Clue\React\SshProxy\Io\CompositeConnection;
4-
use PHPUnit\Framework\TestCase;
4+
use \Clue\Tests\React\SshProxy\TestCase;
55
use React\Stream\ThroughStream;
66

77
class CompositeConnectionTest extends TestCase
@@ -131,30 +131,4 @@ public function testConstructWithClosedWritableStreamWillAlsoCloseReadableStream
131131
$this->assertFalse($stream->isReadable());
132132
$this->assertFalse($stream->isWritable());
133133
}
134-
135-
protected function expectCallableOnce()
136-
{
137-
$mock = $this->createCallableMock();
138-
139-
$mock
140-
->expects($this->once())
141-
->method('__invoke');
142-
143-
return $mock;
144-
}
145-
146-
protected function expectCallableNever()
147-
{
148-
$mock = $this->createCallableMock();
149-
$mock
150-
->expects($this->never())
151-
->method('__invoke');
152-
153-
return $mock;
154-
}
155-
156-
protected function createCallableMock()
157-
{
158-
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
159-
}
160134
}

tests/Io/FunctionsTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?php
22

33
use Clue\React\SshProxy\Io;
4-
use PHPUnit\Framework\TestCase;
4+
use \Clue\Tests\React\SshProxy\TestCase;
55

66
class FunctionsTest extends TestCase
77
{
88
public function testFdsReturnsArray()
99
{
1010
$fds = Io\fds();
1111

12-
$this->assertInternalType('array', $fds);
12+
$this->assertEquals('array', gettype($fds));
1313
}
1414

1515
public function testFdsReturnsArrayWithStdioHandles()
@@ -38,7 +38,7 @@ public function testFdsWithInvalidPathReturnsArray()
3838
{
3939
$fds = Io\fds('/dev/null');
4040

41-
$this->assertInternalType('array', $fds);
41+
$this->assertEquals('array', gettype($fds));
4242
}
4343

4444
public function testFdsWithInvalidPathReturnsSubsetOfFdsFromDevFd()
@@ -65,9 +65,9 @@ public function testProcessWithoutFdsReturnsProcessWithoutClosingDefaultHandles(
6565

6666
$this->assertInstanceOf('React\ChildProcess\Process', $process);
6767

68-
$this->assertNotContains(' 0>&-', $process->getCommand());
69-
$this->assertNotContains(' 1>&-', $process->getCommand());
70-
$this->assertNotContains(' 2>&-', $process->getCommand());
68+
$this->assertNotContainsString(' 0>&-', $process->getCommand());
69+
$this->assertNotContainsString(' 1>&-', $process->getCommand());
70+
$this->assertNotContainsString(' 2>&-', $process->getCommand());
7171
}
7272

7373
public function testProcessWithoutFdsReturnsProcessWithOriginalCommandPartOfActualCommandWhenDescriptorsNeedToBeClosed()
@@ -84,6 +84,6 @@ public function testProcessWithoutFdsReturnsProcessWithOriginalCommandPartOfActu
8484
$this->assertInstanceOf('React\ChildProcess\Process', $process);
8585

8686
$this->assertNotEquals('sleep 10', $process->getCommand());
87-
$this->assertContains('sleep 10', $process->getCommand());
87+
$this->assertContainsString('sleep 10', $process->getCommand());
8888
}
8989
}

tests/Io/LineSeparatedReaderTest.php

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
use Clue\React\SshProxy\Io\LineSeparatedReader;
4-
use PHPUnit\Framework\TestCase;
4+
use \Clue\Tests\React\SshProxy\TestCase;
55
use React\Stream\ThroughStream;
66

77
class LineSeparatedReaderTest extends TestCase
@@ -130,42 +130,4 @@ public function testPipeWillReturnDestinationStream()
130130

131131
$this->assertSame($dest, $ret);
132132
}
133-
134-
protected function expectCallableOnce()
135-
{
136-
$mock = $this->createCallableMock();
137-
138-
$mock
139-
->expects($this->once())
140-
->method('__invoke');
141-
142-
return $mock;
143-
}
144-
145-
protected function expectCallableOnceWith($value)
146-
{
147-
$mock = $this->createCallableMock();
148-
149-
$mock
150-
->expects($this->once())
151-
->method('__invoke')
152-
->with($value);
153-
154-
return $mock;
155-
}
156-
157-
protected function expectCallableNever()
158-
{
159-
$mock = $this->createCallableMock();
160-
$mock
161-
->expects($this->never())
162-
->method('__invoke');
163-
164-
return $mock;
165-
}
166-
167-
protected function createCallableMock()
168-
{
169-
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
170-
}
171133
}

0 commit comments

Comments
 (0)