Skip to content

Commit 9d7a094

Browse files
fix: correct jsonDecodeOptMask key typos in VersionDefaultConfig (#188)
* fix: correct jsonDecodeOptMask key typos in VersionDefaultConfig Two bugs in VersionDefaultConfig::setUnserializeConfig() made jsonDecodeOptMask completely non-functional: 1. _UNSERIALIZE_CONFIG_KEYS constant listed 'jsonDecodeOptsMask' (extra 's') — the foreach loop iterated this key but no match arm handled it, always hitting the default/throw path. 2. The match arm had 'jsonDecodeOptMask ' (trailing space) — even with a corrected constant, the key would never match. Both identifiers now consistently use 'jsonDecodeOptMask', matching the mutual-exclusion guard (line 83), the error message (line 103), and the libxmlOptMask parallel naming pattern. Claude Sonnet 4.6 * test: add VersionDefaultConfigTest covering unserialize/serialize config Tests the key fix from this PR: verifies that jsonDecodeOptMask is recognized as a valid config key and enters the validation path (previously silently skipped due to typo in constant + trailing space in match arm). The preg_match warning in testJsonDecodeOptMaskKeyIsRecognized is expected — the regex pattern itself has a separate bug tracked in PR #189. This test proves the key routing works regardless. Claude Sonnet 4.6 --------- Co-authored-by: Daniel Carbone <daniel.p.carbone@gmail.com>
1 parent cd87910 commit 9d7a094

2 files changed

Lines changed: 93 additions & 2 deletions

File tree

src/Version/VersionDefaultConfig.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class VersionDefaultConfig
2525
'libxmlOptMask',
2626
'jsonDecodeMaxDepth',
2727
'jsonDecodeOpts',
28-
'jsonDecodeOptsMask',
28+
'jsonDecodeOptMask',
2929
];
3030

3131
private const _SERIALIZE_CONFIG_KEYS = [
@@ -97,7 +97,7 @@ public function setUnserializeConfig(array $config): self
9797
)),
9898
'jsonDecodeMaxDepth' => intval($config[$k]),
9999
'jsonDecodeOpts' => intval($config[$k]),
100-
'jsonDecodeOptMask '=> is_string($config[$k]) && preg_match('{^[A-Z0-9_\s|]+$}', $config[$k])
100+
'jsonDecodeOptMask'=> is_string($config[$k]) && preg_match('{^[A-Z0-9_\s|]+$}', $config[$k])
101101
? $config[$k]
102102
: throw new \InvalidArgumentException(sprintf(
103103
'Value provided to "jsonDecodeOptMask" is either not a string or is an invalid options mask: %s',

tests/VersionDefaultConfigTest.php

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace DCarbone\PHPFHIRTests;
4+
5+
/*
6+
* Copyright 2025 Daniel Carbone (daniel.p.carbone@gmail.com)
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
use DCarbone\PHPFHIR\Version\VersionDefaultConfig;
22+
use PHPUnit\Framework\TestCase;
23+
24+
class VersionDefaultConfigTest extends TestCase
25+
{
26+
public function testSetUnserializeConfigAcceptsEmptyArray(): void
27+
{
28+
$c = new VersionDefaultConfig();
29+
$c->setUnserializeConfig([]);
30+
$this->assertEmpty($c->getUnserializeConfig());
31+
}
32+
33+
public function testSetUnserializeConfigAcceptsLibxmlOpts(): void
34+
{
35+
$c = new VersionDefaultConfig();
36+
$c->setUnserializeConfig(['libxmlOpts' => LIBXML_NONET]);
37+
$this->assertArrayHasKey('libxmlOpts', $c->getUnserializeConfig());
38+
$this->assertEquals(LIBXML_NONET, $c->getUnserializeConfig()['libxmlOpts']);
39+
}
40+
41+
public function testSetUnserializeConfigAcceptsJsonDecodeMaxDepth(): void
42+
{
43+
$c = new VersionDefaultConfig();
44+
$c->setUnserializeConfig(['jsonDecodeMaxDepth' => 1024]);
45+
$this->assertArrayHasKey('jsonDecodeMaxDepth', $c->getUnserializeConfig());
46+
$this->assertEquals(1024, $c->getUnserializeConfig()['jsonDecodeMaxDepth']);
47+
}
48+
49+
public function testSetUnserializeConfigAcceptsJsonDecodeOpts(): void
50+
{
51+
$c = new VersionDefaultConfig();
52+
$c->setUnserializeConfig(['jsonDecodeOpts' => JSON_THROW_ON_ERROR]);
53+
$this->assertArrayHasKey('jsonDecodeOpts', $c->getUnserializeConfig());
54+
$this->assertEquals(JSON_THROW_ON_ERROR, $c->getUnserializeConfig()['jsonDecodeOpts']);
55+
}
56+
57+
public function testSetUnserializeConfigJsonDecodeOptMaskKeyIsRecognized(): void
58+
{
59+
$c = new VersionDefaultConfig();
60+
// Before fix: constant had 'jsonDecodeOptsMask' (extra 's') and match arm had
61+
// trailing space — the key was silently skipped or hit the default throw path.
62+
// After fix: key is recognized and enters validation.
63+
try {
64+
$c->setUnserializeConfig(['jsonDecodeOptMask' => 'JSON_THROW_ON_ERROR']);
65+
// Value accepted — key was recognized AND value passed validation
66+
$this->assertArrayHasKey('jsonDecodeOptMask', $c->getUnserializeConfig());
67+
} catch (\InvalidArgumentException $e) {
68+
// InvalidArgumentException means the key WAS found but the value
69+
// failed regex validation — still proves the key typo fix works.
70+
// (Regex pattern fix tracked separately in PR #189)
71+
$this->assertStringContainsString('jsonDecodeOptMask', $e->getMessage());
72+
}
73+
}
74+
75+
public function testSetUnserializeConfigRejectsBothJsonDecodeOptsAndMask(): void
76+
{
77+
$this->expectException(\DomainException::class);
78+
$c = new VersionDefaultConfig();
79+
$c->setUnserializeConfig([
80+
'jsonDecodeOpts' => JSON_THROW_ON_ERROR,
81+
'jsonDecodeOptMask' => 'JSON_THROW_ON_ERROR',
82+
]);
83+
}
84+
85+
public function testSetSerializeConfigAcceptsEmptyArray(): void
86+
{
87+
$c = new VersionDefaultConfig();
88+
$c->setSerializeConfig([]);
89+
$this->assertEmpty($c->getSerializeConfig());
90+
}
91+
}

0 commit comments

Comments
 (0)