Completed
Push — develop ( d73a05...7ce957 )
by Mike
07:24
created

tests/unit/phpDocumentor/PathTest.php (2 issues)

mismatching argument types.

Documentation Minor

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * This file is part of phpDocumentor.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @copyright 2010-2018 Mike van Riel<[email protected]>
9
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
10
 * @link      http://phpdoc.org
11
 */
12
13
namespace phpDocumentor;
14
15
use PHPUnit\Framework\TestCase;
16
17
/**
18
 * @coversDefaultClass \phpDocumentor\Path
19
 * @covers ::<private>
20
 */
21
final class PathTest extends TestCase
22
{
23
    /**
24
     * @covers ::__construct
25
     * @covers ::__toString
26
     */
27
    public function testItCanContainALocationOnAStorageService()
28
    {
29
        $path = new Path('/my/Path');
30
31
        $this->assertSame('/my/Path', (string) $path);
32
    }
33
34
    /**
35
     * @covers ::equals
36
     */
37
    public function testItCanCompareItselfToAnotherPath()
38
    {
39
        $subject = new Path('a');
40
        $similar = new Path('a');
41
        $dissimilar = new Path('b');
42
43
        $this->assertTrue($subject->equals($similar));
0 ignored issues
show
$similar is of type object<phpDocumentor\Path>, but the function expects a object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
44
        $this->assertFalse($subject->equals($dissimilar));
0 ignored issues
show
$dissimilar is of type object<phpDocumentor\Path>, but the function expects a object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
45
    }
46
47
    /**
48
     * @covers ::isAbsolutePath
49
     */
50
    public function testItCanCheckWhetherTheGivenPathIsAnAbsolutePath()
51
    {
52
        $this->assertTrue(Path::isAbsolutePath('\\\\my\\absolute\\path'));
53
        $this->assertTrue(Path::isAbsolutePath('/my/absolute/path'));
54
        $this->assertTrue(Path::isAbsolutePath('c:\\my\\absolute\\path'));
55
        $this->assertTrue(Path::isAbsolutePath('http://my/absolute/path'));
56
        $this->assertTrue(Path::isAbsolutePath('//my/absolute/path'));
57
58
        $this->assertFalse(Path::isAbsolutePath('path'));
59
        $this->assertFalse(Path::isAbsolutePath('my/absolute/path'));
60
        $this->assertFalse(Path::isAbsolutePath('./my/absolute/path'));
61
        $this->assertFalse(Path::isAbsolutePath('../my/absolute/path'));
62
    }
63
}
64