|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace DoctrineORMModuleTest\Yuml; |
|
6
|
|
|
|
|
7
|
|
|
use DoctrineORMModule\Yuml\YumlController; |
|
8
|
|
|
use Laminas\Http\Client; |
|
9
|
|
|
use Laminas\Http\Response; |
|
10
|
|
|
use Laminas\Mvc\Controller\Plugin\Redirect; |
|
11
|
|
|
use Laminas\Mvc\Controller\PluginManager; |
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
|
13
|
|
|
use PHPUnit_Framework_MockObject_MockObject; |
|
14
|
|
|
use UnexpectedValueException; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Tests for Yuml redirector controller |
|
18
|
|
|
* |
|
19
|
|
|
* @link http://www.doctrine-project.org/ |
|
20
|
|
|
*/ |
|
21
|
|
|
class YumlControllerTest extends TestCase |
|
22
|
|
|
{ |
|
23
|
|
|
protected YumlController $controller; |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
/** @var Client|PHPUnit_Framework_MockObject_MockObject */ |
|
26
|
|
|
protected $httpClient; |
|
27
|
|
|
|
|
28
|
|
|
/** @var PluginManager|PHPUnit_Framework_MockObject_MockObject */ |
|
29
|
|
|
protected $pluginManager; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* {@inheritDoc} |
|
33
|
|
|
* |
|
34
|
|
|
* @covers \DoctrineORMModule\Yuml\YumlController::__construct |
|
35
|
|
|
*/ |
|
36
|
|
|
protected function setUp() : void |
|
37
|
|
|
{ |
|
38
|
|
|
$this->httpClient = $this->createMock(Client::class); |
|
39
|
|
|
$this->controller = new YumlController($this->httpClient); |
|
40
|
|
|
$this->pluginManager = $this->getMockBuilder(PluginManager::class) |
|
41
|
|
|
->disableOriginalConstructor() |
|
42
|
|
|
->getMock(); |
|
43
|
|
|
$this->controller->setPluginManager($this->pluginManager); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @covers \DoctrineORMModule\Yuml\YumlController::indexAction |
|
48
|
|
|
*/ |
|
49
|
|
|
public function testIndexActionWillRedirectToYuml() : void |
|
50
|
|
|
{ |
|
51
|
|
|
$response = $this->createMock(Response::class); |
|
52
|
|
|
$controllerResponse = $this->createMock(Response::class); |
|
53
|
|
|
$redirect = $this->createMock(Redirect::class); |
|
54
|
|
|
$this->httpClient->expects($this->any())->method('send')->will($this->returnValue($response)); |
|
55
|
|
|
$response->expects($this->any())->method('isSuccess')->will($this->returnValue(true)); |
|
56
|
|
|
$response->expects($this->any())->method('getBody')->will($this->returnValue('short-url')); |
|
57
|
|
|
$this |
|
58
|
|
|
->pluginManager |
|
59
|
|
|
->expects($this->any()) |
|
60
|
|
|
->method('get')->with('redirect') |
|
61
|
|
|
->will($this->returnValue($redirect)); |
|
62
|
|
|
$redirect |
|
63
|
|
|
->expects($this->any()) |
|
64
|
|
|
->method('toUrl') |
|
65
|
|
|
->with('https://yuml.me/short-url') |
|
66
|
|
|
->will($this->returnValue($controllerResponse)); |
|
67
|
|
|
|
|
68
|
|
|
$this->assertSame($controllerResponse, $this->controller->indexAction()); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @covers \DoctrineORMModule\Yuml\YumlController::indexAction |
|
73
|
|
|
*/ |
|
74
|
|
|
public function testIndexActionWillFailOnMalformedResponse() : void |
|
75
|
|
|
{ |
|
76
|
|
|
$response = $this->createMock(Response::class); |
|
77
|
|
|
$this->httpClient->expects($this->any())->method('send')->will($this->returnValue($response)); |
|
78
|
|
|
$response->expects($this->any())->method('isSuccess')->will($this->returnValue(false)); |
|
79
|
|
|
|
|
80
|
|
|
$this->expectException(UnexpectedValueException::class); |
|
81
|
|
|
$this->controller->indexAction(); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|