Skip to content

Clean up test suite and add .gitattributes to exclude dev files from export #18

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 2 commits into from
May 8, 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: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/examples/ export-ignore
/phpunit.xml.dist export-ignore
/tests/ export-ignore
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"psr-4": { "Clue\\React\\SshProxy\\": "src/" },
"files": [ "src/Io/functions.php" ]
},
"autoload-dev": {
"psr-4": { "Clue\\Tests\\React\\SshProxy\\": "tests/"}
},
"require": {
"php": ">=5.3",
"clue/socks-react": "^1.0",
Expand Down
7 changes: 1 addition & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<phpunit bootstrap="vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="Tests">
<directory>./tests/</directory>
Expand Down
2 changes: 2 additions & 0 deletions tests/FunctionalSshProcessConnectorTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Clue\Tests\React\SshProxy;

use PHPUnit\Framework\TestCase;
use React\EventLoop\Factory;
use Clue\React\SshProxy\SshProcessConnector;
Expand Down
2 changes: 2 additions & 0 deletions tests/FunctionalSshSocksConnectorTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Clue\Tests\React\SshProxy;

use PHPUnit\Framework\TestCase;
use React\EventLoop\Factory;
use Clue\React\SshProxy\SshSocksConnector;
Expand Down
10 changes: 6 additions & 4 deletions tests/IntegrationSshProcessConnectorTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Clue\Tests\React\SshProxy;

use Clue\React\SshProxy\SshProcessConnector;
use PHPUnit\Framework\TestCase;
use React\EventLoop\Factory;
Expand All @@ -12,7 +14,7 @@ public function testConnectWillResolveWithConnectionInterfaceWhenProcessOutputsC
$loop = Factory::create();
$connector = new SshProcessConnector('host', $loop);

$ref = new ReflectionProperty($connector, 'cmd');
$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);
$ref->setValue($connector, 'echo "debug2: channel 0: open confirm rwindow 2097152 rmax 32768" >&2; #');

Expand All @@ -27,7 +29,7 @@ public function testConnectWillRejectWithExceptionWhenProcessOutputsChannelOpenF
$loop = Factory::create();
$connector = new SshProcessConnector('host', $loop);

$ref = new ReflectionProperty($connector, 'cmd');
$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);
$ref->setValue($connector, 'echo "channel 0: open failed: administratively prohibited: open failed" >&2; #');

Expand All @@ -42,7 +44,7 @@ public function testConnectWillRejectWithExceptionWhenProcessOutputsEndsWithoutC
$loop = Factory::create();
$connector = new SshProcessConnector('host', $loop);

$ref = new ReflectionProperty($connector, 'cmd');
$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);
$ref->setValue($connector, 'echo foo >&2; #');

Expand All @@ -57,7 +59,7 @@ public function testConnectWillResolveWithConnectionThatWillEmitImmediateDataFro
$loop = Factory::create();
$connector = new SshProcessConnector('host', $loop);

$ref = new ReflectionProperty($connector, 'cmd');
$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);
$ref->setValue($connector, 'echo "debug2: channel 0: open confirm rwindow 2097152 rmax 32768" >&2; echo foo #');

Expand Down
2 changes: 1 addition & 1 deletion tests/Io/LineSeparatedReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function testStreamErrorWillEmitErrorAndClose()
$input = new ThroughStream();
$stream = new LineSeparatedReader($input);

$error = new RuntimeException();
$error = new \RuntimeException();
$stream->on('error', $this->expectCallableOnceWith($error));
$stream->on('close', $this->expectCallableOnce());

Expand Down
10 changes: 6 additions & 4 deletions tests/SshProcessConnectorTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Clue\Tests\React\SshProxy;

use PHPUnit\Framework\TestCase;
use Clue\React\SshProxy\SshProcessConnector;

Expand All @@ -10,7 +12,7 @@ public function testConstructorAcceptsUri()
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$connector = new SshProcessConnector('host', $loop);

$ref = new ReflectionProperty($connector, 'cmd');
$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);

$this->assertEquals('exec ssh -vv -o BatchMode=yes \'host\'', $ref->getValue($connector));
Expand All @@ -21,7 +23,7 @@ public function testConstructorAcceptsUriWithDefaultPortWillNotBeAddedToCommand(
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$connector = new SshProcessConnector('host:22', $loop);

$ref = new ReflectionProperty($connector, 'cmd');
$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);

$this->assertEquals('exec ssh -vv -o BatchMode=yes \'host\'', $ref->getValue($connector));
Expand All @@ -32,7 +34,7 @@ public function testConstructorAcceptsUriWithUserAndCustomPort()
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$connector = new SshProcessConnector('user@host:2222', $loop);

$ref = new ReflectionProperty($connector, 'cmd');
$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);

$this->assertEquals('exec ssh -vv -o BatchMode=yes -p 2222 \'user@host\'', $ref->getValue($connector));
Expand All @@ -43,7 +45,7 @@ public function testConstructorAcceptsUriWithPasswordWillPrefixSshCommandWithSsh
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$connector = new SshProcessConnector('user:pass@host', $loop);

