forked from phpro/http-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormUrlencodedDecoderTest.php
More file actions
36 lines (28 loc) · 1.08 KB
/
FormUrlencodedDecoderTest.php
File metadata and controls
36 lines (28 loc) · 1.08 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
<?php
declare(strict_types=1);
namespace Phpro\HttpTools\Tests\Unit\Encoding\FormUrlencoded;
use Phpro\HttpTools\Encoding\FormUrlencoded\FormUrlencodedDecoder;
use Phpro\HttpTools\Test\UseHttpFactories;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
final class FormUrlencodedDecoderTest extends TestCase
{
use UseHttpFactories;
#[Test]
public function it_can_decode_form_url_encoded_to_array(): void
{
$decoder = FormUrlencodedDecoder::createWithAutodiscoveredPsrFactories();
$response = $this->createResponse()
->withBody($this->createStream('hello=world&foo=bar'));
$decoded = $decoder($response);
self::assertSame(['hello' => 'world', 'foo' => 'bar'], $decoded);
}
#[Test]
public function it_can_decode_empty_body_to_empty_array(): void
{
$decoder = FormUrlencodedDecoder::createWithAutodiscoveredPsrFactories();
$response = $this->createResponse()->withBody($this->createStream(''));
$decoded = $decoder($response);
self::assertSame([], $decoded);
}
}