Skip to content

ext/uri: Reorganises legacy tests - #23286

Open
NickSdot wants to merge 30 commits into
php:masterfrom
NickSdot:hardening/ext-uri-reorg
Open

ext/uri: Reorganises legacy tests#23286
NickSdot wants to merge 30 commits into
php:masterfrom
NickSdot:hardening/ext-uri-reorg

Conversation

@NickSdot

@NickSdot NickSdot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Ref: #23271 (review) @kocsismate
Depends on: #23271 (ready here, but marked as draft until 23271 is merged)

Coverage

Coverage: ext/uri/tests

Base: 2d7131e1bf1da03eb133c50aee37c8377ecc1723 upstream/master
Tree: 2148cd5c088f1ddddc716ebfb079fd9af0334e36 working tree

+--------+-----------+---------+--------------------+-------------------+--------+---------+
|        |     Tests | Sources |              Lines |          Branches |   Time |  Memory |
+--------+-----------+---------+--------------------+-------------------+--------+---------+
| Base   |       484 |       7 | 2035/2281 (89.22%) | 733/1234 (59.40%) |  9.96s | 28.0 MB |
| Tree   |       519 |       7 | 2035/2281 (89.22%) | 733/1234 (59.40%) | 10.39s | 27.8 MB |
| Change | +73 / -38 |       0 |   +0 / -0 (+0.00%) |  +0 / -0 (+0.00%) | +0.43s | -0.2 MB |
+--------+-----------+---------+--------------------+-------------------+--------+---------+

Comment thread ext/uri/tests/rfc3986/parsing/port_error_overflow.phpt

@NickSdot NickSdot Aug 15, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two options for these: keep grouped in eg parsing with zend_ prefix or give dedicated zend dir. Thoughts?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with putting it into the general directory with something like internal_api_success_parse_url_parsing.php or similar. The important thing here is that the internal API is used by the zend_test function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved them to ext/uri/tests/zend and kept your proposed prefix. Only having the suffix does not make it clear what it is; having a zend directory convention in extensions helps contributors that are new to the code base. Ok with it?

@NickSdot
NickSdot force-pushed the hardening/ext-uri-reorg branch from 74844f2 to d2bfb5c Compare August 15, 2026 14:04
@NickSdot
NickSdot marked this pull request as ready for review August 15, 2026 14:10

@kocsismate kocsismate left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

partial review yet, I'll continue later

Comment thread ext/uri/tests/008.phpt
Comment thread ext/uri/tests/rfc3986/modification/host_success_ipv4_to_ipv6.phpt Outdated
Comment thread ext/uri/tests/rfc3986/modification/host_success_percent_encoded_reserved.phpt Outdated
Comment thread ext/uri/tests/rfc3986/modification/port_success_empty_host.phpt
Comment thread ext/uri/tests/rfc3986/parsing/path_success_percent_encoded_reserved.phpt Outdated
Comment thread ext/uri/tests/rfc3986/parsing/path_success_percent_encoded.phpt

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

much of these cases are already covered, please check them (e.g. there is ext/uri/tests/rfc3986/parsing/path_success_relative_reference.phpt and ext/uri/tests/rfc3986/parsing/path_success_relative_reference_absolute.phpt). so probably only mailto:johndoe@example.com and maybe /// is needed (but let's separate them for better readability)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done for both

Comment thread ext/uri/tests/zend/internal_api_success_rfc3986_large_port.phpt
@NickSdot

Copy link
Copy Markdown
Contributor Author

partial review yet, I'll continue later

To avoid miscommunication: I plan to address everything in one go when you continued. In case your second pass didn't yield anything new please update me so I know it's done and we do not wait for each other. :)

@@ -1,5 +1,5 @@
--TEST--
Test reference resolution
Test Uri\Rfc3986\Uri reference resolution during parsing

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the usual format should be used

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what you mean

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not needed, since it doesn't have a baseUrl

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the rest of the cases should go into separate tests, and the assertion should be the usual one

