forked from phpro/http-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormUrlencodedEncoderTest.php
More file actions
45 lines (35 loc) · 1.54 KB
/
FormUrlencodedEncoderTest.php
File metadata and controls
45 lines (35 loc) · 1.54 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
<?php
declare(strict_types=1);
namespace Phpro\HttpTools\Tests\Unit\Encoding\FormUrlencoded;
use Phpro\HttpTools\Encoding\FormUrlencoded\FormUrlencodedEncoder;
use Phpro\HttpTools\Test\UseHttpFactories;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
final class FormUrlencodedEncoderTest extends TestCase
{
use UseHttpFactories;
#[Test]
public function it_can_encode_array_to_url_encoded(): void
{
$data = ['hello' => 'world'];
$encoder = FormUrlencodedEncoder::createWithAutodiscoveredPsrFactories();
$request = $this->createRequest('POST', '/hello');
$actual = $encoder($request, $data);
self::assertSame($request->getMethod(), $actual->getMethod());
self::assertSame($request->getUri(), $actual->getUri());
self::assertSame('hello=world', (string) $actual->getBody());
self::assertSame(['application/x-www-form-urlencoded'], $actual->getHeader('Content-Type'));
}
#[Test]
public function it_can_encode_null_to_empty_body(): void
{
$data = null;
$encoder = FormUrlencodedEncoder::createWithAutodiscoveredPsrFactories();
$request = $this->createRequest('POST', '/hello');
$actual = $encoder($request, $data);
self::assertSame($request->getMethod(), $actual->getMethod());
self::assertSame($request->getUri(), $actual->getUri());
self::assertSame('', (string) $actual->getBody());
self::assertSame(['application/x-www-form-urlencoded'], $actual->getHeader('Content-Type'));
}
}