Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
20.00% covered (danger)
20.00%
4 / 20
33.33% covered (danger)
33.33%
2 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_filesystem_helper_realpath_test
20.00% covered (danger)
20.00%
4 / 20
33.33% covered (danger)
33.33%
2 / 6
40.77
0.00% covered (danger)
0.00%
0 / 1
 setUpBeforeClass
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 setUp
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 realpath_resolve_absolute_without_symlinks_data
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 realpath_resolve_relative_without_symlinks_data
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
6
 test_realpath_absolute_without_links
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 test_realpath_relative_without_links
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
2.15
1<?php
2/**
3 *
4 * This file is part of the phpBB Forum Software package.
5 *
6 * @copyright (c) phpBB Limited <https://www.phpbb.com>
7 * @license GNU General Public License, version 2 (GPL-2.0)
8 *
9 * For full copyright and license information, please see
10 * the docs/CREDITS.txt file.
11 *
12 */
13
14use phpbb\filesystem\helper as filesystem_helper;
15
16class phpbb_filesystem_helper_realpath_test extends phpbb_test_case
17{
18    protected static $filesystem_helper_phpbb_own_realpath;
19
20    static public function setUpBeforeClass(): void
21    {
22        parent::setUpBeforeClass();
23
24        self::$filesystem_helper_phpbb_own_realpath = new ReflectionMethod('\phpbb\filesystem\helper', 'phpbb_own_realpath');
25    }
26
27    protected function setUp(): void
28    {
29        parent::setUp();
30    }
31
32    public static function realpath_resolve_absolute_without_symlinks_data()
33    {
34        // Constant data
35        yield [__DIR__, __DIR__];
36        yield [__DIR__ . '/../filesystem/../filesystem', __DIR__];
37        yield [__DIR__ . '/././', __DIR__];
38        yield [__DIR__ . '/non_existent', false];
39
40        yield [__FILE__, __FILE__];
41        yield [__FILE__ . '../', false];
42    }
43
44    public static function realpath_resolve_relative_without_symlinks_data()
45    {
46        if (!function_exists('getcwd'))
47        {
48            yield [];
49        }
50        else
51        {
52            $relative_path = filesystem_helper::make_path_relative(__DIR__, getcwd());
53
54            yield [$relative_path, __DIR__];
55            yield [$relative_path . '../filesystem/../filesystem', __DIR__];
56            yield [$relative_path . '././', __DIR__];
57
58            yield [$relative_path . 'helper_realpath_test.php', __FILE__];
59        }
60    }
61
62    /**
63     * @dataProvider realpath_resolve_absolute_without_symlinks_data
64     */
65    public function test_realpath_absolute_without_links($path, $expected)
66    {
67        $this->assertEquals($expected, self::$filesystem_helper_phpbb_own_realpath->invoke(null, $path));
68    }
69
70    /**
71     * @dataProvider realpath_resolve_relative_without_symlinks_data
72     */
73    public function test_realpath_relative_without_links($path, $expected)
74    {
75        if (!function_exists('getcwd'))
76        {
77            $this->markTestSkipped('phpbb_own_realpath() cannot be tested with relative paths: getcwd is not available.');
78        }
79
80        $this->assertEquals($expected, self::$filesystem_helper_phpbb_own_realpath->invoke(null, $path));
81    }
82}