Skip to content

Commit 01a9a22

Browse files
committed
no longer use the internal TestFailure class
1 parent 9a63ca5 commit 01a9a22

6 files changed

+43
-61
lines changed

Tests/Test/Constraint/CrawlerAnySelectorTextContainsTest.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use PHPUnit\Framework\ExpectationFailedException;
1515
use PHPUnit\Framework\TestCase;
16-
use PHPUnit\Framework\TestFailure;
1716
use Symfony\Component\DomCrawler\Crawler;
1817
use Symfony\Component\DomCrawler\Test\Constraint\CrawlerAnySelectorTextContains;
1918

@@ -27,23 +26,25 @@ public function testConstraint()
2726
self::assertTrue($constraint->evaluate(new Crawler('<ul><li>Bar</li><li>Foo'), '', true));
2827
self::assertTrue($constraint->evaluate(new Crawler('<ul><li>Bar</li><li>Foo Bar Baz'), '', true));
2928
self::assertFalse($constraint->evaluate(new Crawler('<ul><li>Bar</li><li>Baz'), '', true));
29+
}
3030

31-
try {
32-
$constraint->evaluate(new Crawler('<ul><li>Bar</li><li>Baz'));
31+
public function testDoesNotMatchIfNodeDoesContainExpectedText()
32+
{
33+
$constraint = new CrawlerAnySelectorTextContains('ul li', 'Foo');
3334

34-
self::fail();
35-
} catch (ExpectationFailedException $e) {
36-
self::assertEquals("Failed asserting that the text of any node matching selector \"ul li\" contains \"Foo\".\n", TestFailure::exceptionToString($e));
37-
}
35+
$this->expectException(ExpectationFailedException::class);
36+
$this->expectExceptionMessage('Failed asserting that the text of any node matching selector "ul li" contains "Foo".');
3837

39-
try {
40-
$constraint->evaluate(new Crawler('<html><head><title>Foobar'));
38+
$constraint->evaluate(new Crawler('<ul><li>Bar</li><li>Baz'));
39+
}
40+
41+
public function testDoesNotMatchIfNodeDoesNotExist()
42+
{
43+
$constraint = new CrawlerAnySelectorTextContains('ul li', 'Foo');
4144

42-
self::fail();
43-
} catch (ExpectationFailedException $e) {
44-
self::assertEquals("Failed asserting that the Crawler has a node matching selector \"ul li\".\n", TestFailure::exceptionToString($e));
45+
$this->expectException(ExpectationFailedException::class);
46+
$this->expectExceptionMessage('Failed asserting that the Crawler has a node matching selector "ul li".');
4547

46-
return;
47-
}
48+
$constraint->evaluate(new Crawler('<html><head><title>Foobar'));
4849
}
4950
}

Tests/Test/Constraint/CrawlerAnySelectorTextSameTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use PHPUnit\Framework\ExpectationFailedException;
1515
use PHPUnit\Framework\TestCase;
16-
use PHPUnit\Framework\TestFailure;
1716
use Symfony\Component\DomCrawler\Crawler;
1817
use Symfony\Component\DomCrawler\Test\Constraint\CrawlerAnySelectorTextSame;
1918

@@ -28,12 +27,9 @@ public function testConstraint()
2827
self::assertFalse($constraint->evaluate(new Crawler('<ul><li>Bar</li><li>Foo Bar Baz'), '', true));
2928
self::assertFalse($constraint->evaluate(new Crawler('<ul><li>Bar</li><li>Baz'), '', true));
3029

31-
try {
32-
$constraint->evaluate(new Crawler('<ul><li>Bar</li><li>Baz'));
30+
$this->expectException(ExpectationFailedException::class);
31+
$this->expectExceptionMessage('Failed asserting that the Crawler has at least a node matching selector "ul li" with content "Foo".');
3332

34-
self::fail();
35-
} catch (ExpectationFailedException $e) {
36-
self::assertEquals("Failed asserting that the Crawler has at least a node matching selector \"ul li\" with content \"Foo\".\n", TestFailure::exceptionToString($e));
37-
}
33+
$constraint->evaluate(new Crawler('<ul><li>Bar</li><li>Baz'));
3834
}
3935
}

Tests/Test/Constraint/CrawlerSelectorAttributeValueSameTest.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use PHPUnit\Framework\ExpectationFailedException;
1515
use PHPUnit\Framework\TestCase;
16-
use PHPUnit\Framework\TestFailure;
1716
use Symfony\Component\DomCrawler\Crawler;
1817
use Symfony\Component\DomCrawler\Test\Constraint\CrawlerSelectorAttributeValueSame;
1918

@@ -26,14 +25,9 @@ public function testConstraint()
2625
$this->assertFalse($constraint->evaluate(new Crawler('<html><body><form><input type="text" name="username">'), '', true));
2726
$this->assertFalse($constraint->evaluate(new Crawler('<html><head><title>Bar'), '', true));
2827

29-
try {
30-
$constraint->evaluate(new Crawler('<html><head><title>Bar'));
31-
} catch (ExpectationFailedException $e) {
32-
$this->assertEquals("Failed asserting that the Crawler has a node matching selector \"input[name=\"username\"]\" with attribute \"value\" of value \"Fabien\".\n", TestFailure::exceptionToString($e));
28+
$this->expectException(ExpectationFailedException::class);
29+
$this->expectExceptionMessage('Failed asserting that the Crawler has a node matching selector "input[name="username"]" with attribute "value" of value "Fabien".');
3330

34-
return;
35-
}
36-
37-
$this->fail();
31+
$constraint->evaluate(new Crawler('<html><head><title>Bar'));
3832
}
3933
}

