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->createMock(\Zend\Http\Client::class); |
56
|
|
|
$this->controller = new YumlController($this->httpClient); |
57
|
|
|
$this->pluginManager = $this->getMockBuilder(\Zend\Mvc\Controller\PluginManager::class) |
58
|
|
|
->disableOriginalConstructor() |
59
|
|
|
->getMock(); |
60
|
|
|
$this->controller->setPluginManager($this->pluginManager); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @covers \DoctrineORMModule\Yuml\YumlController::indexAction |
65
|
|
|
*/ |
66
|
|
|
public function testIndexActionWillRedirectToYuml() |
67
|
|
|
{ |
68
|
|
|
$response = $this->createMock(\Zend\Http\Response::class); |
69
|
|
|
$controllerResponse = $this->createMock(\Zend\Http\Response::class); |
70
|
|
|
$redirect = $this->createMock(\Zend\Mvc\Controller\Plugin\Redirect::class); |
71
|
|
|
$this->httpClient->expects($this->any())->method('send')->will($this->returnValue($response)); |
|
|
|
|
72
|
|
|
$response->expects($this->any())->method('isSuccess')->will($this->returnValue(true)); |
73
|
|
|
$response->expects($this->any())->method('getBody')->will($this->returnValue('short-url')); |
74
|
|
|
$this |
|
|
|
|
75
|
|
|
->pluginManager |
76
|
|
|
->expects($this->any()) |
77
|
|
|
->method('get')->with('redirect') |
78
|
|
|
->will($this->returnValue($redirect)); |
79
|
|
|
$redirect |
80
|
|
|
->expects($this->any()) |
81
|
|
|
->method('toUrl') |
82
|
|
|
->with('http://yuml.me/short-url') |
83
|
|
|
->will($this->returnValue($controllerResponse)); |
84
|
|
|
|
85
|
|
|
$this->assertSame($controllerResponse, $this->controller->indexAction()); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @covers \DoctrineORMModule\Yuml\YumlController::indexAction |
90
|
|
|
*/ |
91
|
|
|
public function testIndexActionWillFailOnMalformedResponse() |
92
|
|
|
{ |
93
|
|
|
$response = $this->createMock(\Zend\Http\Response::class); |
94
|
|
|
$this->httpClient->expects($this->any())->method('send')->will($this->returnValue($response)); |
|
|
|
|
95
|
|
|
$response->expects($this->any())->method('isSuccess')->will($this->returnValue(false)); |
96
|
|
|
|
97
|
|
|
$this->expectException(\UnexpectedValueException::class); |
98
|
|
|
$this->controller->indexAction(); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
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:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: