Skip to content

[BrowserKit] Add PHPUnit constraints: BrowserHistoryIsOnFirstPage and BrowserHistoryIsOnLastPage #60955

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

Open
wants to merge 1 commit into
base: 7.4
Choose a base branch
from

Conversation

santysisi
Copy link
Contributor

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

This PR introduces two new PHPUnit constraints to improve testing of browser navigation history state:

  • BrowserHistoryIsOnFirstPage
  • BrowserHistoryIsOnLastPage

These constraints allow asserting the current state of the AbstractBrowser history using the following new assertion methods:

$this->assertBrowserHistoryIsOnFirstPage();
$this->assertBrowserHistoryIsNotOnFirstPage();
$this->assertBrowserHistoryIsOnLastPage();
$this->assertBrowserHistoryIsNotOnLastPage();

@carsonbot carsonbot added this to the 7.4 milestone Jun 30, 2025
@santysisi santysisi force-pushed the feature/browser-history-constraints branch from d07a653 to ca833f1 Compare June 30, 2025 04:08
@santysisi santysisi force-pushed the feature/browser-history-constraints branch from ca833f1 to 76e80c1 Compare June 30, 2025 04:20
@@ -122,6 +123,38 @@ public static function assertBrowserNotHasCookie(string $name, string $path = '/
self::assertThatForClient(new LogicalNot(new BrowserKitConstraint\BrowserHasCookie($name, $path, $domain)), $message);
}

public static function assertBrowserHistoryIsOnFirstPage(string $message = ''): void
{
if (!method_exists(History::class, 'isFirstPage')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of these checks, what about raising the requirement to 7.4 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi 👋, thanks for your comment! 😀

Personally, I don't have a strong preference, but in a previous PR, @nicolas-grekas mentioned not bumping versions 😅. If you'd prefer, I can raise the version to 7.4 🚀

Thanks again for your input! 🙏

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