Skip to content

Commit 0dbab58

Browse files
authored
Merge pull request #18 from SimonFrings/tests
Clean up test suite and add .gitattributes to exclude dev files from
2 parents a67a8c8 + ab13365 commit 0dbab58

9 files changed

+54
-40
lines changed

.gitattributes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/.gitattributes export-ignore
2+
/.gitignore export-ignore
3+
/.travis.yml export-ignore
4+
/examples/ export-ignore
5+
/phpunit.xml.dist export-ignore
6+
/tests/ export-ignore

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
"psr-4": { "Clue\\React\\SshProxy\\": "src/" },
1515
"files": [ "src/Io/functions.php" ]
1616
},
17+
"autoload-dev": {
18+
"psr-4": { "Clue\\Tests\\React\\SshProxy\\": "tests/"}
19+
},
1720
"require": {
1821
"php": ">=5.3",
1922
"clue/socks-react": "^1.0",

phpunit.xml.dist

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<phpunit bootstrap="vendor/autoload.php"
4-
colors="true"
5-
convertErrorsToExceptions="true"
6-
convertNoticesToExceptions="true"
7-
convertWarningsToExceptions="true"
8-
>
3+
<phpunit bootstrap="vendor/autoload.php" colors="true">
94
<testsuites>
105
<testsuite name="Tests">
116
<directory>./tests/</directory>

tests/FunctionalSshProcessConnectorTest.php

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

3+
namespace Clue\Tests\React\SshProxy;
4+
35
use PHPUnit\Framework\TestCase;
46
use React\EventLoop\Factory;
57
use Clue\React\SshProxy\SshProcessConnector;

tests/FunctionalSshSocksConnectorTest.php

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

3+
namespace Clue\Tests\React\SshProxy;
4+
35
use PHPUnit\Framework\TestCase;
46
use React\EventLoop\Factory;
57
use Clue\React\SshProxy\SshSocksConnector;

tests/IntegrationSshProcessConnectorTest.php

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

3+
namespace Clue\Tests\React\SshProxy;
4+
35
use Clue\React\SshProxy\SshProcessConnector;
46
use PHPUnit\Framework\TestCase;
57
use React\EventLoop\Factory;
@@ -12,7 +14,7 @@ public function testConnectWillResolveWithConnectionInterfaceWhenProcessOutputsC
1214
$loop = Factory::create();
1315
$connector = new SshProcessConnector('host', $loop);
1416

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

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

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

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

45-
$ref = new ReflectionProperty($connector, 'cmd');
47+
$ref = new \ReflectionProperty($connector, 'cmd');
4648
$ref->setAccessible(true);
4749
$ref->setValue($connector, 'echo foo >&2; #');
4850

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

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

tests/Io/LineSeparatedReaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function testStreamErrorWillEmitErrorAndClose()
8080
$input = new ThroughStream();
8181
$stream = new LineSeparatedReader($input);
8282

83-
$error = new RuntimeException();
83+
$error = new \RuntimeException();
8484
$stream->on('error', $this->expectCallableOnceWith($error));
8585
$stream->on('close', $this->expectCallableOnce());
8686

tests/SshProcessConnectorTest.php

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

3+
namespace Clue\Tests\React\SshProxy;
4+
35
use PHPUnit\Framework\TestCase;
46
use Clue\React\SshProxy\SshProcessConnector;
57

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

13-
$ref = new ReflectionProperty($connector, 'cmd');
15+
$ref = new \ReflectionProperty($connector, 'cmd');
1416
$ref->setAccessible(true);
1517

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

24-
$ref = new ReflectionProperty($connector, 'cmd');
26+
$ref = new \ReflectionProperty($connector, 'cmd');
2527
$ref->setAccessible(true);
2628

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

35-
$ref = new ReflectionProperty($connector, 'cmd');
37+
$ref = new \ReflectionProperty($connector, 'cmd');
3638
$ref->setAccessible(true);
3739

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

46-
$ref = new ReflectionProperty($connector, 'cmd');
48+
$ref = new \ReflectionProperty($connector, 'cmd');
4749
$ref->setAccessible(true);
4850

4951
$this->assertEquals('exec sshpass -p \'pass\' ssh -vv \'user@host\'', $ref->getValue($connector));

tests/SshSocksConnectorTest.php

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

3+
namespace Clue\Tests\React\SshProxy;
4+
35
use PHPUnit\Framework\TestCase;
46
use Clue\React\SshProxy\SshSocksConnector;
57
use React\Promise\Deferred;
@@ -11,7 +13,7 @@ public function testConstructorAcceptsUri()
1113
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
1214
$connector = new SshSocksConnector('host', $loop);
1315

14-
$ref = new ReflectionProperty($connector, 'cmd');
16+
$ref = new \ReflectionProperty($connector, 'cmd');
1517
$ref->setAccessible(true);
1618

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

25-
$ref = new ReflectionProperty($connector, 'cmd');
27+
$ref = new \ReflectionProperty($connector, 'cmd');
2628
$ref->setAccessible(true);
2729

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

36-
$ref = new ReflectionProperty($connector, 'cmd');
38+
$ref = new \ReflectionProperty($connector, 'cmd');
3739
$ref->setAccessible(true);
3840

3941
$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));
@@ -44,7 +46,7 @@ public function testConstructorAcceptsUriWithPasswordWillPrefixSshCommandWithSsh
4446
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
4547
$connector = new SshSocksConnector('user:pass@host', $loop);
4648

