Skip to content

Commit 738576a

Browse files
committed
Test Page constraint
1 parent 96b79b0 commit 738576a

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/Constraint/Page.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,6 @@ protected function uriMessage(string $onPage = ''): string
8282
if (!$this->uri) {
8383
return '';
8484
}
85-
return " {$onPage} {$this->uri}";
85+
return "{$onPage} {$this->uri}";
8686
}
8787
}

tests/Constraint/PageTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Tests\Codeception\Constraint;
4+
5+
use Codeception\Constraint\Page;
6+
use PHPUnit\Framework\AssertionFailedError;
7+
use PHPUnit\Framework\TestCase;
8+
9+
class PageTest extends TestCase
10+
{
11+
public function testPassesIfPageContainsString(): void
12+
{
13+
$constraint = new Page('text', 'uri');
14+
$this->assertNull($constraint->evaluate('long text string'));
15+
}
16+
17+
public function testFailsIfPageDoesntContainString(): void
18+
{
19+
$this->expectException(AssertionFailedError::class);
20+
$this->expectExceptionMessage(<<<EOT
21+
Failed asserting that on page uri
22+
--> other string
23+
--> contains "text".
24+
EOT
25+
);
26+
27+
$constraint = new Page('text', 'uri');
28+
$this->assertNull($constraint->evaluate('other string'));
29+
}
30+
}

0 commit comments

Comments
 (0)