Remove side-effect from Net/SFTP/Stream.php.

This commit is contained in:
Andreas Fischer 2014-06-27 14:22:47 +02:00
parent d25d115747
commit 970c55d6cc
2 changed files with 8 additions and 20 deletions

View File

@ -138,8 +138,7 @@ class Net_SFTP_Stream
if (in_array($protocol, stream_get_wrappers(), true)) { if (in_array($protocol, stream_get_wrappers(), true)) {
return false; return false;
} }
$class = function_exists('get_called_class') ? get_called_class() : __CLASS__; return stream_wrapper_register($protocol, get_called_class());
return stream_wrapper_register($protocol, $class);
} }
/** /**
@ -798,5 +797,3 @@ class Net_SFTP_Stream
return call_user_func_array(array($this, $name), $arguments); return call_user_func_array(array($this, $name), $arguments);
} }
} }
Net_SFTP_Stream::register();

View File

@ -5,29 +5,20 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License * @license http://www.opensource.org/licenses/mit-license.html MIT License
*/ */
require_once 'Net/SFTP/Stream.php';
class Unit_Net_SFTPStreamTest extends PhpseclibTestCase class Unit_Net_SFTPStreamTest extends PhpseclibTestCase
{ {
protected $protocol = 'sftptest'; public function testRegisterWithoutArgument()
public function setUp()
{ {
parent::setUp(); $this->assertTrue(Net_SFTP_Stream::register());
if (in_array($this->protocol, stream_get_wrappers())) {
stream_wrapper_unregister($this->protocol);
}
}
public function testRegisterFromSideEffect()
{
// Including the file registers 'sftp' as a stream.
$this->assertContains('sftp', stream_get_wrappers()); $this->assertContains('sftp', stream_get_wrappers());
$this->assertTrue(stream_wrapper_unregister('sftp'));
} }
public function testRegisterWithArgument() public function testRegisterWithArgument()
{ {
Net_SFTP_Stream::register($this->protocol); $protocol = 'sftptest';
$this->assertContains($this->protocol, stream_get_wrappers()); $this->assertTrue(Net_SFTP_Stream::register($protocol));
$this->assertContains($protocol, stream_get_wrappers());
$this->assertTrue(stream_wrapper_unregister($protocol));
} }
} }