Skip to content

Commit

Permalink
clean up assertion failure
Browse files Browse the repository at this point in the history
  • Loading branch information
sinnbeck committed Oct 23, 2022
1 parent 7b0e2c0 commit c40b5e6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Asserts/Traits/UsesElementAsserts.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ public function contains(string $elementName, $attributes = null, $count = 0): s
public function doesntContain(string $elementName, array $attributes = []): self
{
if (! $attributes) {
$found = $this->getParser()->query($elementName);
Assert::assertNull(
$this->getParser()->query($elementName),
$found ? get_class($found): null,
sprintf('Found a matching element of type "%s"', $elementName)
);

Expand Down
25 changes: 25 additions & 0 deletions tests/DomTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,28 @@
});
});
});

it('can fail finding an contained element', function () {
$this->get('nesting')
->assertElement(function (ElementAssert $element) {
$element->findDiv(function (ElementAssert $element) {
$element->doesntContain('div');
});
});
})->throws(
AssertionFailedError::class,
'Found a matching element of type "div'
);


it('can fail finding an contained element with query', function () {
$this->get('nesting')
->assertElement(function (ElementAssert $element) {
$element->findDiv(function (ElementAssert $element) {
$element->doesntContain('div.foobar');
});
});
})->throws(
AssertionFailedError::class,
'Found a matching element of type "div'
);

0 comments on commit c40b5e6

Please sign in to comment.