constraint = new Codeception\PHPUnit\Constraint\Crawler('hello', '/user'); } public function testEvaluation() { $nodes = new Symfony\Component\DomCrawler\Crawler("

Bye world

Hello world

"); $this->constraint->evaluate($nodes); } public function testFailMessageResponse() { $nodes = new Symfony\Component\DomCrawler\Crawler('

Bye world

Bye warcraft

'); try { $this->constraint->evaluate($nodes->filter('p'), 'selector'); } catch (\PHPUnit\Framework\AssertionFailedError $fail) { $this->assertContains( "Failed asserting that any element by 'selector' on page /user", $fail->getMessage() ); $this->assertContains('+

Bye world

', $fail->getMessage()); $this->assertContains('+

Bye warcraft

', $fail->getMessage()); return; } $this->fail("should have failed, but not"); } public function testFailMessageResponseWhenMoreNodes() { $html = ''; for ($i = 0; $i < 15; $i++) { $html .= "

item $i

"; } $nodes = new Symfony\Component\DomCrawler\Crawler($html); try { $this->constraint->evaluate($nodes->filter('p'), 'selector'); } catch (\PHPUnit\Framework\AssertionFailedError $fail) { $this->assertContains( "Failed asserting that any element by 'selector' on page /user", $fail->getMessage() ); $this->assertNotContains('+

item 0

', $fail->getMessage()); $this->assertNotContains('+

item 14

', $fail->getMessage()); $this->assertContains('[total 15 elements]', $fail->getMessage()); return; } $this->fail("should have failed, but not"); } public function testFailMessageResponseWithoutUrl() { $this->constraint = new Codeception\PHPUnit\Constraint\Crawler('hello'); $nodes = new Symfony\Component\DomCrawler\Crawler('

Bye world

Bye warcraft

'); try { $this->constraint->evaluate($nodes->filter('p'), 'selector'); } catch (\PHPUnit\Framework\AssertionFailedError $fail) { $this->assertContains("Failed asserting that any element by 'selector'", $fail->getMessage()); $this->assertNotContains("Failed asserting that any element by 'selector' on page", $fail->getMessage()); return; } $this->fail("should have failed, but not"); } }