File: SFTPStreamTest.php

package info (click to toggle)
php-phpseclib 2.0.42-1%2Bdeb12u2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,416 kB
  • sloc: php: 11,867; sh: 66; xml: 49; makefile: 25
file content (53 lines) | stat: -rw-r--r-- 1,379 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php

/**
 * @author    Andreas Fischer <bantu@phpbb.com>
 * @copyright 2015 Andreas Fischer
 * @license   http://www.opensource.org/licenses/mit-license.html  MIT License
 */

use phpseclib\Net\SFTP\Stream;

class Functional_Net_SFTPStreamTest extends Functional_Net_SFTPTestCase
{
    public static function setUpBeforeClass(): void
    {
        Stream::register();
        parent::setUpBeforeClass();
    }

    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'));
    }

    /**
     * @group github778
     */
    public function testFilenameWithHash()
    {
        $context = stream_context_create(array(
            'sftp' => array('session' => $this->sftp),
        ));
        $fp = fopen($this->buildUrl('te#st.txt'), 'wb', false, $context);
        fputs($fp, 'zzzz');
        fclose($fp);

        $this->assertTrue(in_array('te#st.txt', $this->sftp->nlist()));
    }

    protected function buildUrl($suffix)
    {
        return sprintf(
            'sftp://via-context/%s/%s',
            $this->sftp->pwd(),
            $suffix
        );
    }
}