Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #883 +/- ##
============================================
+ Coverage 98.56% 98.59% +0.02%
- Complexity 389 396 +7
============================================
Files 24 24
Lines 909 924 +15
============================================
+ Hits 896 911 +15
Misses 13 13 ☔ View full report in Codecov by Harness. |
|
Suites doing assertions might have legitimate use cases for both behaviors. So maybe we need to make this change opt-in instead of always preserving the query string (potentially breaking existing suites that work since years). And the name of the protected method |
|
Good point on the BC risk, done. public function __construct(Session $session, bool $compareQueryString = false)
Two shape decisions I made on my own, happy to change either:
On 522 tests green, PHPStan clean. |
|
I think this should be a parameter of the assertion method, not of the constructor. The same project might have different needs for assertions in different places |
A project can need both behaviours in different places, so addressEquals(), addressNotEquals() and addressMatches() take the flag and the constructor goes back to its previous signature. cleanUrl() and getCurrentUrlPath() keep their exact signatures, since adding an optional argument to a protected method is a fatal error for any subclass that overrides it. With the flag off an assertion still goes through getCurrentUrlPath(); with it on, a private helper calls cleanUrl() and splices the query back in front of the fragment.
|
Done, the flag is on the assertion methods now and the constructor is back to $assert->addressEquals('/login?return_url=/user', true);
$assert->addressNotEquals('/login?return_url=/admin', true);
$assert->addressMatches('/return_url/', true);I gave it to How it is plumbed, since that decides what happens to the two protected extension points:
That also settles your naming point: The one signature change left is the three public assertion methods, so a subclass overriding 525 tests green, PHPStan clean. |
Fixes #656
cleanUrl()now keeps the query string, the same way #357 taught it to keep the fragment back in 2013.Two things came out of the homework you asked for in the issue, @aik099.
Why it was implemented this way: it never was a decision. In #566 you wrote "I guess this was some kind to normalize url", @stof asked @everzet for the reason, and the answer never came. So there is no intent to preserve here.
The behaviour was locked in by the test suite. Before writing a single new test, exactly one test failed:
testAddressEqualsalready usedhttp://example.com/script.php/sub/url?param=true#webapp/navand asserted thataddressEquals('/sub/url#webapp/nav')passes. It now expects the query string. I added two tests built on the/login?return_url=/userexample from the original report, one per direction.I deliberately did not normalize the query string. You floated sorting the parameters and rebuilding with
http_build_query()in 2014, and @anton-siardziuk answered that the less is done implicitly the better; your 2022 reply agreed with "about the same fix for query string", so a literal treatment like the fragment is what this does. Say the word if you want the normalization too.The part that is your call. This changes assertion results: a suite that wrote
addressEquals('/login')while sitting on/login?x=1used to pass and will now fail.cleanUrl()isprotected, so subclasses are affected as well.CONTRIBUTING.mdsays to branch frommaster, so that is where this is, but retarget it to2-architecture-changesif you would rather not ship it in a minor.522 tests green, PHPStan clean.
CHANGES.mduntouched.