Skip to content

ext/uri: Reorganises legacy tests - #23286

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

ext/uri: Reorganises legacy tests#23286
NickSdot wants to merge 13 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

Base: a2dc4e9ff260cd47f8b8b7abe7b555f2b9ff3b2f upstream/master
Tree: d0315577c31d6aaab5b0ea764856da4417b13eb4 working tree

+--------+-------+---------+--------------------+-------------------+--------+---------+
|        | Tests | Sources |              Lines |          Branches |   Time |  Memory |
+--------+-------+---------+--------------------+-------------------+--------+---------+
| Base   |   433 |       7 | 1962/2202 (89.10%) | 714/1199 (59.55%) |  8.43s | 28.0 MB |
| Tree   |   451 |       7 | 1962/2202 (89.10%) | 714/1199 (59.55%) |  9.55s | 28.0 MB |
| Change |   +18 |       0 |   +0 / -0 (+0.00%) |  +0 / -0 (+0.00%) | +1.12s | +0.0 MB |
+--------+-------+---------+--------------------+-------------------+--------+---------+
Comment thread ext/uri/tests/rfc3986/parsing/port_error_overflow.phpt
Comment thread ext/uri/tests/whatwg/parsing/errors_reference_error.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.

@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

$url = new Uri\WhatWg\Url("https://example.com/foo/bar%2Fbaz");
var_dump($url->getPath());
var_dump($uri->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.

tests in the parsing directory have the following code for assertions:

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


$uri = Uri\Rfc3986\Uri::parse("192.168/contact.html");

var_dump($uri);

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 same assertions are needed as mentioned above

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

I actually think something like assertion_helpers.inc would make sense here.

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/rfc3986/parsing/zend_test_port_success_large.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());
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! :)

Co-authored-by: Máté Kocsis <kocsismate90@gmail.com>
NickSdot and others added 4 commits September 1, 2026 12:14
Co-authored-by: Máté Kocsis <kocsismate90@gmail.com>
Co-authored-by: Máté Kocsis <kocsismate90@gmail.com>
Co-authored-by: Máté Kocsis <kocsismate90@gmail.com>
Co-authored-by: Máté Kocsis <kocsismate90@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants