Skip to content

Commit 917eea9

Browse files
minor #58177 no longer use the internal TestFailure class (xabbuh)
This PR was merged into the 7.2 branch. Discussion ---------- no longer use the internal `TestFailure` class | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | | License | MIT The class was removed in PHPUnit 10. Commits ------- 4719bc920c no longer use the internal TestFailure class
2 parents 1740c7e + fe6d482 commit 917eea9

10 files changed

+41
-117
lines changed

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
}

Tests/Test/Constraint/ResponseCookieValueSameTest.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\Cookie;
1817
use Symfony\Component\HttpFoundation\Response;
1918
use Symfony\Component\HttpFoundation\Test\Constraint\ResponseCookieValueSame;
@@ -31,15 +30,10 @@ public function testConstraint()
3130
$constraint = new ResponseCookieValueSame('foo', 'babar', '/path');
3231
$this->assertFalse($constraint->evaluate($response, '', true));
3332

34-
try {
35-
$constraint->evaluate($response);
36-
} catch (ExpectationFailedException $e) {
37-
$this->assertEquals("Failed asserting that the Response 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 Response has cookie "foo" with path "/path" with value "babar".');
3835

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

4539
public function testCookieWithNullValueIsComparedAsEmptyString()

Tests/Test/Constraint/ResponseFormatSameTest.php

Lines changed: 6 additions & 17 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\Response;
1918
use Symfony\Component\HttpFoundation\Test\Constraint\ResponseFormatSame;
@@ -32,30 +31,20 @@ public function testConstraint()
3231
$this->assertTrue($constraint->evaluate(new Response('', 200, ['Content-Type' => 'application/vnd.myformat']), '', true));
3332
$this->assertFalse($constraint->evaluate(new Response(), '', true));
3433

35-
try {
36-
$constraint->evaluate(new Response('', 200, ['Content-Type' => 'application/ld+json']));
37-
} catch (ExpectationFailedException $e) {
38-
$this->assertStringContainsString("Failed asserting that the Response format is custom.\nHTTP/1.0 200 OK", TestFailure::exceptionToString($e));
34+
$this->expectException(ExpectationFailedException::class);
35+
$this->expectExceptionMessage("Failed asserting that the Response format is custom.\nHTTP/1.0 200 OK");
3936

40-
return;
41-
}
42-
43-
$this->fail();
37+
$constraint->evaluate(new Response('', 200, ['Content-Type' => 'application/ld+json']));
4438
}
4539

4640
public function testNullFormat()
4741
{
4842
$constraint = new ResponseFormatSame(new Request(), null);
4943
$this->assertTrue($constraint->evaluate(new Response(), '', true));
5044

51-
try {
52-
$constraint->evaluate(new Response('', 200, ['Content-Type' => 'application/ld+json']));
53-
} catch (ExpectationFailedException $e) {
54-
$this->assertStringContainsString("Failed asserting that the Response format is null.\nHTTP/1.0 200 OK", TestFailure::exceptionToString($e));
55-
56-
return;
57-
}
45+
$this->expectException(ExpectationFailedException::class);
46+
$this->expectExceptionMessage("Failed asserting that the Response format is null.\nHTTP/1.0 200 OK");
5847

59-
$this->fail();
48+
$constraint->evaluate(new Response('', 200, ['Content-Type' => 'application/ld+json']));
6049
}
6150
}

Tests/Test/Constraint/ResponseHasCookieTest.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\Cookie;
1817
use Symfony\Component\HttpFoundation\Response;
1918
use Symfony\Component\HttpFoundation\Test\Constraint\ResponseHasCookie;
@@ -29,14 +28,9 @@ public function testConstraint()
2928
$constraint = new ResponseHasCookie('bar');
3029
$this->assertFalse($constraint->evaluate($response, '', true));
3130

32-
try {
33-
$constraint->evaluate($response);
34-
} catch (ExpectationFailedException $e) {
35-
$this->assertEquals("Failed asserting that the Response has cookie \"bar\".\n", TestFailure::exceptionToString($e));
31+
$this->expectException(ExpectationFailedException::class);
32+
$this->expectExceptionMessage('Failed asserting that the Response has cookie "bar".');
3633

37-
return;
38-
}
39-
40-
$this->fail();
34+
$constraint->evaluate($response);
4135
}
4236
}

Tests/Test/Constraint/ResponseHasHeaderTest.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\Response;
1817
use Symfony\Component\HttpFoundation\Test\Constraint\ResponseHasHeader;
1918

@@ -26,14 +25,9 @@ public function testConstraint()
2625
$constraint = new ResponseHasHeader('X-Date');
2726
$this->assertFalse($constraint->evaluate(new Response(), '', true));
2827

29-
try {
30-
$constraint->evaluate(new Response());
31-
} catch (ExpectationFailedException $e) {
32-
$this->assertEquals("Failed asserting that the Response has header \"X-Date\".\n", TestFailure::exceptionToString($e));
28+
$this->expectException(ExpectationFailedException::class);
29+
$this->expectExceptionMessage('Failed asserting that the Response has header "X-Date".');
3330

34-
return;
35-
}
36-
37-
$this->fail();
31+
$constraint->evaluate(new Response());
3832
}
3933
}

Tests/Test/Constraint/ResponseHeaderSameTest.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\Response;
1817
use Symfony\Component\HttpFoundation\Test\Constraint\ResponseHeaderSame;
1918

@@ -26,14 +25,9 @@ public function testConstraint()
2625
$constraint = new ResponseHeaderSame('Cache-Control', 'public');
2726
$this->assertFalse($constraint->evaluate(new Response(), '', true));
2827

29-
try {
30-
$constraint->evaluate(new Response());
31-
} catch (ExpectationFailedException $e) {
32-
$this->assertEquals("Failed asserting that the Response has header \"Cache-Control\" with value \"public\".\n", TestFailure::exceptionToString($e));
28+
$this->expectException(ExpectationFailedException::class);
29+
$this->expectExceptionMessage('Failed asserting that the Response has header "Cache-Control" with value "public".');
3330

34-
return;
35-
}
36-
37-
$this->fail();
31+
$constraint->evaluate(new Response());
3832
}
3933
}

Tests/Test/Constraint/ResponseIsRedirectedTest.php

Lines changed: 5 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\HttpFoundation\Response;
1817
use Symfony\Component\HttpFoundation\Test\Constraint\ResponseIsRedirected;
1918

@@ -26,17 +25,10 @@ public function testConstraint()
2625
$this->assertTrue($constraint->evaluate(new Response('', 301), '', true));
2726
$this->assertFalse($constraint->evaluate(new Response(), '', true));
2827

29-
try {
30-
$constraint->evaluate(new Response('Body content'));
31-
} catch (ExpectationFailedException $e) {
32-
$exceptionMessage = TestFailure::exceptionToString($e);
33-
$this->assertStringContainsString("Failed asserting that the Response is redirected.\nHTTP/1.0 200 OK", $exceptionMessage);
34-
$this->assertStringContainsString('Body content', $exceptionMessage);
28+
$this->expectException(ExpectationFailedException::class);
29+
$this->expectExceptionMessageMatches('/Failed asserting that the Response is redirected.\nHTTP\/1.0 200 OK.+Body content/s');
3530

36-
return;
37-
}
38-
39-
$this->fail();
31+
$constraint->evaluate(new Response('Body content'));
4032
}
4133

4234
public function testReducedVerbosity()
@@ -45,9 +37,8 @@ public function testReducedVerbosity()
4537
try {
4638
$constraint->evaluate(new Response('Body content'));
4739
} catch (ExpectationFailedException $e) {
48-
$exceptionMessage = TestFailure::exceptionToString($e);
49-
$this->assertStringContainsString("Failed asserting that the Response is redirected.\nHTTP/1.0 200 OK", $exceptionMessage);
50-
$this->assertStringNotContainsString('Body content', $exceptionMessage);
40+
$this->assertStringContainsString("Failed asserting that the Response is redirected.\nHTTP/1.0 200 OK", $e->getMessage());
41+
$this->assertStringNotContainsString('Body content', $e->getMessage());
5142

5243
return;
5344
}

Tests/Test/Constraint/ResponseIsSuccessfulTest.php

Lines changed: 5 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\HttpFoundation\Response;
1817
use Symfony\Component\HttpFoundation\Test\Constraint\ResponseIsSuccessful;
1918

@@ -26,17 +25,10 @@ public function testConstraint()
2625
$this->assertTrue($constraint->evaluate(new Response(), '', true));
2726
$this->assertFalse($constraint->evaluate(new Response('', 404), '', true));
2827

29-
try {
30-
$constraint->evaluate(new Response('Response body', 404));
31-
} catch (ExpectationFailedException $e) {
32-
$exceptionMessage = TestFailure::exceptionToString($e);
33-
$this->assertStringContainsString("Failed asserting that the Response is successful.\nHTTP/1.0 404 Not Found", $exceptionMessage);
34-
$this->assertStringContainsString('Response body', $exceptionMessage);
28+
$this->expectException(ExpectationFailedException::class);
29+
$this->expectExceptionMessageMatches('/Failed asserting that the Response is successful.\nHTTP\/1.0 404 Not Found.+Response body/s');
3530

36-
return;
37-
}
38-
39-
$this->fail();
31+
$constraint->evaluate(new Response('Response body', 404));
4032
}
4133

