Skip to content

Run tests on PHPUnit 9 and clean up test suite #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: php
# lock distro so new future defaults will not break the build
dist: trusty

matrix:
jobs:
include:
- php: 5.3
dist: precise
Expand All @@ -20,10 +20,8 @@ matrix:
allow_failures:
- php: hhvm-3.18

sudo: false

install:
- composer install --no-interaction
- composer install

script:
- vendor/bin/phpunit --coverage-text
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"require-dev": {
"clue/block-react": "^1.3",
"phpunit/phpunit": "^7.4 || ^6.4 || ^5.0 || ^4.8.36",
"phpunit/phpunit": "^9.0 || ^5.7 || ^4.8.36",
"react/mysql": "^0.5.3"
}
}
6 changes: 5 additions & 1 deletion src/Io/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Returns a list of active file descriptors (may contain bogus entries)
*
* @param string $path
* @return array
* @return int[]
* @internal
*/
function fds($path = '/dev/fd')
Expand All @@ -28,6 +28,10 @@ function fds($path = '/dev/fd')
\fclose($copy);
}
}
} else {
foreach ($fds as $i => $fd) {
$fds[$i] = (int) $fd;
}
}

return $fds;
Expand Down
20 changes: 7 additions & 13 deletions tests/FunctionalSshProcessConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ class FunctionalSshProcessConnectorTest extends TestCase
private $loop;
private $connector;

public function setUp()
/**
* @before
*/
public function setUpConnector()
{
$url = getenv('SSH_PROXY');
if ($url === false) {
Expand All @@ -24,38 +27,29 @@ public function setUp()
$this->connector = new SshProcessConnector($url, $this->loop);
}

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

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

/**
* @expectedException RuntimeException
* @expectedExceptionMessage Connection to example.invalid:80 rejected:
*/
public function testConnectInvalidTargetWillReturnRejectedPromise()
{
$promise = $this->connector->connect('example.invalid:80');

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

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

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

Expand Down
26 changes: 11 additions & 15 deletions tests/FunctionalSshSocksConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Clue\Tests\React\SshProxy;

use PHPUnit\Framework\TestCase;
use React\EventLoop\Factory;
use Clue\React\SshProxy\SshSocksConnector;

Expand All @@ -13,7 +12,10 @@ class FunctionalSshSocksConnectorTest extends TestCase
private $loop;
private $connector;

public function setUp()
/**
* @before
*/
public function setUpConnector()
{
$url = getenv('SSH_PROXY');
if ($url === false) {
Expand All @@ -24,45 +26,39 @@ public function setUp()
$this->connector = new SshSocksConnector($url, $this->loop);
}

public function tearDown()
/**
* @after
*/
public function tearDownSSHClientProcess()
{
// run loop in order to shut down SSH client process again
\Clue\React\Block\sleep(0.001, $this->loop);
}

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

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

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

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

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

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

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

Expand Down
18 changes: 0 additions & 18 deletions tests/IntegrationSshProcessConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Clue\Tests\React\SshProxy;

use Clue\React\SshProxy\SshProcessConnector;
use PHPUnit\Framework\TestCase;
use React\EventLoop\Factory;
use React\Socket\ConnectionInterface;

Expand Down Expand Up @@ -72,21 +71,4 @@ public function testConnectWillResolveWithConnectionThatWillEmitImmediateDataFro

$loop->run();
}

protected function expectCallableOnceWith($value)
{
$mock = $this->createCallableMock();

$mock
->expects($this->once())
->method('__invoke')
->with($value);

return $mock;
}

protected function createCallableMock()
{
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
}
}
28 changes: 1 addition & 27 deletions tests/Io/CompositeConnectionTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use Clue\React\SshProxy\Io\CompositeConnection;
use PHPUnit\Framework\TestCase;
use \Clue\Tests\React\SshProxy\TestCase;
use React\Stream\ThroughStream;

class CompositeConnectionTest extends TestCase
Expand Down Expand Up @@ -131,30 +131,4 @@ public function testConstructWithClosedWritableStreamWillAlsoCloseReadableStream
$this->assertFalse($stream->isReadable());
$this->assertFalse($stream->isWritable());
}

protected function expectCallableOnce()
{
$mock = $this->createCallableMock();

$mock
->expects($this->once())
->method('__invoke');

return $mock;
}

protected function expectCallableNever()
{
$mock = $this->createCallableMock();
$mock
->expects($this->never())
->method('__invoke');

return $mock;
}

protected function createCallableMock()
{
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
}
}
14 changes: 7 additions & 7 deletions tests/Io/FunctionsTest.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php

use Clue\React\SshProxy\Io;
use PHPUnit\Framework\TestCase;
use \Clue\Tests\React\SshProxy\TestCase;

class FunctionsTest extends TestCase
{
public function testFdsReturnsArray()
{
$fds = Io\fds();

$this->assertInternalType('array', $fds);
$this->assertEquals('array', gettype($fds));
}

public function testFdsReturnsArrayWithStdioHandles()
Expand Down Expand Up @@ -38,7 +38,7 @@ public function testFdsWithInvalidPathReturnsArray()
{
$fds = Io\fds('/dev/null');

$this->assertInternalType('array', $fds);
$this->assertEquals('array', gettype($fds));
}

public function testFdsWithInvalidPathReturnsSubsetOfFdsFromDevFd()
Expand All @@ -65,9 +65,9 @@ public function testProcessWithoutFdsReturnsProcessWithoutClosingDefaultHandles(

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

$this->assertNotContains(' 0>&-', $process->getCommand());
$this->assertNotContains(' 1>&-', $process->getCommand());
$this->assertNotContains(' 2>&-', $process->getCommand());
$this->assertNotContainsString(' 0>&-', $process->getCommand());
$this->assertNotContainsString(' 1>&-', $process->getCommand());
$this->assertNotContainsString(' 2>&-', $process->getCommand());
}

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

$this->assertNotEquals('sleep 10', $process->getCommand());
$this->assertContains('sleep 10', $process->getCommand());
$this->assertContainsString('sleep 10', $process->getCommand());
}
}
40 changes: 1 addition & 39 deletions tests/Io/LineSeparatedReaderTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use Clue\React\SshProxy\Io\LineSeparatedReader;
use PHPUnit\Framework\TestCase;
use \Clue\Tests\React\SshProxy\TestCase;
use React\Stream\ThroughStream;

class LineSeparatedReaderTest extends TestCase
Expand Down Expand Up @@ -130,42 +130,4 @@ public function testPipeWillReturnDestinationStream()

$this->assertSame($dest, $ret);
}

protected function expectCallableOnce()
{
$mock = $this->createCallableMock();

$mock
->expects($this->once())
->method('__invoke');

return $mock;
}

protected function expectCallableOnceWith($value)
{
$mock = $this->createCallableMock();

$mock
->expects($this->once())
->method('__invoke')
->with($value);

return $mock;
}

protected function expectCallableNever()
{
$mock = $this->createCallableMock();
$mock
->expects($this->never())
->method('__invoke');

return $mock;
}

protected function createCallableMock()
{
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
}
}
Loading