|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Http\HttplugBundle\Tests\Unit\Collector; |
|
4
|
|
|
|
|
5
|
|
|
use GuzzleHttp\Psr7\Request; |
|
6
|
|
|
use GuzzleHttp\Psr7\Response; |
|
7
|
|
|
use Http\Client\Exception\HttpException; |
|
8
|
|
|
use Http\Client\Exception\TransferException; |
|
9
|
|
|
use Http\HttplugBundle\Collector\Formatter; |
|
10
|
|
|
use Http\Message\Formatter as MessageFormatter; |
|
11
|
|
|
use Http\Message\Formatter\CurlCommandFormatter; |
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
|
13
|
|
|
|
|
14
|
|
|
class FormatterTest extends TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var MessageFormatter|\PHPUnit_Framework_MockObject_MockObject |
|
18
|
|
|
*/ |
|
19
|
|
|
private $formatter; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var CurlCommandFormatter|\PHPUnit_Framework_MockObject_MockObject |
|
23
|
|
|
*/ |
|
24
|
|
|
private $curlFormatter; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var Formatter |
|
28
|
|
|
*/ |
|
29
|
|
|
private $subject; |
|
30
|
|
|
|
|
31
|
|
|
public function setUp() |
|
32
|
|
|
{ |
|
33
|
|
|
$this->formatter = $this->getMockBuilder(MessageFormatter::class)->getMock(); |
|
34
|
|
|
$this->curlFormatter = $this->getMockBuilder(CurlCommandFormatter::class)->getMock(); |
|
35
|
|
|
|
|
36
|
|
|
$this->subject = new Formatter($this->formatter, $this->curlFormatter); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testFormatRequest() |
|
40
|
|
|
{ |
|
41
|
|
|
$request = new Request('GET', '/'); |
|
42
|
|
|
|
|
43
|
|
|
$this->formatter |
|
|
|
|
|
|
44
|
|
|
->expects($this->once()) |
|
45
|
|
|
->method('formatRequest') |
|
46
|
|
|
->with($this->identicalTo($request)) |
|
47
|
|
|
; |
|
48
|
|
|
|
|
49
|
|
|
$this->subject->formatRequest($request); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testFormatResponse() |
|
53
|
|
|
{ |
|
54
|
|
|
$response = new Response(); |
|
55
|
|
|
|
|
56
|
|
|
$this->formatter |
|
|
|
|
|
|
57
|
|
|
->expects($this->once()) |
|
58
|
|
|
->method('formatResponse') |
|
59
|
|
|
->with($this->identicalTo($response)) |
|
60
|
|
|
; |
|
61
|
|
|
|
|
62
|
|
|
$this->subject->formatResponse($response); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testFormatHttpException() |
|
66
|
|
|
{ |
|
67
|
|
|
$request = new Request('GET', '/'); |
|
68
|
|
|
$response = new Response(); |
|
69
|
|
|
$exception = new HttpException('', $request, $response); |
|
70
|
|
|
|
|
71
|
|
|
$this->formatter |
|
|
|
|
|
|
72
|
|
|
->expects($this->once()) |
|
73
|
|
|
->method('formatResponse') |
|
74
|
|
|
->with($this->identicalTo($response)) |
|
75
|
|
|
->willReturn('FormattedException') |
|
76
|
|
|
; |
|
77
|
|
|
|
|
78
|
|
|
$this->assertEquals('FormattedException', $this->subject->formatException($exception)); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function testFormatTransferException() |
|
82
|
|
|
{ |
|
83
|
|
|
$exception = new TransferException('ExceptionMessage'); |
|
84
|
|
|
|
|
85
|
|
|
$this->assertEquals('Transfer error: ExceptionMessage', $this->subject->formatException($exception)); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function testFormatException() |
|
89
|
|
|
{ |
|
90
|
|
|
$exception = new \RuntimeException('Unexpected error'); |
|
91
|
|
|
$this->assertEquals('Unexpected exception of type "RuntimeException": Unexpected error', $this->subject->formatException($exception)); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function testFormatAsCurlCommand() |
|
95
|
|
|
{ |
|
96
|
|
|
$request = new Request('GET', '/'); |
|
97
|
|
|
|
|
98
|
|
|
$this->curlFormatter |
|
|
|
|
|
|
99
|
|
|
->expects($this->once()) |
|
100
|
|
|
->method('formatRequest') |
|
101
|
|
|
->with($this->identicalTo($request)) |
|
102
|
|
|
->willReturn('curl -L http://example.com') |
|
103
|
|
|
; |
|
104
|
|
|
|
|
105
|
|
|
$this->assertEquals('curl -L http://example.com', $this->subject->formatAsCurlCommand($request)); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
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.