47-
$ref = new ReflectionProperty($connector, 'cmd');
49+
$ref = new \ReflectionProperty($connector, 'cmd');
4850
$ref->setAccessible(true);
4951

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

58-
$ref = new ReflectionProperty($connector, 'cmd');
60+
$ref = new \ReflectionProperty($connector, 'cmd');
5961
$ref->setAccessible(true);
6062

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

69-
$ref = new ReflectionProperty($connector, 'cmd');
71+
$ref = new \ReflectionProperty($connector, 'cmd');
7072
$ref->setAccessible(true);
7173

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

191193
$timer = $this->getMockBuilder('React\EventLoop\TimerInterface')->getMock();
192-
$ref = new ReflectionProperty($connector, 'idleTimer');
194+
$ref = new \ReflectionProperty($connector, 'idleTimer');
193195
$ref->setAccessible(true);
194196
$ref->setValue($connector, $timer);
195197

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

209211
$deferred = new Deferred();
210-
$ref = new ReflectionProperty($connector, 'listen');
212+
$ref = new \ReflectionProperty($connector, 'listen');
211213
$ref->setAccessible(true);
212214
$ref->setValue($connector, $deferred->promise());
213215

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

216-
$deferred->reject(new RuntimeException('foobar'));
218+
$deferred->reject(new \RuntimeException('foobar'));
217219

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

231233
$deferred = new Deferred();
232-
$ref = new ReflectionProperty($connector, 'listen');
234+
$ref = new \ReflectionProperty($connector, 'listen');
233235
$ref->setAccessible(true);
234236
$ref->setValue($connector, $deferred->promise());
235237

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

242-
$deferred->reject(new InvalidArgumentException());
244+
$deferred->reject(new \InvalidArgumentException());
243245
}
244246

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

252254
$deferred = new Deferred();
253-
$ref = new ReflectionProperty($connector, 'listen');
255+
$ref = new \ReflectionProperty($connector, 'listen');
254256
$ref->setAccessible(true);
255257
$ref->setValue($connector, $deferred->promise());
256258

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

260-
$deferred->reject(new InvalidArgumentException());
262+
$deferred->reject(new \InvalidArgumentException());
261263
}
262264

263265
public function testConnectWithSuccessfulSshListenerWillInvokeSocksConnector()
@@ -266,15 +268,15 @@ public function testConnectWithSuccessfulSshListenerWillInvokeSocksConnector()
266268

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

269-
$ref = new ReflectionProperty($connector, 'listen');
271+
$ref = new \ReflectionProperty($connector, 'listen');
270272
$ref->setAccessible(true);
271273
$ref->setValue($connector, \React\Promise\resolve(null));
272274

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

277-
$ref = new ReflectionProperty($connector, 'socks');
279+
$ref = new \ReflectionProperty($connector, 'socks');
278280
$ref->setAccessible(true);
279281
$ref->setValue($connector, $socks);
280282

@@ -292,17 +294,17 @@ public function testConnectCancellationWithSuccessfulSshListenerWillCancelSocksC
292294

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

295-
$ref = new ReflectionProperty($connector, 'listen');
297+
$ref = new \ReflectionProperty($connector, 'listen');
296298
$ref->setAccessible(true);
297299
$ref->setValue($connector, \React\Promise\resolve(null));
298300

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

305-
$ref = new ReflectionProperty($connector, 'socks');
307+
$ref = new \ReflectionProperty($connector, 'socks');
306308
$ref->setAccessible(true);
307309
$ref->setValue($connector, $socks);
308310

@@ -327,21 +329,21 @@ public function testConnectWithSuccessfulSshListenerButFailingSocksConnectorShou
327329

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

330-
$ref = new ReflectionProperty($connector, 'listen');
332+
$ref = new \ReflectionProperty($connector, 'listen');
331333
$ref->setAccessible(true);
332334
$ref->setValue($connector, \React\Promise\resolve(null));
333335

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

338-
$ref = new ReflectionProperty($connector, 'socks');
340+
$ref = new \ReflectionProperty($connector, 'socks');
339341
$ref->setAccessible(true);
340342
$ref->setValue($connector, $socks);
341343

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

344-
$deferred->reject(new RuntimeException('Connection failed'));
346+
$deferred->reject(new \RuntimeException('Connection failed'));
345347

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

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

359-
$ref = new ReflectionProperty($connector, 'listen');
361+
$ref = new \ReflectionProperty($connector, 'listen');
360362
$ref->setAccessible(true);
361363
$ref->setValue($connector, \React\Promise\resolve(null));
362364

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

370-
$ref = new ReflectionProperty($connector, 'socks');
372+
$ref = new \ReflectionProperty($connector, 'socks');
371373
$ref->setAccessible(true);
372374
$ref->setValue($connector, $socks);
373375

@@ -383,7 +385,7 @@ public function testConnectWithSuccessfulSshListenerAndSuccessfulSocksConnectorW
383385

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

386-
$ref = new ReflectionProperty($connector, 'listen');
388+
$ref = new \ReflectionProperty($connector, 'listen');
387389
$ref->setAccessible(true);
388390
$ref->setValue($connector, \React\Promise\resolve(null));
389391

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

397-
$ref = new ReflectionProperty($connector, 'socks');
399+
$ref = new \ReflectionProperty($connector, 'socks');
398400
$ref->setAccessible(true);
399401
$ref->setValue($connector, $socks);
400402

0 commit comments

Comments
 (0)