Skip to content

Commit efd041f

Browse files
committed
Fix bug in toString function
1 parent cfc71d8 commit efd041f

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/Data/MediaType.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ public function toString(): string
6161
{
6262
$value = $this->name;
6363
if (\count($this->parameters) > 0) {
64-
$value .= ';' . \implode(';', $this->parameters);
64+
$params = [];
65+
foreach ($this->parameters as $key => $paramValue) {
66+
$params[] = $key . '=' . $paramValue;
67+
}
68+
$value .= ';' . \implode(';', $params);
6569
}
6670
return $value;
6771
}

tests/Data/MediaTypeTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace HttpAccept\Tests\Data;
44

5+
use Generator;
56
use HttpAccept\Utility\Parser;
67
use PHPUnit\Framework\TestCase;
78

@@ -23,4 +24,18 @@ public function test_parameter_case_insensitive(): void
2324

2425
$this->assertTrue($types[0]->hasParamater('Q'));
2526
}
27+
28+
/**
29+
* @dataProvider toStringDataProvider
30+
*/
31+
public function test_to_string(string $source, string $expected): void
32+
{
33+
$types = (new Parser())->parse($source);
34+
$this->assertSame($expected, $types[0]->toString());
35+
}
36+
37+
public function toStringDataProvider(): Generator
38+
{
39+
yield['*;version=1.0', '*;version=1.0'];
40+
}
2641
}

0 commit comments

Comments
 (0)