1
0
mirror of https://github.com/danog/tgseclib.git synced 2024-11-27 04:34:45 +01:00

Add SFTPStreamTest::testFopenFcloseCreatesFile()

This commit is contained in:
Andreas Fischer 2015-06-25 00:15:19 +02:00
parent 6789b945d0
commit 01f547ba17
3 changed files with 73 additions and 26 deletions

View File

@ -8,11 +8,8 @@
require_once 'Crypt/Base.php';
class Functional_Net_SFTPLargeFileTest extends PhpseclibFunctionalTestCase
class Functional_Net_SFTPLargeFileTest extends Functional_Net_SFTPTestCase
{
protected $sftp;
protected $scratchDir;
static public function setUpBeforeClass()
{
if (!extension_loaded('mcrypt') && !extension_loaded('openssl')) {
@ -21,28 +18,6 @@ class Functional_Net_SFTPLargeFileTest extends PhpseclibFunctionalTestCase
parent::setUpBeforeClass();
}
public function setUp()
{
$this->scratchDir = uniqid('phpseclib-sftp-large-scratch-');
$this->sftp = new Net_SFTP($this->getEnv('SSH_HOSTNAME'));
$this->assertTrue($this->sftp->login(
$this->getEnv('SSH_USERNAME'),
$this->getEnv('SSH_PASSWORD')
));
$this->assertTrue($this->sftp->mkdir($this->scratchDir));
$this->assertTrue($this->sftp->chdir($this->scratchDir));
}
public function tearDown()
{
if ($this->sftp) {
$this->sftp->chdir($this->getEnv('SSH_HOME'));
$this->sftp->delete($this->scratchDir);
}
parent::tearDown();
}
/**
* @group github298
* @group github455

View File

@ -0,0 +1,33 @@
<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright 2015 Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
// Registers sftp:// as a side effect.
require_once 'Net/SFTP/Stream.php';
class Functional_Net_SFTPStreamTest extends Functional_Net_SFTPTestCase
{
public function testFopenFcloseCreatesFile()
{
$context = stream_context_create(array(
'sftp' => array('session' => $this->sftp),
));
$fp = fopen($this->buildUrl('fooo.txt'), 'wb', false, $context);
$this->assertTrue(is_resource($fp));
fclose($fp);
$this->assertSame(0, $this->sftp->size('fooo.txt'));
}
protected function buildUrl($suffix)
{
return sprintf(
'sftp://via-context/%s/%s',
$this->sftp->pwd(),
$suffix
);
}
}

View File

@ -0,0 +1,39 @@
<?php
/**
* @author Andreas Fischer <bantu@phpbb.com>
* @copyright 2015 Andreas Fischer
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
/**
* This class provides each test method with a new and empty $this->scratchDir.
*/
abstract class Functional_Net_SFTPTestCase extends PhpseclibFunctionalTestCase
{
protected $sftp;
protected $scratchDir;
public function setUp()
{
parent::setUp();
$this->scratchDir = uniqid('phpseclib-sftp-scratch-');
$this->sftp = new Net_SFTP($this->getEnv('SSH_HOSTNAME'));
$this->assertTrue($this->sftp->login(
$this->getEnv('SSH_USERNAME'),
$this->getEnv('SSH_PASSWORD')
));
$this->assertTrue($this->sftp->mkdir($this->scratchDir));
$this->assertTrue($this->sftp->chdir($this->scratchDir));
}
public function tearDown()
{
if ($this->sftp) {
$this->sftp->chdir($this->getEnv('SSH_HOME'));
$this->sftp->delete($this->scratchDir);
}
parent::tearDown();
}
}