From 970c55d6cc96f8f87955a010db3f81d665cbe262 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 27 Jun 2014 14:22:47 +0200 Subject: [PATCH] Remove side-effect from Net/SFTP/Stream.php. --- phpseclib/Net/SFTP/Stream.php | 5 +---- tests/Unit/Net/SFTPStreamTest.php | 23 +++++++---------------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/phpseclib/Net/SFTP/Stream.php b/phpseclib/Net/SFTP/Stream.php index 64126b2d..df9f8325 100644 --- a/phpseclib/Net/SFTP/Stream.php +++ b/phpseclib/Net/SFTP/Stream.php @@ -138,8 +138,7 @@ class Net_SFTP_Stream if (in_array($protocol, stream_get_wrappers(), true)) { return false; } - $class = function_exists('get_called_class') ? get_called_class() : __CLASS__; - return stream_wrapper_register($protocol, $class); + return stream_wrapper_register($protocol, get_called_class()); } /** @@ -798,5 +797,3 @@ class Net_SFTP_Stream return call_user_func_array(array($this, $name), $arguments); } } - -Net_SFTP_Stream::register(); diff --git a/tests/Unit/Net/SFTPStreamTest.php b/tests/Unit/Net/SFTPStreamTest.php index f54f79f8..074988aa 100644 --- a/tests/Unit/Net/SFTPStreamTest.php +++ b/tests/Unit/Net/SFTPStreamTest.php @@ -5,29 +5,20 @@ * @license http://www.opensource.org/licenses/mit-license.html MIT License */ -require_once 'Net/SFTP/Stream.php'; - class Unit_Net_SFTPStreamTest extends PhpseclibTestCase { - protected $protocol = 'sftptest'; - - public function setUp() + public function testRegisterWithoutArgument() { - parent::setUp(); - 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->assertTrue(Net_SFTP_Stream::register()); $this->assertContains('sftp', stream_get_wrappers()); + $this->assertTrue(stream_wrapper_unregister('sftp')); } public function testRegisterWithArgument() { - Net_SFTP_Stream::register($this->protocol); - $this->assertContains($this->protocol, stream_get_wrappers()); + $protocol = 'sftptest'; + $this->assertTrue(Net_SFTP_Stream::register($protocol)); + $this->assertContains($protocol, stream_get_wrappers()); + $this->assertTrue(stream_wrapper_unregister($protocol)); } }