This repository was archived by the owner on Apr 13, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathRequestSerializationHandlerTest.php
More file actions
79 lines (69 loc) · 2.28 KB
/
RequestSerializationHandlerTest.php
File metadata and controls
79 lines (69 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* This file is part of the Elastic OpenAPI PHP code generator.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Elastic\OpenApi\Codegen\Tests\Unit\Connection\Handler;
use PHPUnit\Framework\TestCase;
use Elastic\OpenApi\Codegen\Connection\Handler\RequestSerializationHandler;
use Elastic\OpenApi\Codegen\Serializer\SmartSerializer;
/**
* Unit tests for the request serialization handler.
*
* @package Elastic\OpenApi\Codegen\Test\Unit\Connection\Handler
* @author Aurélien FOUCRET <aurelien.foucret@elastic.co>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
*/
class RequestSerializationHandlerTest extends TestCase
{
/**
* Check data serialization accross various requests of the dataprovider.
*
* @dataProvider requestDataProvider
*/
public function testSerializeRequest($request, $expectedBody)
{
$handler = $this->getHandler();
$this->assertEquals($expectedBody, $handler($request));
}
/**
* @return array
*/
public function requestDataProvider()
{
$data = [
[['http_method' => 'POST', 'body' => ['foo' => 'bar']], '{"foo":"bar"}'],
[['http_method' => 'GET', 'query_params' => ['foo' => 'bar']], null],
[
['http_method' => 'POST', 'body' => ['foo' => 'bar'], 'query_params' => ['foo' => 'bar']],
'{"foo":"bar"}'
],
[
['http_method' => 'POST', 'body' => ['foo1' => 'bar1'], 'query_params' => ['foo2' => 'bar2']],
'{"foo1":"bar1","foo2":"bar2"}'
],
[[], null],
];
return $data;
}
/**
* @return \Elastic\OpenApi\Codegen\Connection\Handler\RequestSerializationHandler
*/
private function getHandler()
{
$handler = function ($request) {
return isset($request['body']) ? $request['body'] : null;
};
$serializer = $this->getSerializer();
return new RequestSerializationHandler($handler, $serializer);
}
/**
* @return \Elastic\OpenApi\Codegen\Serializer\SmartSerializer
*/
private function getSerializer()
{
return new SmartSerializer();
}
}