YumlControllerTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 70
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 9 1
A testIndexActionWillRedirectToYuml() 0 21 1
A testIndexActionWillFailOnMalformedResponse() 0 9 1
1
<?php
2
3
namespace DoctrineORMModuleTest\Yuml;
4
5
use DoctrineORMModule\Yuml\YumlController;
6
use PHPUnit\Framework\TestCase;
7
8
/**
9
 * Tests for Yuml redirector controller
10
 *
11
 * @license MIT
12
 * @link    http://www.doctrine-project.org/
13
 * @author  Marco Pivetta <[email protected]>
14
 */
15
class YumlControllerTest extends TestCase
16
{
17
    /**
18
     * @var YumlController
19
     */
20
    protected $controller;
21
22
    /**
23
     * @var \Laminas\Http\Client|\PHPUnit_Framework_MockObject_MockObject
24
     */
25
    protected $httpClient;
26
27
    /**
28
     * @var \Laminas\Mvc\Controller\PluginManager|\PHPUnit_Framework_MockObject_MockObject
29
     */
30
    protected $pluginManager;
31
32
    /**
33
     * {@inheritDoc}
34
     *
35
     * @covers \DoctrineORMModule\Yuml\YumlController::__construct
36
     */
37
    public function setUp() : void
38
    {
39
        $this->httpClient     = $this->createMock(\Laminas\Http\Client::class);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $this->httpClient is correct as $this->createMock(\Laminas\Http\Client::class) (which targets PHPUnit\Framework\TestCase::createMock()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
40
        $this->controller     = new YumlController($this->httpClient);
0 ignored issues
show
Documentation introduced by
$this->httpClient is of type null, but the function expects a object<Laminas\Http\Client>.

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...
41
        $this->pluginManager  = $this->getMockBuilder(\Laminas\Mvc\Controller\PluginManager::class)
0 ignored issues
show
Bug introduced by
The method disableOriginalConstructor cannot be called on $this->getMockBuilder(\L...r\PluginManager::class) (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
42
            ->disableOriginalConstructor()
43
            ->getMock();
44
        $this->controller->setPluginManager($this->pluginManager);
45
    }
46
47
    /**
48
     * @covers \DoctrineORMModule\Yuml\YumlController::indexAction
49
     */
50
    public function testIndexActionWillRedirectToYuml()
51
    {
52
        $response = $this->createMock(\Laminas\Http\Response::class);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $response is correct as $this->createMock(\Laminas\Http\Response::class) (which targets PHPUnit\Framework\TestCase::createMock()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
53
        $controllerResponse = $this->createMock(\Laminas\Http\Response::class);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $controllerResponse is correct as $this->createMock(\Laminas\Http\Response::class) (which targets PHPUnit\Framework\TestCase::createMock()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
54
        $redirect = $this->createMock(\Laminas\Mvc\Controller\Plugin\Redirect::class);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $redirect is correct as $this->createMock(\Lamin...Plugin\Redirect::class) (which targets PHPUnit\Framework\TestCase::createMock()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
55
        $this->httpClient->expects($this->any())->method('send')->will($this->returnValue($response));
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Laminas\Http\Client>.

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...
Bug introduced by
The method any() does not seem to exist on object<DoctrineORMModule...uml\YumlControllerTest>.

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...
Bug introduced by
The method returnValue() does not seem to exist on object<DoctrineORMModule...uml\YumlControllerTest>.

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...
56
        $response->expects($this->any())->method('isSuccess')->will($this->returnValue(true));
0 ignored issues
show
Bug introduced by
The method any() does not seem to exist on object<DoctrineORMModule...uml\YumlControllerTest>.

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...
Bug introduced by
The method expects cannot be called on $response (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
Bug introduced by
The method returnValue() does not seem to exist on object<DoctrineORMModule...uml\YumlControllerTest>.

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...
57
        $response->expects($this->any())->method('getBody')->will($this->returnValue('short-url'));
0 ignored issues
show
Bug introduced by
The method any() does not seem to exist on object<DoctrineORMModule...uml\YumlControllerTest>.

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...
Bug introduced by
The method expects cannot be called on $response (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
Bug introduced by
The method returnValue() does not seem to exist on object<DoctrineORMModule...uml\YumlControllerTest>.

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...
58
        $this
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Laminas\Mvc\Controller\PluginManager>.

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...
59
            ->pluginManager
60
            ->expects($this->any())
0 ignored issues
show
Bug introduced by
The method any() does not seem to exist on object<DoctrineORMModule...uml\YumlControllerTest>.

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...
61
            ->method('get')->with('redirect')
62
            ->will($this->returnValue($redirect));
0 ignored issues
show
Bug introduced by
The method returnValue() does not seem to exist on object<DoctrineORMModule...uml\YumlControllerTest>.

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...
63
        $redirect
0 ignored issues
show
Bug introduced by
The method expects cannot be called on $redirect (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
64
            ->expects($this->any())
0 ignored issues
show
Bug introduced by
The method any() does not seem to exist on object<DoctrineORMModule...uml\YumlControllerTest>.

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...
65
            ->method('toUrl')
66
            ->with('https://yuml.me/short-url')
67
            ->will($this->returnValue($controllerResponse));
0 ignored issues
show
Bug introduced by
The method returnValue() does not seem to exist on object<DoctrineORMModule...uml\YumlControllerTest>.

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...
68
69
        $this->assertSame($controllerResponse, $this->controller->indexAction());
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<DoctrineORMModule...uml\YumlControllerTest>.

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...
70
    }
71
72
    /**
73
     * @covers \DoctrineORMModule\Yuml\YumlController::indexAction
74
     */
75
    public function testIndexActionWillFailOnMalformedResponse()
76
    {
77
        $response = $this->createMock(\Laminas\Http\Response::class);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $response is correct as $this->createMock(\Laminas\Http\Response::class) (which targets PHPUnit\Framework\TestCase::createMock()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
78
        $this->httpClient->expects($this->any())->method('send')->will($this->returnValue($response));
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Laminas\Http\Client>.

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...
Bug introduced by
The method any() does not seem to exist on object<DoctrineORMModule...uml\YumlControllerTest>.

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...
Bug introduced by
The method returnValue() does not seem to exist on object<DoctrineORMModule...uml\YumlControllerTest>.

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...
79
        $response->expects($this->any())->method('isSuccess')->will($this->returnValue(false));
0 ignored issues
show
Bug introduced by
The method any() does not seem to exist on object<DoctrineORMModule...uml\YumlControllerTest>.

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...
Bug introduced by
The method expects cannot be called on $response (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
Bug introduced by
The method returnValue() does not seem to exist on object<DoctrineORMModule...uml\YumlControllerTest>.

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...
80
81
        $this->expectException(\UnexpectedValueException::class);
0 ignored issues
show
Bug introduced by
The method expectException() does not seem to exist on object<DoctrineORMModule...uml\YumlControllerTest>.

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...
82
        $this->controller->indexAction();
83
    }
84
}
85