Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
Preserve trailing zero when json encode
Browse files Browse the repository at this point in the history
  • Loading branch information
VGirol committed Sep 27, 2019
1 parent 557abef commit c64c819
Show file tree
Hide file tree
Showing 18 changed files with 12 additions and 189 deletions.
10 changes: 0 additions & 10 deletions scripts/build.sh

This file was deleted.

14 changes: 0 additions & 14 deletions scripts/doc.sh

This file was deleted.

4 changes: 0 additions & 4 deletions scripts/infection.sh

This file was deleted.

33 changes: 0 additions & 33 deletions scripts/lint.sh

This file was deleted.

12 changes: 0 additions & 12 deletions scripts/metrics.sh

This file was deleted.

5 changes: 0 additions & 5 deletions scripts/phan.sh

This file was deleted.

66 changes: 0 additions & 66 deletions scripts/php-no-xdebug.sh

This file was deleted.

4 changes: 0 additions & 4 deletions scripts/phpcpd.sh

This file was deleted.

4 changes: 0 additions & 4 deletions scripts/phpcs.sh

This file was deleted.

4 changes: 0 additions & 4 deletions scripts/phpdox.sh

This file was deleted.

4 changes: 0 additions & 4 deletions scripts/phploc.sh

This file was deleted.

6 changes: 0 additions & 6 deletions scripts/phpmd.sh

This file was deleted.

4 changes: 0 additions & 4 deletions scripts/phpmetrics.sh

This file was deleted.

4 changes: 0 additions & 4 deletions scripts/phpmnd.sh

This file was deleted.

4 changes: 0 additions & 4 deletions scripts/phpstan.sh

This file was deleted.

5 changes: 0 additions & 5 deletions scripts/phpunit.sh

This file was deleted.

1 change: 1 addition & 0 deletions src/Factory/BaseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function addToArray(string $object, $value): void
*/
public function toJson($options = 0): string
{
$options = $options | JSON_PRESERVE_ZERO_FRACTION;
$json = json_encode($this->toArray(), $options);

if ($json === false) {
Expand Down
17 changes: 11 additions & 6 deletions tests/Factory/BaseFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,17 @@ public function addToArray()
*/
public function toJson()
{
$obj = new class extends BaseFactory {
$obj = new class extends BaseFactory
{
public function toArray(): ?array
{
return [
'attr' => 'value with <, &, \' and ".',
'arr' => [
'first',
'second'
]
],
'float' => 3.0
];
}

Expand All @@ -104,7 +106,7 @@ public function fake()
};

$json = $obj->toJson();
$expected = '{"attr":"value with <, &, \' and \".","arr":["first","second"]}';
$expected = '{"attr":"value with <, &, \' and \".","arr":["first","second"],"float":3.0}';

PHPUnit::assertEquals($expected, $json);
}
Expand All @@ -114,7 +116,8 @@ public function fake()
*/
public function toJsonFailed()
{
$obj = new class extends BaseFactory {
$obj = new class extends BaseFactory
{
public function toArray(): ?array
{
return [
Expand All @@ -141,7 +144,8 @@ public function fake()
*/
public function fakeMemberName()
{
$obj = new class extends BaseFactory {
$obj = new class extends BaseFactory
{
public function toArray(): ?array
{
return [];
Expand Down Expand Up @@ -189,7 +193,8 @@ public function test($name)
*/
public function fakeValue()
{
$obj = new class extends BaseFactory {
$obj = new class extends BaseFactory
{
public function toArray(): ?array
{
return [];
Expand Down

0 comments on commit c64c819

Please sign in to comment.