PluginProbe
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more / 2.5.3
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more v2.5.3
3.7.2 3.7.1 3.7.0 3.6.0 3.6.1 3.5.2 trunk 2.0 2.1 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.6.0 2.6.1 All 73 releases
stockpack / vendor / guzzlehttp / guzzle / tests / MessageFormatterTest.php

MessageFormatterTest.php in StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more 2.5.3, at vendor/guzzlehttp/guzzle/tests/MessageFormatterTest.php

94 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace GuzzleHttp\Tests;
3
4 use GuzzleHttp\Exception\RequestException;
5 use GuzzleHttp\MessageFormatter;
6 use GuzzleHttp\Psr7;
7 use GuzzleHttp\Psr7\Request;
8 use GuzzleHttp\Psr7\Response;
9 use PHPUnit\Framework\TestCase;
10
11 /**
12 * @covers GuzzleHttp\MessageFormatter
13 */
14 class MessageFormatterTest extends TestCase
15 {
16 public function testCreatesWithClfByDefault()
17 {
18 $f = new MessageFormatter();
19 self::assertEquals(MessageFormatter::CLF, self::readAttribute($f, 'template'));
20 $f = new MessageFormatter(null);
21 self::assertEquals(MessageFormatter::CLF, self::readAttribute($f, 'template'));
22 }
23
24 public function dateProvider()
25 {
26 return [
27 ['{ts}', '/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}/'],
28 ['{date_iso_8601}', '/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}/'],
29 ['{date_common_log}', '/^\d\d\/[A-Z][a-z]{2}\/[0-9]{4}/']
30 ];
31 }
32
33 /**
34 * @dataProvider dateProvider
35 */
36 public function testFormatsTimestamps($format, $pattern)
37 {
38 $f = new MessageFormatter($format);
39 $request = new Request('GET', '/');
40 $result = $f->format($request);
41 self::assertRegExp($pattern, $result);
42 }
43
44 public function formatProvider()
45 {
46 $request = new Request('PUT', '/', ['x-test' => 'abc'], Psr7\stream_for('foo'));
47 $response = new Response(200, ['X-Baz' => 'Bar'], Psr7\stream_for('baz'));
48 $err = new RequestException('Test', $request, $response);
49
50 return [
51 ['{request}', [$request], Psr7\str($request)],
52 ['{response}', [$request, $response], Psr7\str($response)],
53 ['{request} {response}', [$request, $response], Psr7\str($request) . ' ' . Psr7\str($response)],
54 // Empty response yields no value
55 ['{request} {response}', [$request], Psr7\str($request) . ' '],
56 ['{req_headers}', [$request], "PUT / HTTP/1.1\r\nx-test: abc"],
57 ['{res_headers}', [$request, $response], "HTTP/1.1 200 OK\r\nX-Baz: Bar"],
58 ['{res_headers}', [$request], 'NULL'],
59 ['{req_body}', [$request], 'foo'],
60 ['{res_body}', [$request, $response], 'baz'],
61 ['{res_body}', [$request], 'NULL'],
62 ['{method}', [$request], $request->getMethod()],
63 ['{url}', [$request], $request->getUri()],
64 ['{target}', [$request], $request->getRequestTarget()],
65 ['{req_version}', [$request], $request->getProtocolVersion()],
66 ['{res_version}', [$request, $response], $response->getProtocolVersion()],
67 ['{res_version}', [$request], 'NULL'],
68 ['{host}', [$request], $request->getHeaderLine('Host')],
69 ['{hostname}', [$request, $response], gethostname()],
70 ['{hostname}{hostname}', [$request, $response], gethostname() . gethostname()],
71 ['{code}', [$request, $response], $response->getStatusCode()],
72 ['{code}', [$request], 'NULL'],
73 ['{phrase}', [$request, $response], $response->getReasonPhrase()],
74 ['{phrase}', [$request], 'NULL'],
75 ['{error}', [$request, $response, $err], 'Test'],
76 ['{error}', [$request], 'NULL'],
77 ['{req_header_x-test}', [$request], 'abc'],
78 ['{req_header_x-not}', [$request], ''],
79 ['{res_header_X-Baz}', [$request, $response], 'Bar'],
80 ['{res_header_x-not}', [$request, $response], ''],
81 ['{res_header_X-Baz}', [$request], 'NULL'],
82 ];
83 }
84
85 /**
86 * @dataProvider formatProvider
87 */
88 public function testFormatsMessages($template, $args, $result)
89 {
90 $f = new MessageFormatter($template);
91 self::assertSame((string) $result, call_user_func_array([$f, 'format'], $args));
92 }
93 }
94