1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sylius\Bundle\AdminBundle\Tests\Controller; |
13
|
|
|
|
14
|
|
|
use GuzzleHttp\ClientInterface; |
15
|
|
|
use GuzzleHttp\Exception\ConnectException; |
16
|
|
|
use Http\Message\MessageFactory; |
17
|
|
|
use Prophecy\Argument; |
18
|
|
|
use Psr\Http\Message\RequestInterface; |
19
|
|
|
use Psr\Http\Message\ResponseInterface; |
20
|
|
|
use Psr\Http\Message\StreamInterface; |
21
|
|
|
use Sylius\Bundle\AdminBundle\Controller\NotificationController; |
22
|
|
|
use Symfony\Component\HttpFoundation\Request; |
23
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @author Jan Góralski <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
final class NotificationControllerTest extends \PHPUnit_Framework_TestCase |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var ClientInterface |
32
|
|
|
*/ |
33
|
|
|
private $client; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var MessageFactory |
37
|
|
|
*/ |
38
|
|
|
private $messageFactory; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var NotificationController |
42
|
|
|
*/ |
43
|
|
|
private $controller; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var string |
47
|
|
|
*/ |
48
|
|
|
private static $hubUri = 'www.doesnotexist.test.com'; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @test |
52
|
|
|
*/ |
53
|
|
|
public function it_returns_an_empty_json_response_upon_client_exception() |
54
|
|
|
{ |
55
|
|
|
$this->messageFactory->createRequest(Argument::cetera()) |
|
|
|
|
56
|
|
|
->willReturn($this->prophesize(RequestInterface::class)->reveal()) |
57
|
|
|
; |
58
|
|
|
|
59
|
|
|
$this->client->send(Argument::cetera())->willThrow(ConnectException::class); |
|
|
|
|
60
|
|
|
|
61
|
|
|
$emptyResponse = $this->controller->getVersionAction(new Request()); |
62
|
|
|
|
63
|
|
|
$this->assertEquals(JsonResponse::HTTP_NO_CONTENT, $emptyResponse->getStatusCode()); |
64
|
|
|
$this->assertEquals('""', $emptyResponse->getContent()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @test |
69
|
|
|
*/ |
70
|
|
|
public function it_returns_json_response_from_client_on_success() |
71
|
|
|
{ |
72
|
|
|
$content = json_encode(['version' => '9001']); |
73
|
|
|
|
74
|
|
|
$this->messageFactory->createRequest(Argument::cetera()) |
|
|
|
|
75
|
|
|
->willReturn($this->prophesize(RequestInterface::class)->reveal()) |
76
|
|
|
; |
77
|
|
|
|
78
|
|
|
$stream = $this->prophesize(StreamInterface::class); |
79
|
|
|
$stream->getContents()->willReturn($content); |
80
|
|
|
|
81
|
|
|
$externalResponse = $this->prophesize(ResponseInterface::class); |
82
|
|
|
$externalResponse->getBody()->willReturn($stream->reveal()); |
83
|
|
|
|
84
|
|
|
$this->client->send(Argument::cetera())->willReturn($externalResponse->reveal()); |
|
|
|
|
85
|
|
|
|
86
|
|
|
$response = $this->controller->getVersionAction(new Request()); |
87
|
|
|
|
88
|
|
|
$this->assertEquals(JsonResponse::HTTP_OK, $response->getStatusCode()); |
89
|
|
|
$this->assertEquals($content, $response->getContent()); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* {@inheritdoc} |
94
|
|
|
*/ |
95
|
|
|
protected function setUp() |
96
|
|
|
{ |
97
|
|
|
$this->client = $this->prophesize(ClientInterface::class); |
|
|
|
|
98
|
|
|
$this->messageFactory = $this->prophesize(MessageFactory::class); |
|
|
|
|
99
|
|
|
|
100
|
|
|
$this->controller = new NotificationController( |
101
|
|
|
$this->client->reveal(), |
102
|
|
|
$this->messageFactory->reveal(), |
103
|
|
|
self::$hubUri |
104
|
|
|
); |
105
|
|
|
|
106
|
|
|
parent::setUp(); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
This check looks for function calls that miss required arguments.