Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit c64d4c9

Browse files
samsonasikweierophinney
authored andcommitted
test json pretty print flag
1 parent 978c31b commit c64d4c9

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/ProblemDetailsResponseFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ class ProblemDetailsResponseFactory
146146
/**
147147
* JSON flags to use when generating JSON response payload.
148148
*
149-
* Defaults to JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION
149+
* Defaults to JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION on non-debug mode
150+
* and JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION on debug mode
150151
*
151152
* @var int
152153
*/

test/ProblemDetailsResponseFactoryFactoryTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function testLackOfConfigServiceResultsInFactoryUsingDefaults() : void
7777
$this->assertInstanceOf(ProblemDetailsResponseFactory::class, $factory);
7878
$this->assertAttributeSame(ProblemDetailsResponseFactory::EXCLUDE_THROWABLE_DETAILS, 'isDebug', $factory);
7979
$this->assertAttributeSame(
80-
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION,
80+
JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION,
8181
'jsonFlags',
8282
$factory
8383
);
@@ -86,6 +86,25 @@ public function testLackOfConfigServiceResultsInFactoryUsingDefaults() : void
8686
$this->assertResponseFactoryReturns($response, $factory);
8787
}
8888

89+
public function testUsesPrettyPrintFlagOnEnabledDebugMode() : void
90+
{
91+
$this->container->has('config')->willReturn(true);
92+
$this->container->get('config')->willReturn([
93+
'debug' => true,
94+
]);
95+
$this->container->has(ResponseInterface::class)->willReturn(false);
96+
$this->container->has('Zend\ProblemDetails\StreamFactory')->willReturn(false);
97+
98+
$factoryFactory = new ProblemDetailsResponseFactoryFactory();
99+
$factory = $factoryFactory($this->container->reveal());
100+
101+
$this->assertAttributeSame(
102+
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION,
103+
'jsonFlags',
104+
$factory
105+
);
106+
}
107+
89108
public function testUsesDebugSettingFromConfigWhenPresent() : void
90109
{
91110
$this->container->has('config')->willReturn(true);

0 commit comments

Comments
 (0)