Fix moveBack() history pointer + add symmetric moveForward()#87
Merged
TavoNiievez merged 2 commits intoJun 26, 2026
Merged
Conversation
added 2 commits
June 26, 2026 17:01
`moveBack()` replayed the previous request through `_loadPage()`, which called `clientRequest()` with the default `$changeHistory = true`. That appended a new entry to the BrowserKit history and discarded the forward entries, so going back behaved like a fresh navigation rather than a real Back button: the history pointer ended up on the last page again and a second `moveBack()` no longer walked further back. Thread a `$changeHistory` flag through `_loadPage()` (default `true`, so it is backward compatible) and pass `false` from `moveBack()`. The replayed request no longer mutates the history, matching Symfony's native `AbstractBrowser::back()` semantics. This also makes the framework history assertions (`assertBrowserHistoryIsNotOnLastPage()`) observable through the public `moveBack()` step.
Mirror of moveBack(): walks the BrowserKit history pointer forward N steps and replays the request with changeHistory = false, matching Symfony's native AbstractBrowser::forward(). Symfony exposes both back() and forward() with identical semantics, so InnerBrowser now offers the symmetric pair. This is purely additive (new public method) and is only usable now that moveBack() preserves the forward history entries instead of discarding them. Tests: testMoveForwardOneStep, testMoveForwardTwoSteps and testMoveForwardThrowsExceptionIfNumberOfStepsIsInvalid. The forward tests also assert that moveBack() kept the forward stack intact.
ce89ee4 to
da2befb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
1. Fix
moveBack()to move the history pointer instead of appendingmoveBack()replays the previous request via_loadPage(), which calledclientRequest()with the default$changeHistory = true. Replaying withchangeHistory = trueappends the request to the BrowserKit history and discards the forward entries, somoveBack()didn't behave like a real Back button:moveBack()no longer walked further back.Demonstration (fails on
master):Fix: thread a
$changeHistoryflag through_loadPage()and passfalsefrommoveBack(). Matches Symfony's nativeAbstractBrowser::back()(requestFromRequest($request, false)).2. Add symmetric
moveForward()Symfony's
AbstractBrowserexposes bothback()andforward()with identical semantics ($this->history->forward()+requestFromRequest($request, false)). InnerBrowser only hadmoveBack(). This adds the mirrormoveForward(int $numberOfSteps = 1). It is only meaningful because the fix above keeps the forward stack intact:Backward compatibility
No BC break:
moveForward()— brand-new public method, purely additive._loadPage()— gains a trailing optional parameterbool $changeHistory = true. Existing callers (incl. external Helpers using the@apimethod) are unaffected because the default preserves the previous behavior.moveBack()— signature unchanged; the change is a behavioral bugfix (back no longer mutates history). No relied-upon contract is removed.Why it matters downstream
moveForward()and a correctmoveBack()make the framework history assertions reachable through public steps — e.g.assertBrowserHistoryIsNotOnLastPage()(SymfonyBrowserKitAssertionsTrait,symfony/browser-kit >= 7.4), which previously had no step to position history off the last page. Unblocks the matching functional tests inCodeception/symfony-module-tests(#58, #59) forcodeception/module-symfony#240.Tests
moveBack: addedtestMoveBackPreservesForwardHistory(fails onmaster, passes here).moveForward: addedtestMoveForwardOneStep,testMoveForwardTwoSteps,testMoveForwardThrowsExceptionIfNumberOfStepsIsInvalid.Full unit suite green: 209 tests, 469 assertions.