Skip to content

Commit

Permalink
Fix: add an test for serialize-controlled response creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Strahl committed Sep 17, 2020
1 parent 607bd94 commit 0f7029e
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions tests/ResponseFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,13 @@ public function canUseGivenContext(): void
}

/**
* @param string $changeSerializeTypeTo
* @param string $expectedResult
*
* @test
* @dataProvider dataProviderCanSerializeWithSerializeType
*/
public function canWithSerializeType(): void
public function canSerializeWithSerializeType(string $changeSerializeTypeTo, string $expectedResult): void
{
$this->config
->expects(self::once())
Expand All @@ -201,19 +205,37 @@ public function canWithSerializeType(): void

$responseFactory = new ResponseFactory((new Factory())->getSerializer($this->config), $this->config);
$responseFactory->withContext(SerializationContext::create()->setSerializeNull(true));
$responseFactory = $responseFactory->withSerializeType(Config::SERIALIZE_TYPE_XML);
$responseFactory = $responseFactory->withSerializeType($changeSerializeTypeTo);

$response = $responseFactory->create(new Dummy());

self::assertEquals(
'<?xml version="1.0" encoding="UTF-8"?>
$expectedResult,
$response->getContent()
);
}

/**
* @return array<string, array<int, string>>
* @psalm-return array{with_json: array<int, string>, 'with_xml': array<int, string>}
*/
public function dataProviderCanSerializeWithSerializeType(): array
{
return [
'with_json' => [
Config::SERIALIZE_TYPE_JSON,
'{"amount":12,"text":"Hello World!"}',
],
'with_xml' => [
Config::SERIALIZE_TYPE_XML,
'<?xml version="1.0" encoding="UTF-8"?>
<result>
<amount>12</amount>
<text><![CDATA[Hello World!]]></text>
</result>
',
$response->getContent()
);
],
];
}

/**
Expand Down

0 comments on commit 0f7029e

Please sign in to comment.