From 9b05ac1700a04747190f9ffc5b594a453c8c0009 Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Fri, 8 May 2020 11:49:59 +0200 Subject: [PATCH 1/2] Clean up test suite --- composer.json | 3 ++ phpunit.xml.dist | 7 +-- tests/FunctionalSshProcessConnectorTest.php | 2 + tests/FunctionalSshSocksConnectorTest.php | 2 + tests/IntegrationSshProcessConnectorTest.php | 10 ++-- tests/Io/LineSeparatedReaderTest.php | 2 +- tests/SshProcessConnectorTest.php | 10 ++-- tests/SshSocksConnectorTest.php | 52 ++++++++++---------- 8 files changed, 48 insertions(+), 40 deletions(-) diff --git a/composer.json b/composer.json index 56aea14..8336e47 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5dc68da..ff08621 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,11 +1,6 @@ - + ./tests/ diff --git a/tests/FunctionalSshProcessConnectorTest.php b/tests/FunctionalSshProcessConnectorTest.php index 37d19af..67bf39d 100644 --- a/tests/FunctionalSshProcessConnectorTest.php +++ b/tests/FunctionalSshProcessConnectorTest.php @@ -1,5 +1,7 @@ setAccessible(true); $ref->setValue($connector, 'echo "debug2: channel 0: open confirm rwindow 2097152 rmax 32768" >&2; #'); @@ -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; #'); @@ -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; #'); @@ -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 #'); diff --git a/tests/Io/LineSeparatedReaderTest.php b/tests/Io/LineSeparatedReaderTest.php index 4e819a0..2eb64cc 100644 --- a/tests/Io/LineSeparatedReaderTest.php +++ b/tests/Io/LineSeparatedReaderTest.php @@ -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()); diff --git a/tests/SshProcessConnectorTest.php b/tests/SshProcessConnectorTest.php index 666ae6a..ef1acf7 100644 --- a/tests/SshProcessConnectorTest.php +++ b/tests/SshProcessConnectorTest.php @@ -1,5 +1,7 @@ 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)); @@ -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)); @@ -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)); @@ -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)); diff --git a/tests/SshSocksConnectorTest.php b/tests/SshSocksConnectorTest.php index 7e79f5a..19d082c 100644 --- a/tests/SshSocksConnectorTest.php +++ b/tests/SshSocksConnectorTest.php @@ -1,5 +1,7 @@ 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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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); @@ -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) { @@ -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()); @@ -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() @@ -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() @@ -266,7 +268,7 @@ 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)); @@ -274,7 +276,7 @@ public function testConnectWithSuccessfulSshListenerWillInvokeSocksConnector() $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); @@ -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); @@ -327,7 +329,7 @@ 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)); @@ -335,13 +337,13 @@ public function testConnectWithSuccessfulSshListenerButFailingSocksConnectorShou $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) { @@ -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)); @@ -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); @@ -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)); @@ -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); From ab13365cf6b089d7a588dde1fa2f07d82f0f1e6a Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Fri, 8 May 2020 11:49:59 +0200 Subject: [PATCH 2/2] Add .gitattributes to exclude dev files from export --- .gitattributes | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..0925d33 --- /dev/null +++ b/.gitattributes @@ -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