Tests/Test/Constraint/CrawlerSelectorExistsTest.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use PHPUnit\Framework\ExpectationFailedException;
1515
use PHPUnit\Framework\TestCase;
16-
use PHPUnit\Framework\TestFailure;
1716
use Symfony\Component\DomCrawler\Crawler;
1817
use Symfony\Component\DomCrawler\Test\Constraint\CrawlerSelectorExists;
1918

@@ -26,14 +25,9 @@ public function testConstraint()
2625
$constraint = new CrawlerSelectorExists('h1');
2726
$this->assertFalse($constraint->evaluate(new Crawler('<html><head><title>'), '', true));
2827

29-
try {
30-
$constraint->evaluate(new Crawler('<html><head><title>'));
31-
} catch (ExpectationFailedException $e) {
32-
$this->assertEquals("Failed asserting that the Crawler matches selector \"h1\".\n", TestFailure::exceptionToString($e));
28+
$this->expectException(ExpectationFailedException::class);
29+
$this->expectExceptionMessage('Failed asserting that the Crawler matches selector "h1".');
3330

34-
return;
35-
}
36-
37-
$this->fail();
31+
$constraint->evaluate(new Crawler('<html><head><title>'));
3832
}
3933
}

Tests/Test/Constraint/CrawlerSelectorTextContainsTest.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use PHPUnit\Framework\ExpectationFailedException;
1515
use PHPUnit\Framework\TestCase;
16-
use PHPUnit\Framework\TestFailure;
1716
use Symfony\Component\DomCrawler\Crawler;
1817
use Symfony\Component\DomCrawler\Test\Constraint\CrawlerSelectorTextContains;
1918

@@ -25,21 +24,25 @@ public function testConstraint()
2524
$this->assertTrue($constraint->evaluate(new Crawler('<html><head><title>Foobar'), '', true));
2625
$this->assertFalse($constraint->evaluate(new Crawler('<html><head><title>Bar'), '', true));
2726
$this->assertFalse($constraint->evaluate(new Crawler('<html><head></head><body>Bar'), '', true));
27+
}
28+
29+
public function testDoesNotMatchIfNodeTextIsNotExpectedValue()
30+
{
31+
$constraint = new CrawlerSelectorTextContains('title', 'Foo');
2832

29-
try {
30-
$constraint->evaluate(new Crawler('<html><head><title>Bar'));
33+
$this->expectException(ExpectationFailedException::class);
34+
$this->expectExceptionMessage('Failed asserting that the text "Bar" of the node matching selector "title" contains "Foo".');
3135

32-
$this->fail();
33-
} catch (ExpectationFailedException $e) {
34-
$this->assertEquals("Failed asserting that the text \"Bar\" of the node matching selector \"title\" contains \"Foo\".\n", TestFailure::exceptionToString($e));
35-
}
36+
$constraint->evaluate(new Crawler('<html><head><title>Bar'));
37+
}
38+
39+
public function testDoesNotMatchIfNodeDoesNotExist()
40+
{
41+
$constraint = new CrawlerSelectorTextContains('title', 'Foo');
3642

37-
try {
38-
$constraint->evaluate(new Crawler('<html><head></head><body>Bar'));
43+
$this->expectException(ExpectationFailedException::class);
44+
$this->expectExceptionMessage('Failed asserting that the Crawler has a node matching selector "title".');
3945

40-
$this->fail();
41-
} catch (ExpectationFailedException $e) {
42-
$this->assertEquals("Failed asserting that the Crawler has a node matching selector \"title\".\n", TestFailure::exceptionToString($e));
43-
}
46+
$constraint->evaluate(new Crawler('<html><head></head><body>Bar'));
4447
}
4548
}

Tests/Test/Constraint/CrawlerSelectorTextSameTest.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use PHPUnit\Framework\ExpectationFailedException;
1515
use PHPUnit\Framework\TestCase;
16-
use PHPUnit\Framework\TestFailure;
1716
use Symfony\Component\DomCrawler\Crawler;
1817
use Symfony\Component\DomCrawler\Test\Constraint\CrawlerSelectorTextSame;
1918

@@ -25,14 +24,9 @@ public function testConstraint()
2524
$this->assertTrue($constraint->evaluate(new Crawler('<html><head><title>Foo'), '', true));
2625
$this->assertFalse($constraint->evaluate(new Crawler('<html><head><title>Bar'), '', true));
2726

28-
try {
29-
$constraint->evaluate(new Crawler('<html><head><title>Bar'));
30-
} catch (ExpectationFailedException $e) {
31-
$this->assertEquals("Failed asserting that the Crawler has a node matching selector \"title\" with content \"Foo\".\n", TestFailure::exceptionToString($e));
27+
$this->expectException(ExpectationFailedException::class);
28+
$this->expectExceptionMessage('Failed asserting that the Crawler has a node matching selector "title" with content "Foo".');
3229

33-
return;
34-
}
35-
36-
$this->fail();
30+
$constraint->evaluate(new Crawler('<html><head><title>Bar'));
3731
}
3832
}

0 commit comments

Comments
 (0)