Skip to content

Commit e7bbde3

Browse files
minor #644 Align tests with PHP 8.6 changes to ext/tidy and ext/intl (nicolas-grekas)
This PR was merged into the 1.x branch. Discussion ---------- Align tests with PHP 8.6 changes to ext/tidy and ext/intl Fixes the two failures of the `PHPUnit Tests (8.6, apc, apcu, ... intl-73.2 ...)` job, which is red on `1.x` itself, plus an unrelated flaky test that failed in the same run. ### `DeepCloneTest::testTidyNodeRoundTrip` php-src [`4782ec55aae`](php/php-src@4782ec55aae) (*Add NOT_SERIALIZABLE to XMLWriter, XMLReader, SNMP, tidy, and tidyNode*, php/php-src#21694, master only) marks `tidyNode` ``@not`-serializable` — it wraps a libTidy handle and "segfaults on use" once unserialized. `ext/deepclone` honours `ZEND_ACC_NOT_SERIALIZABLE`, so on 8.6 both engines now refuse the node: the extension via that flag, the polyfill because `unserialize('O:8:"tidyNode":0:{}')` throws. Same exception, same message — only the test was stale. Per the design principle that the `deepclone` polyfill mirrors the newest native state rather than each intermediate version, `tidyNode` joins `NOT_ROUND_TRIPPABLE`. The extension is more lenient below 8.6 (`tidyNode` is `final` and bare-instantiable there, so it passes the probe), so the test keeps the round-trip expectation for that combination. ### `NormalizerTest::testNormalizeWithInvalidForm` php-src [`94e8c54ef27`](php/php-src@94e8c54ef27) (*ext/intl: Fix various error messages*, php/php-src#22828, master only) dropped the doubled article introduced back when intl warnings were promoted to exceptions. Both the polyfill and its test hardcoded `must be a a valid`, so the message is now conditional on `PHP_VERSION_ID >= 80600`. ### `Php73Test::testHardwareTimeAsArrayNanos` Unrelated, and the reason the `(7.3, apc, apcu, ...)` job failed in the same run: the test asserted `$hrtime2[0] - $hrtime[0] === 0`, which fails whenever the two `hrtime()` calls straddle a whole second. It now measures total elapsed nanoseconds and checks the sub-second component stays in range. Commits ------- 159e290 Align tests with PHP 8.6 changes to ext/tidy and ext/intl
2 parents 036c8f5 + 159e290 commit e7bbde3

5 files changed

Lines changed: 28 additions & 10 deletions

File tree

src/DeepClone/DeepClone.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ final class DeepClone
2525
'XMLReader' => true,
2626
'SNMP' => true,
2727
'tidy' => true,
28+
'tidyNode' => true,
2829
];
2930

3031
private static array $reflectors = [];

src/Intl/Normalizer/Normalizer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ public static function normalize(string $s, int $form = self::FORM_C)
129129
return false;
130130
}
131131

132-
throw new \ValueError('normalizer_normalize(): Argument #2 ($form) must be a a valid normalization form');
132+
// the doubled article was fixed in PHP 8.6
133+
throw new \ValueError('normalizer_normalize(): Argument #2 ($form) must be a '.(80600 > \PHP_VERSION_ID ? 'a ' : '').'valid normalization form');
133134
}
134135

135136
if ('' === $s) {

tests/DeepClone/DeepCloneTest.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,18 +1193,31 @@ public function testMongoDbBsonRoundTrip()
11931193
/**
11941194
* @requires extension tidy
11951195
*/
1196-
public function testTidyNodeRoundTrip()
1196+
public function testTidyNodeIsNotInstantiable()
11971197
{
11981198
$tidy = new \tidy();
11991199
$tidy->parseString('<p><b>hello</b></p>', [], 'utf8');
12001200
$b = $tidy->body()->child[0]->child[0]; // <b> node
12011201

1202-
$clone = deepclone_from_array(deepclone_to_array($b));
1202+
if (\PHP_VERSION_ID < 80600 && \extension_loaded('deepclone') && !TestListenerTrait::$enabledPolyfills) {
1203+
// tidyNode is final and bare-instantiable there, so the extension
1204+
// still restores it property by property.
1205+
$clone = deepclone_from_array(deepclone_to_array($b));
12031206

1204-
$this->assertInstanceOf(\tidyNode::class, $clone);
1205-
$this->assertNotSame($b, $clone);
1206-
$this->assertSame($b->name, $clone->name);
1207-
$this->assertSame($b->value, $clone->value);
1207+
$this->assertInstanceOf(\tidyNode::class, $clone);
1208+
$this->assertNotSame($b, $clone);
1209+
$this->assertSame($b->name, $clone->name);
1210+
$this->assertSame($b->value, $clone->value);
1211+
1212+
return;
1213+
}
1214+
1215+
// tidyNode wraps a libTidy handle that cannot survive serialization; PHP 8.6
1216+
// marks it NOT_SERIALIZABLE, and the polyfill mirrors that on every version.
1217+
$this->expectException(\DeepClone\NotInstantiableException::class);
1218+
$this->expectExceptionMessage('Type "tidyNode" is not instantiable.');
1219+
1220+
deepclone_to_array($b);
12081221
}
12091222

12101223
public function testHydrateScopedInstantiate()

tests/Intl/Normalizer/NormalizerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function testNormalizeWithInvalidForm()
9797
{
9898
if (80000 <= \PHP_VERSION_ID) {
9999
$this->expectException(\ValueError::class);
100-
$this->expectExceptionMessage('normalizer_normalize(): Argument #2 ($form) must be a a valid normalization form');
100+
$this->expectExceptionMessage('normalizer_normalize(): Argument #2 ($form) must be a '.(80600 > \PHP_VERSION_ID ? 'a ' : '').'valid normalization form');
101101
}
102102

103103
$this->assertFalse(normalizer_normalize('foo', -1));

tests/Php73/Php73Test.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,11 @@ public function testHardwareTimeAsArrayNanos()
8383
usleep(1000);
8484
$hrtime2 = hrtime();
8585

86-
$this->assertSame(0, $hrtime2[0] - $hrtime[0]);
87-
$this->assertGreaterThanOrEqual(1000000, $hrtime2[1] - $hrtime[1]);
86+
// don't compare the components separately: the pair can straddle a whole second
87+
$elapsed = 1000000000 * ($hrtime2[0] - $hrtime[0]) + $hrtime2[1] - $hrtime[1];
88+
89+
$this->assertGreaterThanOrEqual(1000000, $elapsed);
90+
$this->assertLessThan(1000000000, $hrtime2[1]);
8891
}
8992

9093
public function testHardwareTimeAsArraySeconds()

0 commit comments

Comments
 (0)