Skip to content

[BrowserKit] Add isFirstPage() and isLastPage() methods to History #60895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

santysisi
Copy link
Contributor

@santysisi santysisi commented Jun 24, 2025

Q A
Branch? 7.4
Bug fix? no
New feature? yes
Deprecations? no
Issues No
License MIT

This PR introduces two new utility methods

  • isFirstPage(): Returns true if the current position is at the start of the history stack.
  • isLastPage(): Returns true if the current position is at the end of the history stack.

These methods are particularly useful in a testing context. For example, they enable clearer and more targeted assertions, such as:

$this->assertTrue($client->getHistory()->isLastPage());
$this->assertTrue($client->getHistory()->isFirstPage());
$this->assertFalse($client->getHistory()->isFirstPage());
$this->assertFalse($client->getHistory()->isLastPage());

These new methods also allow developers to proactively check the navigation state before calling back() or forward(), which can be useful in certain scenarios to avoid unnecessary exceptions and reduce the need for additional error handling logic.

7.4
---

* Add `isFirstPage()` and `isLastPage()` methods to the History class for checking navigation boundaries.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Add `isFirstPage()` and `isLastPage()` methods to the History class for checking navigation boundaries.
* Add `isFirstPage()` and `isLastPage()` methods to the History class for checking navigation boundaries

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad, thanks for your help ❤️
Changes have been made.

P.S. I think the errors aren't relevant in the context of this PR.

@santysisi santysisi force-pushed the feature/history-navigation-checks branch from 16aa79e to 8b2045e Compare June 27, 2025 02:34
@nicolas-grekas
Copy link
Member

Thank you @santysisi.

@nicolas-grekas nicolas-grekas merged commit 4539661 into symfony:7.4 Jun 27, 2025
8 of 11 checks passed
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.

3 participants