Completed
Push — master ( 491c8d...4d0412 )
by Gianluca
10s
created

testIndexActionWillRedirectToYuml()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 1
eloc 21
nc 1
nop 0
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace DoctrineORMModuleTest\Yuml;
21
22
use DoctrineORMModule\Yuml\YumlController;
23
24
/**
25
 * Tests for Yuml redirector controller
26
 *
27
 * @license MIT
28
 * @link    http://www.doctrine-project.org/
29
 * @author  Marco Pivetta <[email protected]>
30
 */
31
class YumlControllerTest extends \PHPUnit_Framework_TestCase
32
{
33
    /**
34
     * @var YumlController
35
     */
36
    protected $controller;
37
38
    /**
39
     * @var \Zend\Http\Client|\PHPUnit_Framework_MockObject_MockObject
40
     */
41
    protected $httpClient;
42
43
    /**
44
     * @var \Zend\Mvc\Controller\PluginManager|\PHPUnit_Framework_MockObject_MockObject
45
     */
46
    protected $pluginManager;
47
48
    /**
49
     * {@inheritDoc}
50
     *
51
     * @covers \DoctrineORMModule\Yuml\YumlController::__construct
52
     */
53
    public function setUp()
54
    {
55
        $this->httpClient     = $this->getMockBuilder('Zend\\Http\\Client')
56
            ->getMock();
57
        $this->controller     = new YumlController($this->httpClient);
58
        $this->pluginManager  = $this->getMockBuilder('Zend\\Mvc\\Controller\\PluginManager')
59
            ->disableOriginalConstructor()
60
            ->getMock();
61
        $this->controller->setPluginManager($this->pluginManager);
62
    }
63
64
    /**
65
     * @covers \DoctrineORMModule\Yuml\YumlController::indexAction
66
     */
67
    public function testIndexActionWillRedirectToYuml()
68
    {
69
        $response = $this->getMockBuilder('Zend\\Http\\Response')
70
            ->getMock();
71
        $controllerResponse = $this->getMockBuilder('Zend\\Http\\Response')
72
            ->getMock();
73
        $redirect = $this->getMockBuilder('Zend\\Mvc\\Controller\\Plugin\\Redirect')
74
            ->getMock();
75
        $this->httpClient->expects($this->any())->method('send')->will($this->returnValue($response));
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Zend\Http\Client.

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
        $response->expects($this->any())->method('isSuccess')->will($this->returnValue(true));
77
        $response->expects($this->any())->method('getBody')->will($this->returnValue('short-url'));
78
        $this
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Zend\Mvc\Controller\PluginManager.

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...
79
            ->pluginManager
80
            ->expects($this->any())
81
            ->method('get')->with('redirect')
82
            ->will($this->returnValue($redirect));
83
        $redirect
84
            ->expects($this->any())
85
            ->method('toUrl')
86
            ->with('http://yuml.me/short-url')
87
            ->will($this->returnValue($controllerResponse));
88
89
        $this->assertSame($controllerResponse, $this->controller->indexAction());
90
    }
91
92
    /**
93
     * @covers \DoctrineORMModule\Yuml\YumlController::indexAction
94
     */
95
    public function testIndexActionWillFailOnMalformedResponse()
96
    {
97
        $response = $this->getMockBuilder('Zend\\Http\\Response')
98
            ->getMock();
99
        $this->httpClient->expects($this->any())->method('send')->will($this->returnValue($response));
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Zend\Http\Client.

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...
100
        $response->expects($this->any())->method('isSuccess')->will($this->returnValue(false));
101
102
        $this->expectException('UnexpectedValueException');
103
        $this->controller->indexAction();
104
    }
105
}
106