$ref = new ReflectionProperty($connector, 'cmd');
$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);

$this->assertEquals('exec sshpass -p \'pass\' ssh -vv \'user@host\'', $ref->getValue($connector));
Expand Down
52 changes: 27 additions & 25 deletions tests/SshSocksConnectorTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Clue\Tests\React\SshProxy;

use PHPUnit\Framework\TestCase;
use Clue\React\SshProxy\SshSocksConnector;
use React\Promise\Deferred;
Expand All @@ -11,7 +13,7 @@ public function testConstructorAcceptsUri()
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$connector = new SshSocksConnector('host', $loop);

$ref = new ReflectionProperty($connector, 'cmd');
$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);

$this->assertEquals('exec ssh -v -o ExitOnForwardFailure=yes -N -o BatchMode=yes -D \'127.0.0.1:1080\' \'host\'', $ref->getValue($connector));
Expand All @@ -22,7 +24,7 @@ public function testConstructorAcceptsUriWithDefaultPortWillNotBeAddedToCommand(
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$connector = new SshSocksConnector('host:22', $loop);

$ref = new ReflectionProperty($connector, 'cmd');
$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);

$this->assertEquals('exec ssh -v -o ExitOnForwardFailure=yes -N -o BatchMode=yes -D \'127.0.0.1:1080\' \'host\'', $ref->getValue($connector));
Expand All @@ -33,7 +35,7 @@ public function testConstructorAcceptsUriWithUserAndCustomPort()
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$connector = new SshSocksConnector('user@host:2222', $loop);

$ref = new ReflectionProperty($connector, 'cmd');
$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);

$this->assertEquals('exec ssh -v -o ExitOnForwardFailure=yes -N -o BatchMode=yes -p 2222 -D \'127.0.0.1:1080\' \'user@host\'', $ref->getValue($connector));
Expand All @@ -44,7 +46,7 @@ public function testConstructorAcceptsUriWithPasswordWillPrefixSshCommandWithSsh
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$connector = new SshSocksConnector('user:pass@host', $loop);

$ref = new ReflectionProperty($connector, 'cmd');
$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);

$this->assertEquals('exec sshpass -p \'pass\' ssh -v -o ExitOnForwardFailure=yes -N -D \'127.0.0.1:1080\' \'user@host\'', $ref->getValue($connector));
Expand All @@ -55,7 +57,7 @@ public function testConstructorAcceptsUriWithCustomBindUrl()
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$connector = new SshSocksConnector('host?bind=127.1.0.1:2711', $loop);

$ref = new ReflectionProperty($connector, 'cmd');
$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);

$this->assertEquals('exec ssh -v -o ExitOnForwardFailure=yes -N -o BatchMode=yes -D \'127.1.0.1:2711\' \'host\'', $ref->getValue($connector));
Expand All @@ -66,7 +68,7 @@ public function testConstructorAcceptsUriWithCustomBindUrlIpv6()
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$connector = new SshSocksConnector('host?bind=[::1]:2711', $loop);

$ref = new ReflectionProperty($connector, 'cmd');
$ref = new \ReflectionProperty($connector, 'cmd');
$ref->setAccessible(true);

$this->assertEquals('exec ssh -v -o ExitOnForwardFailure=yes -N -o BatchMode=yes -D \'[::1]:2711\' \'host\'', $ref->getValue($connector));
Expand Down Expand Up @@ -189,7 +191,7 @@ public function testConnectWillCancelPendingIdleTimerAndWaitForSshListener()
$connector = new SshSocksConnector('host', $loop);

$timer = $this->getMockBuilder('React\EventLoop\TimerInterface')->getMock();
$ref = new ReflectionProperty($connector, 'idleTimer');
$ref = new \ReflectionProperty($connector, 'idleTimer');
$ref->setAccessible(true);
$ref->setValue($connector, $timer);

Expand All @@ -207,13 +209,13 @@ public function testConnectWithFailingSshListenerShouldReturnRejectedPromise()
$connector = new SshSocksConnector('host', $loop);

$deferred = new Deferred();
$ref = new ReflectionProperty($connector, 'listen');
$ref = new \ReflectionProperty($connector, 'listen');
$ref->setAccessible(true);
$ref->setValue($connector, $deferred->promise());

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

$deferred->reject(new RuntimeException('foobar'));
$deferred->reject(new \RuntimeException('foobar'));