var_dump($uri);
var_dump($uri->toRawString());
var_dump($uri->toString());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Split to:

parse_success_absolute_with_base.phpt
parse_success_relative_with_base.phpt
parse_success_without_base.phpt

Normalise case was removed in accordance with your comment below.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really sure a separate case for normalized URI is needed here, unless it improves coverage somehow 🤔 (but I don't think it does)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. It did not. As mentioned above, these were just 1:1: moved. Goal here was to retain coverage, nothing was added extra.

Comment thread ext/uri/tests/rfc3986/general/array_cast_success.phpt

$uri = new Uri\Rfc3986\Uri('https://example.com');
try {
$uri->__unserialize([['uri' => 'ftp://example.org'], []]);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be a serialization test indeed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It already is an serialisation test?

Comment thread ext/uri/tests/rfc3986/serialization/reinitialization_error.phpt Outdated
Comment thread ext/uri/tests/rfc3986/serialization/string_conversion_success.phpt Outdated
Comment thread ext/uri/tests/rfc3986/serialization/var_export_success.phpt Outdated
Comment thread ext/uri/tests/rfc3986/serialization/var_export_success.phpt Outdated
@kocsismate

Copy link
Copy Markdown
Member

To avoid miscommunication: I plan to address everything in one go when you continued. In case your second pass didn't yield anything new please update me so I know it's done and we do not wait for each other. :)

I went through all rfc3986 tests now. There are quite a few recurring problems which even apply to the WHATWG URL tests, so please resolve my comments globally, and then I'll continue with another, full review round.

@NickSdot
NickSdot force-pushed the hardening/ext-uri-reorg branch from d2bfb5c to 43b5f64 Compare August 20, 2026 07:42
@NickSdot

NickSdot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

To avoid miscommunication: I plan to address everything in one go when you continued. In case your second pass didn't yield anything new please update me so I know it's done and we do not wait for each other. :)

I went through all rfc3986 tests now. There are quite a few recurring problems which even apply to the WHATWG URL tests, so please resolve my comments globally, and then I'll continue with another, full review round.

  1. Except a few with questions that should be done in 43b5f64.
  2. Rebased
  3. Updated the coverage table in the desc. Numbers now slightly different because of Implement "Followup improvements for ext/uri" RFC - WHATWG URL building #22268 -- coverage same.
  4. Unlike others the PR used PHP_EOL for error assertions. Since those are fresh tests I allowed myself to add 80346c6 to unify them (can cherry pick to a separate PR if you prefer). There are some older ones that I didn't want to touch unasked; can do them too if you want -- my OCD would appreciate it.

Aside: before your review I treated the task as mechanical moves and extractions. So the pre-review state was 1:1 to before this PR ; I didn't check for duplications. I get now what you want. Thing is, I am not exactly confident to decide what qualifies as identical, what differs enough to keep it asserted, and what justifies a removal. I also cannot check each move against all 448 tests, my brain will explode. 😅 I did check the cases you mentioned (+whatwg) -- but if the goal really is to have zero duplicates, I cannot claim that's achieved now.

@NickSdot
NickSdot requested a review from kocsismate August 20, 2026 08:19

@kocsismate kocsismate left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, it's a very long list of review comments, only a few files are left, but I have to take a break now. Feel free to address my comments already.

Comment thread ext/uri/tests/rfc3986/getters/percent_encoded_components.phpt Outdated
$uri1 = Uri\Rfc3986\Uri::parse("https://example.com");
$uri2 = $uri1->withHost("t%3As%2Ft.com");

var_dump($uri1->getRawHost());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing tests only assert the modified component of the original URI like this:

var_dump($uri1->getRawHost());
var_dump($uri2->getRawHost());
var_dump($uri2->toRawString());
var_dump($uri2->getHost());
var_dump($uri2->toString());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines +10 to +13
var_dump($uri1->toRawString());

