Skip to content

Commit 1c940db

Browse files
committed
Update test suite to ensure 100% code coverage
1 parent c94dde4 commit 1c940db

5 files changed

Lines changed: 48 additions & 6 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ jobs:
3535
- run: composer remove react/mysql --dev --no-interaction # do not install react/mysql example on legacy PHP
3636
if: ${{ matrix.php == 5.3 }}
3737
- run: composer install
38-
- run: vendor/bin/phpunit --coverage-text ${{ matrix.php < 7.3 && '-c phpunit.xml.legacy' || '' }}
38+
- run: vendor/bin/phpunit --coverage-text --coverage-clover clover.xml ${{ matrix.php < 7.3 && '-c phpunit.xml.legacy' || '' }}
39+
- name: Check 100% code coverage
40+
shell: php {0}
41+
run: |
42+
<?php
43+
$metrics = simplexml_load_file('clover.xml')->project->metrics;
44+
exit((int) $metrics['statements'] === (int) $metrics['coveredstatements'] ? 0 : 1);
3945
4046
PHPUnit-hhvm:
4147
name: PHPUnit (HHVM)

‎README.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# clue/reactphp-ssh-proxy
22

33
[![CI status](https://github.com/clue/reactphp-ssh-proxy/actions/workflows/ci.yml/badge.svg)](https://github.com/clue/reactphp-ssh-proxy/actions)
4+
[![code coverage](https://img.shields.io/badge/code%20coverage-100%25-success)](#tests)
45
[![installs on Packagist](https://img.shields.io/packagist/dt/clue/reactphp-ssh-proxy?color=blue&label=installs%20on%20Packagist)](https://packagist.org/packages/clue/reactphp-ssh-proxy)
56

67
Async SSH proxy connector and forwarder, tunnel any TCP/IP-based protocol through an SSH server,
@@ -603,6 +604,14 @@ To run the test suite, go to the project root and run:
603604
vendor/bin/phpunit
604605
```
605606

607+
The test suite is set up to always ensure 100% code coverage across all
608+
supported environments. If you have the Xdebug extension installed, you can also
609+
generate a code coverage report locally like this:
610+
611+
```bash
612+
XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-text
613+
```
614+
606615
The test suite contains a number of tests that require an actual SSH proxy server.
607616
These tests will be skipped unless you configure your SSH login credentials to
608617
be able to create some actual test connections. You can assign the `SSH_PROXY`

‎src/SshProcessConnector.php‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,11 @@ public function connect($uri)
8585
$process = Io\processWithoutFds($command);
8686
$process->start($this->loop);
8787

88+
// @codeCoverageIgnoreStart
8889
if ($this->debug) {
89-
echo 'Launched "' . $command . '" with PID ' . $process->getPid() . PHP_EOL; // @codeCoverageIgnore
90+
echo 'Launched "' . $command . '" with PID ' . $process->getPid() . PHP_EOL;
9091
}
92+
// @codeCoverageIgnoreEnd
9193

9294
$deferred = new Deferred(function () use ($process, $uri) {
9395
$process->stdin->close();
@@ -106,9 +108,11 @@ public function connect($uri)
106108
// remember last line for error output in case process exits
107109
$last = $line;
108110

111+
// @codeCoverageIgnoreStart
109112
if ($debug) {
110-
echo \addcslashes($line, "\0..\032") . PHP_EOL; // @codeCoverageIgnore
113+
echo \addcslashes($line, "\0..\032") . PHP_EOL;
111114
}
115+
// @codeCoverageIgnoreEnd
112116

113117
// match everything related to our forwarding channel
114118
// forwarding error will be printed right to stderr
@@ -154,9 +158,12 @@ public function connect($uri)
154158
});
155159

156160
$process->on('exit', function ($code) use ($deferred, $uri, &$last, $debug) {
161+
// @codeCoverageIgnoreStart
157162
if ($debug) {
158-
echo 'Process exit with code ' . $code . PHP_EOL; // @codeCoverageIgnore
163+
echo 'Process exit with code ' . $code . PHP_EOL;
159164
}
165+
// @codeCoverageIgnoreEnd
166+
160167
$deferred->reject(new \RuntimeException(
161168
'Connection to ' . $uri . ' failed because SSH client died (' . $last . ')',
162169
(int) $code

‎src/SshSocksConnector.php‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,11 @@ public function idle()
204204
$listen->cancel();
205205
$listen = null;
206206

207+
// @codeCoverageIgnoreStart
207208
if ($debug) {
208-
echo 'Stopped listening' . PHP_EOL; // @codeCoverageIgnore
209+
echo 'Stopped listening' . PHP_EOL;
209210
}
211+
// @codeCoverageIgnoreEnd
210212
});
211213
}
212214
}
@@ -232,9 +234,11 @@ private function listen()
232234
// Could not request local forwarding.
233235
$last = $line;
234236

237+
// @codeCoverageIgnoreStart
235238
if ($debug) {
236-
echo \addcslashes($line, "\0..\032") . PHP_EOL; // @codeCoverageIgnore
239+
echo \addcslashes($line, "\0..\032") . PHP_EOL;
237240
}
241+
// @codeCoverageIgnoreEnd
238242

239243
// match everything related to our forwarding channel
240244
// forwarding success will only be reported to stderr via debug1 / -v

‎tests/IntegrationSshProcessConnectorTest.php‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,22 @@ public function testConnectWillRejectWithExceptionWhenProcessOutputsEndsWithoutC
5656
Loop::run();
5757
}
5858

59+
public function testConnectWillRejectWithExceptionWhenProcessOutputsEndsAfterChannelMessageWithoutOpenConfirm()
60+
{
61+
$connector = new SshProcessConnector('host');
62+
63+
$ref = new \ReflectionProperty($connector, 'cmd');
64+
if (PHP_VERSION_ID < 80100) {
65+
$ref->setAccessible(true);
66+
}
67+
$ref->setValue($connector, 'echo "debug1: channel 0: new stdio-forward [stdio-forward] (inactive timeout: 0)" >&2; #');
68+
69+
$promise = $connector->connect('example.com:80');
70+
$promise->then(null, $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException')));
71+
72+
Loop::run();
73+
}
74+
5975
public function testConnectCancellationWillRejectWithException()
6076
{
6177
$connector = new SshProcessConnector('host');

0 commit comments

Comments
 (0)