diff --git a/tests/Functional/Net/SSH2Test.php b/tests/Functional/Net/SSH2Test.php index 55df076f..8603e13f 100644 --- a/tests/Functional/Net/SSH2Test.php +++ b/tests/Functional/Net/SSH2Test.php @@ -542,4 +542,21 @@ class SSH2Test extends PhpseclibFunctionalTestCase 'Failed asserting that exec channel identifier is maintained as last opened channel.' ); } + + public function testReadingOfClosedChannel() + { + $ssh = $this->getSSH2Login(); + $this->assertSame(0, $ssh->getOpenChannelCount()); + $ssh->enablePTY(); + $ssh->exec('ping -c 3 127.0.0.1; exit'); + $ssh->write("ping 127.0.0.2\n", SSH2::CHANNEL_SHELL); + $ssh->setTimeout(3); + $output = $ssh->read('', SSH2::READ_SIMPLE, SSH2::CHANNEL_SHELL); + $this->assertStringContainsString('PING 127.0.0.2', $output); + $output = $ssh->read('', SSH2::READ_SIMPLE, SSH2::CHANNEL_EXEC); + $this->assertStringContainsString('PING 127.0.0.1', $output); + $this->assertSame(1, $ssh->getOpenChannelCount()); + $ssh->reset(SSH2::CHANNEL_SHELL); + $this->assertSame(0, $ssh->getOpenChannelCount()); + } }