var_dump($uri2->getPort());
var_dump($uri2->toRawString());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The estabilished format:

Suggested change
var_dump($uri1->toRawString());
var_dump($uri2->getPort());
var_dump($uri2->toRawString());
var_dump($uri1->getPort());
var_dump($uri2->getPort());
var_dump($uri2->toRawString());

Comment thread ext/uri/tests/rfc3986/modification/port_success_unset_without_host.phpt Outdated
Comment on lines +9 to +13
var_dump($uri1->getPort());
var_dump($uri1->toString());

var_dump($uri2->getPort());
var_dump($uri2->toString());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var_dump($uri1->getPort());
var_dump($uri1->toString());
var_dump($uri2->getPort());
var_dump($uri2->toString());
var_dump($uri1->getPort());
var_dump($uri2->getPort());
var_dump($uri2->toRawString());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it is rather a general test?

$url = Uri\WhatWg\Url::parse("file:///E:\Documents and Settings");

var_dump($url);
var_dump($url->toUnicodeString());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var_dump($url->toUnicodeString());

Comment thread ext/uri/tests/whatwg/parsing/path_success_percent_encoded_reserved.phpt Outdated
$url = new Uri\WhatWg\Url("https://example.com/foo/bar%2Fbaz");

var_dump($url);
var_dump($url->toUnicodeString());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var_dump($url->toUnicodeString());

var_dump($url);
var_dump($url->toUnicodeString());
var_dump($url->toAsciiString());
var_dump($url->getPath());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var_dump($url->getPath());

@kocsismate

Copy link
Copy Markdown
Member

Aside: before your review I treated the task as mechanical moves and extractions. So the pre-review state was 1:1 to before this PR ; I didn't check for duplications. I get now what you want. Thing is, I am not exactly confident to decide what qualifies as identical, what differs enough to keep it asserted, and what justifies a removal. I also cannot check each move against all 448 tests, my brain will explode. 😅 I did check the cases you mentioned (+whatwg) -- but if the goal really is to have zero duplicates, I cannot claim that's achieved now.

Sorry if I got you into more than what you subscribed for. :) If you are still patient then we are not that far away from the finish line. I wanted to avoid keeping bad/unnecessary tests from the legacy folder, that's why I did such a "strict" review. I hope that you understand it :)

@NickSdot

NickSdot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Sorry if I got you into more than what you subscribed for. :) If you are still patient then we are not that far away from the finish line. I wanted to avoid keeping bad/unnecessary tests from the legacy folder, that's why I did such a "strict" review. I hope that you understand it :)

Nah,that's all good. Really just wanted to let you know that I will have to rely on your deeper knowledge of the domain. Will pick up on the comments soon! :)

@NickSdot
NickSdot force-pushed the hardening/ext-uri-reorg branch from c2f6384 to 72c11be Compare September 1, 2026 13:59
} catch (Throwable $e) {
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
echo $e::class, ': ', $e->getMessage(), "\n";
var_dump($e->errors[0]->type === Uri\WhatWg\UrlValidationErrorType::PortOutOfRange);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this because the other test has it too.

<?php

$errors = [];
$url = Uri\WhatWg\Url::parse("🐘", null, $errors);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly the same as the one with emoji in host.

@NickSdot

NickSdot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Should be done @kocsismate.

  • each test should now does one thing
  • applied each feedback to rfc and whatwg
  • had Codex run over it twice to look for duplicates

Notes:

  • The last two commits are for unrelated tests. While we are on it, we can unify all titles and style. They added some more files. If you prefer them cherry-picked to a new PR please let me know.
  • whatwg/builder/host_error_null_special.phpt and whatwg/builder/basic_error_with_base.phpt do not actually test what they say; probably related to Implement "Followup improvements for ext/uri" RFC - URL building with base URL #23526, and you might want to address it there.

Failure unrelated.

@NickSdot
NickSdot requested a review from kocsismate September 1, 2026 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants