Skip to content

Commit 4719bc9

Browse files
committed
no longer use the internal TestFailure class
1 parent bf71686 commit 4719bc9

19 files changed

+99
-221
lines changed

src/Symfony/Component/BrowserKit/Tests/Test/Constraint/BrowserCookieValueSameTest.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\BrowserKit\AbstractBrowser;
1817
use Symfony\Component\BrowserKit\Cookie;
1918
use Symfony\Component\BrowserKit\CookieJar;
@@ -31,15 +30,10 @@ public function testConstraint()
3130
$constraint = new BrowserCookieValueSame('foo', 'babar', false, '/path');
3231
$this->assertFalse($constraint->evaluate($browser, '', true));
3332

34-
try {
35-
$constraint->evaluate($browser);
36-
} catch (ExpectationFailedException $e) {
37-
$this->assertEquals("Failed asserting that the Browser has cookie \"foo\" with path \"/path\" with value \"babar\".\n", TestFailure::exceptionToString($e));
33+
$this->expectException(ExpectationFailedException::class);
34+
$this->expectExceptionMessage('Failed asserting that the Browser has cookie "foo" with path "/path" with value "babar".');
3835

39-
return;
40-
}
41-
42-
$this->fail();
36+
$constraint->evaluate($browser);
4337
}
4438

4539
private function getBrowser(): AbstractBrowser

src/Symfony/Component/BrowserKit/Tests/Test/Constraint/BrowserHasCookieTest.php

Lines changed: 9 additions & 23 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\BrowserKit\AbstractBrowser;
1817
use Symfony\Component\BrowserKit\Cookie;
1918
use Symfony\Component\BrowserKit\CookieJar;
@@ -31,45 +30,32 @@ public function testConstraint()
3130
$constraint = new BrowserHasCookie('bar');
3231
$this->assertFalse($constraint->evaluate($browser, '', true));
3332

34-
try {
35-
$constraint->evaluate($browser);
36-
} catch (ExpectationFailedException $e) {
37-
$this->assertEquals("Failed asserting that the Browser has cookie \"bar\".\n", TestFailure::exceptionToString($e));
33+
$this->expectException(ExpectationFailedException::class);
34+
$this->expectExceptionMessage('Failed asserting that the Browser has cookie "bar".');
3835

39-
return;
40-
}
41-
42-
$this->fail();
36+
$constraint->evaluate($browser);
4337
}
4438

4539
public function testConstraintWithWrongPath()
4640
{
4741
$browser = $this->getBrowser();
4842
$constraint = new BrowserHasCookie('foo', '/other');
49-
try {
50-
$constraint->evaluate($browser);
51-
} catch (ExpectationFailedException $e) {
52-
$this->assertEquals("Failed asserting that the Browser has cookie \"foo\" with path \"/other\".\n", TestFailure::exceptionToString($e));
5343

54-
return;
55-
}
44+
$this->expectException(ExpectationFailedException::class);
45+
$this->expectExceptionMessage('Failed asserting that the Browser has cookie "foo" with path "/other".');
5646

57-
$this->fail();
47+
$constraint->evaluate($browser);
5848
}
5949

6050
public function testConstraintWithWrongDomain()
6151
{
6252
$browser = $this->getBrowser();
6353
$constraint = new BrowserHasCookie('foo', '/path', 'example.org');
64-
try {
65-
$constraint->evaluate($browser);
66-
} catch (ExpectationFailedException $e) {
67-
$this->assertEquals("Failed asserting that the Browser has cookie \"foo\" with path \"/path\" for domain \"example.org\".\n", TestFailure::exceptionToString($e));
6854

69-
return;
70-
}
55+
$this->expectException(ExpectationFailedException::class);
56+
$this->expectExceptionMessage('Failed asserting that the Browser has cookie "foo" with path "/path" for domain "example.org".');
7157

72-
$this->fail();
58+
$constraint->evaluate($browser);
7359
}
7460

7561
private function getBrowser(): AbstractBrowser

src/Symfony/Component/Console/Tests/Tester/Constraint/CommandIsSuccessfulTest.php

Lines changed: 3 additions & 11 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\Console\Command\Command;
1817
use Symfony\Component\Console\Tester\Constraint\CommandIsSuccessful;
1918

@@ -35,16 +34,9 @@ public function testUnsuccessfulCommand(string $expectedException, int $exitCode
3534
{
3635
$constraint = new CommandIsSuccessful();
3736

38-
try {
39-
$constraint->evaluate($exitCode);
40-
} catch (ExpectationFailedException $e) {
41-
$this->assertStringContainsString('Failed asserting that the command is successful.', TestFailure::exceptionToString($e));
42-
$this->assertStringContainsString($expectedException, TestFailure::exceptionToString($e));
43-
44-
return;
45-
}
46-
47-
$this->fail();
37+
$this->expectException(ExpectationFailedException::class);
38+
$this->expectExceptionMessageMatches('/Failed asserting that the command is successful\..*'.$expectedException.'/s');
39+
$constraint->evaluate($exitCode);
4840
}
4941

5042
public static function providesUnsuccessful(): iterable

src/Symfony/Component/DomCrawler/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
}

src/Symfony/Component/DomCrawler/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
}

src/Symfony/Component/DomCrawler/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
}

src/Symfony/Component/DomCrawler/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
}

src/Symfony/Component/DomCrawler/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
}

src/Symfony/Component/DomCrawler/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
}

src/Symfony/Component/HttpFoundation/Tests/Test/Constraint/RequestAttributeValueSameTest.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\HttpFoundation\Request;
1817
use Symfony\Component\HttpFoundation\Test\Constraint\RequestAttributeValueSame;
1918

@@ -28,14 +27,9 @@ public function testConstraint()
2827
$constraint = new RequestAttributeValueSame('bar', 'foo');
2928
$this->assertFalse($constraint->evaluate($request, '', true));
3029

31-
try {
32-
$constraint->evaluate($request);
33-
} catch (ExpectationFailedException $e) {
34-
$this->assertEquals("Failed asserting that the Request has attribute \"bar\" with value \"foo\".\n", TestFailure::exceptionToString($e));
30+
$this->expectException(ExpectationFailedException::class);
31+
$this->expectExceptionMessage('Failed asserting that the Request has attribute "bar" with value "foo".');
3532

36-
return;
37-
}
38-
39-
$this->fail();
33+
$constraint->evaluate($request);
4034
}
4135
}

0 commit comments

Comments
 (0)