4234
public function testReducedVerbosity()
@@ -46,9 +38,8 @@ public function testReducedVerbosity()
4638
try {
4739
$constraint->evaluate(new Response('Response body', 404));
4840
} catch (ExpectationFailedException $e) {
49-
$exceptionMessage = TestFailure::exceptionToString($e);
50-
$this->assertStringContainsString("Failed asserting that the Response is successful.\nHTTP/1.0 404 Not Found", $exceptionMessage);
51-
$this->assertStringNotContainsString('Response body', $exceptionMessage);
41+
$this->assertStringContainsString("Failed asserting that the Response is successful.\nHTTP/1.0 404 Not Found", $e->getMessage());
42+
$this->assertStringNotContainsString('Response body', $e->getMessage());
5243

5344
return;
5445
}

Tests/Test/Constraint/ResponseIsUnprocessableTest.php

Lines changed: 5 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\HttpFoundation\Response;
1817
use Symfony\Component\HttpFoundation\Test\Constraint\ResponseIsUnprocessable;
1918

@@ -26,17 +25,10 @@ public function testConstraint()
2625
$this->assertTrue($constraint->evaluate(new Response('', 422), '', true));
2726
$this->assertFalse($constraint->evaluate(new Response(), '', true));
2827

29-
try {
30-
$constraint->evaluate(new Response('Response body'));
31-
} catch (ExpectationFailedException $e) {
32-
$exceptionMessage = TestFailure::exceptionToString($e);
33-
$this->assertStringContainsString("Failed asserting that the Response is unprocessable.\nHTTP/1.0 200 OK", $exceptionMessage);
34-
$this->assertStringContainsString('Response body', $exceptionMessage);
28+
$this->expectException(ExpectationFailedException::class);
29+
$this->expectExceptionMessageMatches('/Failed asserting that the Response is unprocessable.\nHTTP\/1.0 200 OK.+Response body/s');
3530

36-
return;
37-
}
38-
39-
$this->fail();
31+
$constraint->evaluate(new Response('Response body'));
4032
}
4133

4234
public function testReducedVerbosity()
@@ -46,9 +38,8 @@ public function testReducedVerbosity()
4638
try {
4739
$constraint->evaluate(new Response('Response body'));
4840
} catch (ExpectationFailedException $e) {
49-
$exceptionMessage = TestFailure::exceptionToString($e);
50-
$this->assertStringContainsString("Failed asserting that the Response is unprocessable.\nHTTP/1.0 200 OK", $exceptionMessage);
51-
$this->assertStringNotContainsString('Response body', $exceptionMessage);
41+
$this->assertStringContainsString("Failed asserting that the Response is unprocessable.\nHTTP/1.0 200 OK", $e->getMessage());
42+
$this->assertStringNotContainsString('Response body', $e->getMessage());
5243

5344
return;
5445
}

Tests/Test/Constraint/ResponseStatusCodeSameTest.php

Lines changed: 5 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\HttpFoundation\Response;
1817
use Symfony\Component\HttpFoundation\Test\Constraint\ResponseStatusCodeSame;
1918

@@ -28,17 +27,11 @@ public function testConstraint()
2827
$this->assertTrue($constraint->evaluate(new Response('', 404), '', true));
2928

3029
$constraint = new ResponseStatusCodeSame(200);
31-
try {
32-
$constraint->evaluate(new Response('Response body', 404));
33-
} catch (ExpectationFailedException $e) {
34-
$exceptionMessage = TestFailure::exceptionToString($e);
35-
$this->assertStringContainsString("Failed asserting that the Response status code is 200.\nHTTP/1.0 404 Not Found", TestFailure::exceptionToString($e));
36-
$this->assertStringContainsString('Response body', $exceptionMessage);
3730

38-
return;
39-
}
31+
$this->expectException(ExpectationFailedException::class);
32+
$this->expectExceptionMessageMatches('/Failed asserting that the Response status code is 200.\nHTTP\/1.0 404 Not Found.+Response body/s');
4033

41-
$this->fail();
34+
$constraint->evaluate(new Response('Response body', 404));
4235
}
4336

4437
public function testReducedVerbosity()
@@ -48,9 +41,8 @@ public function testReducedVerbosity()
4841
try {
4942
$constraint->evaluate(new Response('Response body', 404));
5043
} catch (ExpectationFailedException $e) {
51-
$exceptionMessage = TestFailure::exceptionToString($e);
52-
$this->assertStringContainsString("Failed asserting that the Response status code is 200.\nHTTP/1.0 404 Not Found", TestFailure::exceptionToString($e));
53-
$this->assertStringNotContainsString('Response body', $exceptionMessage);
44+
$this->assertStringContainsString("Failed asserting that the Response status code is 200.\nHTTP/1.0 404 Not Found", $e->getMessage());
45+
$this->assertStringNotContainsString('Response body', $e->getMessage());
5446

5547
return;
5648
}

0 commit comments

Comments
 (0)