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

RouterTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Tests\Ds\Router;
4
5
use Ds\Router\Interfaces\AdaptorInterface;
6
use Ds\Router\Interfaces\RouteCollectionInterface;
7
use Ds\Router\Interfaces\RouterInterface;
8
use Ds\Router\RouteCollection;
9
use Ds\Router\Router;
10
11
/**
12
 * Class RouterTest
13
 * @package Tests\Rs\Router
14
 */
15
class RouterTest extends \PHPUnit_Framework_TestCase
16
{
17
18
    /**
19
     * @var \PHPUnit_Framework_MockObject_MockObject|AdaptorInterface
20
     */
21
    public $adaptor;
22
23
    /**
24
     * @var \PHPUnit_Framework_MockObject_MockObject|RouteCollectionInterface
25
     */
26
    public $collection;
27
28
    /**
29
     * @var RouterInterface
30
     */
31
    public $router;
32
33
34
    /**
35
     *
36
     */
37
    public function setUp()
38
    {
39
        $this->adaptor = $this->getMockBuilder(AdaptorInterface::class)->getMock();
40
        $this->collection = $this->getMockBuilder(RouteCollectionInterface::class)->getMock();
41
42
        $this->router = new Router(
43
            $this->adaptor,
44
            $this->collection
45
        );
46
    }
47
48
    /**
49
     *
50
     */
51 View Code Duplication
    public function testGetRouterResponseFromPath()
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...
52
    {
53
        $method = 'GET';
54
        $path = '/mypath';
55
        $actual = 'my-handler';
56
57
        $this->adaptor->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\AdaptorInterface.

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...
58
            ->method('match')
59
            ->with($this->collection, $method, $path)
60
            ->willReturn($actual);
61
62
        $expected = $this->router->getRouterResponseFromPath($method, $path);
63
        $this->assertEquals($expected, $actual);
64
    }
65
66
    /**
67
     *
68
     */
69 View Code Duplication
    public function testGetRouterResponse()
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...
70
    {
71
        $method = 'GET';
72
        $path = '/path';
73
        $actual = 'my-handler';
74
75
        $this->adaptor->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\AdaptorInterface.

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...
76
            ->method('match')
77
            ->with($this->collection, $method, $path)
78
            ->willReturn($actual);
79
80
        $expected = $this->router->getRouterResponseFromPath($method,$path);
81
        $this->assertEquals($expected, $actual);
82
    }
83
84
85
    /**
86
     *
87
     */
88
    public function testWithAdaptor()
89
    {
90
        $newAdaptor = $this->getMockBuilder(AdaptorInterface::class)->getMock();
91
        $newRouter = $this->router->withAdaptor($newAdaptor);
92
        $this->assertNotSame($this->adaptor, $newRouter->getAdaptor());
93
    }
94
95
    /**
96
     *
97
     */
98
    public function testGetAdaptor()
99
    {
100
        $expected = $this->adaptor;
101
        $actual = $this->router->getAdaptor();
102
        $this->assertEquals($expected, $actual);
103
    }
104
105
    /**
106
     *
107
     */
108
    public function testWithCollection()
109
    {
110
        $routes = $this->getMockBuilder(RouteCollectionInterface::class)->getMock();
111
        $this->router = $this->router->withCollection($routes);
112
113
        $this->assertSame(
114
            $routes,
115
            Helpers\Reflection::getProperty(Router::class, 'collection', $this->router)
116
        );
117
    }
118
119
    /**
120
     *
121
     */
122
    public function testGetCollection()
123
    {
124
        $expected = $this->collection;
125
        $actual = $this->router->getCollection();
126
        $this->assertEquals($expected, $actual);
127
    }
128
129
    /**
130
     *
131
     */
132
    public function testGetCollectionCached()
133
    {
134
        $this->adaptor->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\AdaptorInterface.

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...
135
            ->method('isCached')
136
            ->willReturn(true);
137
138
        $this->adaptor->expects($this->once())
139
            ->method('getCachedRoutes')
140
            ->willReturn($this->collection);
141
142
        $collection = $this->router->getCollection();
143
        $this->assertSame($this->collection, $collection);
144
    }
145
146
147
    /**
148
     *
149
     */
150
    public function testMergeCollection()
151
    {
152
        $collection = new RouteCollection();
153
154
        $this->collection->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\RouteCollectionInterface.

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...
155
            ->method('mergeCollection')
156
            ->with($this->equalTo($collection))
157
            ->willReturn($collection);
158
159
        $newCollection = $this->router->mergeCollection($collection);
160
        $this->assertNotSame($this->collection, $newCollection);
161
    }
162
163
    /**
164
     *
165
     */
166
    public function testIsCached()
167
    {
168
        $this->adaptor->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\AdaptorInterface.

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...
169
            ->method('isCached')
170
            ->willReturn(true);
171
        $this->router->isCached();
172
    }
173
}
174