|
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); |
|
|
|
|
|
|
40
|
|
|
$this->controller = new YumlController($this->httpClient); |
|
|
|
|
|
|
41
|
|
|
$this->pluginManager = $this->getMockBuilder(\Laminas\Mvc\Controller\PluginManager::class) |
|
|
|
|
|
|
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); |
|
|
|
|
|
|
53
|
|
|
$controllerResponse = $this->createMock(\Laminas\Http\Response::class); |
|
|
|
|
|
|
54
|
|
|
$redirect = $this->createMock(\Laminas\Mvc\Controller\Plugin\Redirect::class); |
|
|
|
|
|
|
55
|
|
|
$this->httpClient->expects($this->any())->method('send')->will($this->returnValue($response)); |
|
|
|
|
|
|
56
|
|
|
$response->expects($this->any())->method('isSuccess')->will($this->returnValue(true)); |
|
|
|
|
|
|
57
|
|
|
$response->expects($this->any())->method('getBody')->will($this->returnValue('short-url')); |
|
|
|
|
|
|
58
|
|
|
$this |
|
|
|
|
|
|
59
|
|
|
->pluginManager |
|
60
|
|
|
->expects($this->any()) |
|
|
|
|
|
|
61
|
|
|
->method('get')->with('redirect') |
|
62
|
|
|
->will($this->returnValue($redirect)); |
|
|
|
|
|
|
63
|
|
|
$redirect |
|
|
|
|
|
|
64
|
|
|
->expects($this->any()) |
|
|
|
|
|
|
65
|
|
|
->method('toUrl') |
|
66
|
|
|
->with('https://yuml.me/short-url') |
|
67
|
|
|
->will($this->returnValue($controllerResponse)); |
|
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
$this->assertSame($controllerResponse, $this->controller->indexAction()); |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @covers \DoctrineORMModule\Yuml\YumlController::indexAction |
|
74
|
|
|
*/ |
|
75
|
|
|
public function testIndexActionWillFailOnMalformedResponse() |
|
76
|
|
|
{ |
|
77
|
|
|
$response = $this->createMock(\Laminas\Http\Response::class); |
|
|
|
|
|
|
78
|
|
|
$this->httpClient->expects($this->any())->method('send')->will($this->returnValue($response)); |
|
|
|
|
|
|
79
|
|
|
$response->expects($this->any())->method('isSuccess')->will($this->returnValue(false)); |
|
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
$this->expectException(\UnexpectedValueException::class); |
|
|
|
|
|
|
82
|
|
|
$this->controller->indexAction(); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
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.