$exception = null;
$promise->then(null, function ($reason) use (&$exception) {
Expand All @@ -229,7 +231,7 @@ public function testConnectTwiceWithFailingSshListenerShouldRejectBothPromises()
$connector = new SshSocksConnector('host', $loop);

$deferred = new Deferred();
$ref = new ReflectionProperty($connector, 'listen');
$ref = new \ReflectionProperty($connector, 'listen');
$ref->setAccessible(true);
$ref->setValue($connector, $deferred->promise());

Expand All @@ -239,7 +241,7 @@ public function testConnectTwiceWithFailingSshListenerShouldRejectBothPromises()
$second = $connector->connect('google.com:80');
$second->then(null, $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException')));

$deferred->reject(new InvalidArgumentException());
$deferred->reject(new \InvalidArgumentException());
}

public function testConnectCancellationWithFailingSshListenerShouldAddTimerOnce()
Expand All @@ -250,14 +252,14 @@ public function testConnectCancellationWithFailingSshListenerShouldAddTimerOnce(
$connector = new SshSocksConnector('host', $loop);

$deferred = new Deferred();
$ref = new ReflectionProperty($connector, 'listen');
$ref = new \ReflectionProperty($connector, 'listen');
$ref->setAccessible(true);
$ref->setValue($connector, $deferred->promise());

$promise = $connector->connect('google.com:80');
$promise->cancel();

$deferred->reject(new InvalidArgumentException());
$deferred->reject(new \InvalidArgumentException());
}

public function testConnectWithSuccessfulSshListenerWillInvokeSocksConnector()
Expand All @@ -266,15 +268,15 @@ public function testConnectWithSuccessfulSshListenerWillInvokeSocksConnector()

$connector = new SshSocksConnector('host', $loop);

$ref = new ReflectionProperty($connector, 'listen');
$ref = new \ReflectionProperty($connector, 'listen');
$ref->setAccessible(true);
$ref->setValue($connector, \React\Promise\resolve(null));

$deferred = new Deferred();
$socks = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$socks->expects($this->once())->method('connect')->with('google.com:80')->willReturn($deferred->promise());

$ref = new ReflectionProperty($connector, 'socks');
$ref = new \ReflectionProperty($connector, 'socks');
$ref->setAccessible(true);
$ref->setValue($connector, $socks);

Expand All @@ -292,17 +294,17 @@ public function testConnectCancellationWithSuccessfulSshListenerWillCancelSocksC

$connector = new SshSocksConnector('host', $loop);

$ref = new ReflectionProperty($connector, 'listen');
$ref = new \ReflectionProperty($connector, 'listen');
$ref->setAccessible(true);
$ref->setValue($connector, \React\Promise\resolve(null));

$deferred = new Deferred(function () {
throw new RuntimeException('SOCKS cancelled');
throw new \RuntimeException('SOCKS cancelled');
});
$socks = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$socks->expects($this->once())->method('connect')->willReturn($deferred->promise());

$ref = new ReflectionProperty($connector, 'socks');
$ref = new \ReflectionProperty($connector, 'socks');
$ref->setAccessible(true);
$ref->setValue($connector, $socks);

Expand All @@ -327,21 +329,21 @@ public function testConnectWithSuccessfulSshListenerButFailingSocksConnectorShou

$connector = new SshSocksConnector('host', $loop);

$ref = new ReflectionProperty($connector, 'listen');
$ref = new \ReflectionProperty($connector, 'listen');
$ref->setAccessible(true);
$ref->setValue($connector, \React\Promise\resolve(null));

$deferred = new Deferred();
$socks = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$socks->expects($this->once())->method('connect')->willReturn($deferred->promise());

$ref = new ReflectionProperty($connector, 'socks');
$ref = new \ReflectionProperty($connector, 'socks');
$ref->setAccessible(true);
$ref->setValue($connector, $socks);

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

$deferred->reject(new RuntimeException('Connection failed'));
$deferred->reject(new \RuntimeException('Connection failed'));

$exception = null;
$promise->then(null, function ($reason) use (&$exception) {
Expand All @@ -356,7 +358,7 @@ public function testConnectWithSuccessfulSshListenerAndSuccessfulSocksConnectorS

$connector = new SshSocksConnector('host', $loop);

$ref = new ReflectionProperty($connector, 'listen');
$ref = new \ReflectionProperty($connector, 'listen');
$ref->setAccessible(true);
$ref->setValue($connector, \React\Promise\resolve(null));

Expand All @@ -367,7 +369,7 @@ public function testConnectWithSuccessfulSshListenerAndSuccessfulSocksConnectorS
$socks = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$socks->expects($this->once())->method('connect')->willReturn($deferred->promise());

$ref = new ReflectionProperty($connector, 'socks');
$ref = new \ReflectionProperty($connector, 'socks');
$ref->setAccessible(true);
$ref->setValue($connector, $socks);

Expand All @@ -383,7 +385,7 @@ public function testConnectWithSuccessfulSshListenerAndSuccessfulSocksConnectorW

$connector = new SshSocksConnector('host', $loop);

$ref = new ReflectionProperty($connector, 'listen');
$ref = new \ReflectionProperty($connector, 'listen');
$ref->setAccessible(true);
$ref->setValue($connector, \React\Promise\resolve(null));

Expand All @@ -394,7 +396,7 @@ public function testConnectWithSuccessfulSshListenerAndSuccessfulSocksConnectorW
$socks = $this->getMockBuilder('React\Socket\ConnectorInterface')->getMock();
$socks->expects($this->once())->method('connect')->willReturn($deferred->promise());

$ref = new ReflectionProperty($connector, 'socks');
$ref = new \ReflectionProperty($connector, 'socks');
$ref->setAccessible(true);
$ref->setValue($connector, $socks);

Expand Down