Completed
Push — master ( 4895be...67409c )
by Oleg
04:41
created

CompareUrlTest::makeComparativeUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
namespace Malezha\Menu\Tests;
3
4
use Illuminate\Routing\UrlGenerator;
5
use Malezha\Menu\Support\ComparativeUrl;
6
7
class CompareUrlTest extends TestCase
8
{
9
    protected function makeComparativeUrl($currentUrl)
10
    {
11
        $mock = $this->createMock(UrlGenerator::class);
0 ignored issues
show
Bug introduced by
The method createMock() does not seem to exist on object<Malezha\Menu\Tests\CompareUrlTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
12
        $mock->method('current')->willReturn(url($currentUrl));
13
        $mock->method('to')->willReturnCallback('url');
14
15
        return new ComparativeUrl($mock, config('menu.skippedPaths'));
16
    }
17
    
18
    public function testSkipped()
19
    {
20
        $compare = $this->makeComparativeUrl(url('/'));
21
        foreach (config('menu.skippedPaths') as $value) {
22
            $this->assertFalse($compare->isEquals($value));
23
        }
24
    }
25
26
    public function testEquals()
27
    {
28
        $stub = [
29
            'http://username:password@hostname/path?arg=value#anchor',
30
            '//www.example.com/path?googleguy=googley',
31
            'http://usr:[email protected]:81/mypath/myfile.html?a=b&b[]=2&b[]=3#myfragment',
32
            url('/'),
33
            '/',
34
        ];
35
        
36
        foreach ($stub as $value) {
37
            $compare = $this->makeComparativeUrl($value);
38
            $this->assertTrue($compare->isEquals($value));
0 ignored issues
show
Bug introduced by
It seems like $value defined by $value on line 36 can also be of type object<Illuminate\Contracts\Routing\UrlGenerator>; however, Malezha\Menu\Support\ComparativeUrl::isEquals() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
39
        }
40
    }
41
}