Test Failed
Push — master ( 3e96d2...d4b731 )
by Dan
06:30
created

YamlLoaderTest::testLoadFilesNoCache()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
dl 15
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
namespace Tests\Ds\Router\Loaders;
4
5
use Ds\Router\Exceptions\RouterException;
6
use Ds\Router\Interfaces\RouteCollectionInterface;
7
use Ds\Router\Interfaces\RouterInterface;
8
use Ds\Router\Loaders\YamlLoader;
9
use Ds\Router\RouteCollection;
10
11
/**
12
 * Class YamlLoaderTest
13
 * @package Tests\Ds\Router\Loaders
14
 */
15
class YamlLoaderTest extends \PHPUnit_Framework_TestCase
16
{
17
18
    /**
19
     * @var \PHPUnit_Framework_MockObject_MockObject|RouterInterface
20
     */
21
    public $router;
22
23
    /**
24
     * @var YamlLoader
25
     */
26
    public $loader;
27
28
    /**
29
     * @var string
30
     */
31
    public $file;
32
33
    /**
34
     *
35
     */
36
    public function setUp()
37
    {
38
        $this->router = $this->getMockBuilder(RouterInterface::class)->getMock();
39
        $this->loader = new YamlLoader($this->router);
40
        $this->file = __DIR__ . '/Files/FileLoaderRoutes.yml';
41
    }
42
43
    /**
44
     *
45
     */
46 View Code Duplication
    public function testLoadFileNoCacheParse()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
47
    {
48
        $this->setExpectedException(RouterException::class);
49
50
51
        $this->router->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Ds\Router\Interfaces\RouterInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
52
            ->method('isCached')
53
            ->willReturn(false);
54
        $this->loader->loadFile(__DIR__ . '/Files/malformed.yml');
55
    }
56
57
    /**
58
     *
59
     */
60 View Code Duplication
    public function testLoadFileNoCacheNoFile()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
    {
62
        $this->setExpectedException(RouterException::class);
63
64
        $this->router->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Ds\Router\Interfaces\RouterInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
65
            ->method('isCached')
66
            ->willReturn(false);
67
68
        $this->loader->loadFile(__DIR__ . '/RouteFileNone.yml');
69
    }
70
71
    /**
72
     *
73
     */
74 View Code Duplication
    public function testLoadFileNoCache()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
    {
76
        $this->router->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Ds\Router\Interfaces\RouterInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
77
            ->method('isCached')
78
            ->willReturn(false);
79
80
        $collection = $this->loader->loadFile($this->file);
81
        $route = $collection->current();
82
83
        $expected = 'myHandler::myMethod';
84
        $actual = $route->getHandler();
85
86
        $this->assertInstanceOf(RouteCollectionInterface::class, $collection);
87
        $this->assertEquals($expected, $actual);
88
    }
89
90
    /**
91
     *
92
     */
93 View Code Duplication
    public function testLoadFileCache()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
94
    {
95
        $this->router->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Ds\Router\Interfaces\RouterInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
96
            ->method('isCached')
97
            ->willReturn(true);
98
99
        $this->router->expects($this->once())
100
            ->method('getCollection')
101
            ->willReturn(new RouteCollection());
102
103
        $collection = $this->loader->loadFile($this->file);
104
105
        $this->assertInstanceOf(RouteCollection::class, $collection);
106
    }
107
108
    /**
109
     *
110
     */
111 View Code Duplication
    public function testLoadFilesNoCache()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
112
    {
113
        $this->router->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Ds\Router\Interfaces\RouterInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
114
            ->method('isCached')
115
            ->willReturn(false);
116
117
        $this->router->expects($this->any())
118
            ->method('mergeCollection')
119
            ->willReturn($this->router);
120
121
        $this->loader->loadFiles([
122
            $this->file,
123
            __DIR__ . '/Files/FileLoaderRoutesAlt.yml'
124
        ]);
125
    }
126
}
127