Skip to content

Commit

Permalink
Add missing assertion prefixes to testing helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Mar 18, 2024
1 parent a715ae2 commit d447205
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
32 changes: 16 additions & 16 deletions packages/framework/tests/Unit/HtmlTestingSupportMetaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,69 +439,69 @@ public function testToArrayWithAttributes()

public function testElementHasId()
{
$this->html('<div id="foo">Foo</div>')->getRootElement()->hasId('foo');
$this->html('<div id="foo">Foo</div>')->getRootElement()->assertHasId('foo');
}

public function testElementDoesNotHaveId()
{
$this->html('<div>Foo</div>')->getRootElement()->doesNotHaveId('foo');
$this->html('<div>Foo</div>')->getRootElement()->assertDoesNotHaveId('foo');
}

public function testElementAssertHasClass()
{
$this->html('<div class="foo">Foo</div>')->getRootElement()->hasClass('foo');
$this->html('<div class="foo">Foo</div>')->getRootElement()->assertHasClass('foo');
}

public function testElementAssertDoesNotHaveClass()
{
$this->html('<div class="foo">Foo</div>')->getRootElement()->doesNotHaveClass('bar');
$this->html('<div class="foo">Foo</div>')->getRootElement()->assertDoesNotHaveClass('bar');
}

public function testElementAssertHasAttribute()
{
$this->html('<div name="foo">Foo</div>')->getRootElement()->hasAttribute('name');
$this->html('<div name="foo">Foo</div>')->getRootElement()->assertHasAttribute('name');
}

public function testElementAssertDoesNotHaveAttribute()
{
$this->html('<div name="foo">Foo</div>')->getRootElement()->doesNotHaveAttribute('href');
$this->html('<div name="foo">Foo</div>')->getRootElement()->assertDoesNotHaveAttribute('href');
}

public function testElementAssertHasAttributeWithValue()
{
$this->html('<div name="foo">Foo</div>')->getRootElement()->hasAttribute('name', 'foo');
$this->html('<div name="foo">Foo</div>')->getRootElement()->assertHasAttribute('name', 'foo');
}

public function testElementAssertHasAttributeWithWrongValue()
{
try {
$this->html('<div name="foo">Foo</div>')->getRootElement()->hasAttribute('name', 'bar');
$this->html('<div name="foo">Foo</div>')->getRootElement()->assertHasAttribute('name', 'bar');
} catch (ExpectationFailedException $exception) {
$this->assertSame("The attribute 'name' did not have the expected value.\nFailed asserting that two strings are identical.", $exception->getMessage());
}
}

public function testElementAssertHasAttributeForwardsIdAssertions()
{
$this->html('<div id="foo">Foo</div>')->getRootElement()->hasAttribute('id', 'foo');
$this->html('<div id="foo">Foo</div>')->getRootElement()->assertHasAttribute('id', 'foo');
}

public function testElementAssertHasAttributeForwardsClassAssertions()
{
$this->html('<div class="foo">Foo</div>')->getRootElement()->hasAttribute('class', 'foo');
$this->html('<div class="foo">Foo</div>')->getRootElement()->assertHasAttribute('class', 'foo');
}

public function testAssertionCallsOnDocumentAreForwardedToRootElement()
{
$this->assertInstanceOf(TestableHtmlElement::class,
$this->html('<div id="foo" class="bar">Foo</div>')
->assertSee('Foo')
->hasId('foo')
->doesNotHaveId('bar')
->hasClass('bar')
->doesNotHaveClass('baz')
->hasAttribute('class', 'bar')
->doesNotHaveAttribute('href')
->assertHasId('foo')
->assertDoesNotHaveId('bar')
->assertHasClass('bar')
->assertDoesNotHaveClass('baz')
->assertHasAttribute('class', 'bar')
->assertDoesNotHaveAttribute('href')
->assertSee('Foo')
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,34 @@ public function assertDontSeeEscaped(string $value): static
return $this->doAssert(fn () => PHPUnit::assertStringNotContainsString(e($value), $this->html, "The escaped string '$value' was found in the HTML."));
}

public function hasId(string $id): TestableHtmlElement
public function assertHasId(string $id): TestableHtmlElement
{
return $this->doElementAssert(fn () => PHPUnit::assertSame($id, $this->id, 'The id attribute did not have the expected value.'));
}

public function doesNotHaveId(string $id): TestableHtmlElement
public function assertDoesNotHaveId(string $id): TestableHtmlElement
{
return $this->doElementAssert(fn () => PHPUnit::assertNotSame($id, $this->id, 'The id attribute had the unexpected value.'));
}

public function hasClass(string $class): TestableHtmlElement
public function assertHasClass(string $class): TestableHtmlElement
{
return $this->doElementAssert(fn () => PHPUnit::assertContains($class, $this->classes, "The class '$class' was not found in the element."));
}

public function doesNotHaveClass(string $class): TestableHtmlElement
public function assertDoesNotHaveClass(string $class): TestableHtmlElement
{
return $this->doElementAssert(fn () => PHPUnit::assertNotContains($class, $this->classes, "The class '$class' was found in the element."));
}

public function hasAttribute(string $attribute, ?string $value = null): TestableHtmlElement
public function assertHasAttribute(string $attribute, ?string $value = null): TestableHtmlElement
{
if ($attribute === 'id') {
return $this->hasId($value);
return $this->assertHasId($value);
}

if ($attribute === 'class') {
return $this->hasClass($value);
return $this->assertHasClass($value);
}

$this->doElementAssert(fn () => PHPUnit::assertArrayHasKey($attribute, $this->attributes, "The attribute '$attribute' was not found in the element."));
Expand All @@ -73,7 +73,7 @@ public function hasAttribute(string $attribute, ?string $value = null): Testable
return $this;
}

public function doesNotHaveAttribute(string $attribute): TestableHtmlElement
public function assertDoesNotHaveAttribute(string $attribute): TestableHtmlElement
{
return $this->doElementAssert(fn () => PHPUnit::assertArrayNotHasKey($attribute, $this->attributes, "The attribute '$attribute' was found in the element."));
}
Expand Down

0 comments on commit d447205

Please sign in to comment.