Skip to content

Commit 10daaad

Browse files
committed
[BrowserKit] Add PHPUnit constraints: BrowserHistoryIsOnFirstPage and BrowserHistoryIsOnLastPage
1 parent 8c73fd0 commit 10daaad

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add `isFirstPage()` and `isLastPage()` methods to the History class for checking navigation boundaries
8+
* Add PHPUnit constraints: `BrowserHistoryIsOnFirstPage` and `BrowserHistoryIsOnLastPage`
89

910
6.4
1011
---
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\BrowserKit\Test\Constraint;
13+
14+
use PHPUnit\Framework\Constraint\Constraint;
15+
use Symfony\Component\BrowserKit\AbstractBrowser;
16+
17+
final class BrowserHistoryIsOnFirstPage extends Constraint
18+
{
19+
public function toString(): string
20+
{
21+
return 'is on the first page';
22+
}
23+
24+
protected function matches($other): bool
25+
{
26+
if (!$other instanceof AbstractBrowser) {
27+
throw new \LogicException('Can only test on an AbstractBrowser instance.');
28+
}
29+
30+
return $other->getHistory()->isFirstPage();
31+
}
32+
33+
protected function failureDescription($other): string
34+
{
35+
return 'the Browser history '.$this->toString();
36+
}
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\BrowserKit\Test\Constraint;
13+
14+
use PHPUnit\Framework\Constraint\Constraint;
15+
use Symfony\Component\BrowserKit\AbstractBrowser;
16+
17+
final class BrowserHistoryIsOnLastPage extends Constraint
18+
{
19+
public function toString(): string
20+
{
21+
return 'is on the last page';
22+
}
23+
24+
protected function matches($other): bool
25+
{
26+
if (!$other instanceof AbstractBrowser) {
27+
throw new \LogicException('Can only test on an AbstractBrowser instance.');
28+
}
29+
30+
return $other->getHistory()->isLastPage();
31+
}
32+
33+
protected function failureDescription($other): string
34+
{
35+
return 'the Browser history '.$this->toString();
36+
}
37+
}

0 commit comments

Comments
 (0)