13
13
14
14
use PHPUnit \Framework \ExpectationFailedException ;
15
15
use PHPUnit \Framework \TestCase ;
16
- use PHPUnit \Framework \TestFailure ;
17
16
use Symfony \Component \BrowserKit \AbstractBrowser ;
18
17
use Symfony \Component \BrowserKit \Cookie ;
19
18
use Symfony \Component \BrowserKit \CookieJar ;
@@ -31,45 +30,32 @@ public function testConstraint()
31
30
$ constraint = new BrowserHasCookie ('bar ' );
32
31
$ this ->assertFalse ($ constraint ->evaluate ($ browser , '' , true ));
33
32
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". ' );
38
35
39
- return ;
40
- }
41
-
42
- $ this ->fail ();
36
+ $ constraint ->evaluate ($ browser );
43
37
}
44
38
45
39
public function testConstraintWithWrongPath ()
46
40
{
47
41
$ browser = $ this ->getBrowser ();
48
42
$ 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 ));
53
43
54
- return ;
55
- }
44
+ $ this -> expectException (ExpectationFailedException::class) ;
45
+ $ this -> expectExceptionMessage ( ' Failed asserting that the Browser has cookie "foo" with path "/other". ' );
56
46
57
- $ this -> fail ( );
47
+ $ constraint -> evaluate ( $ browser );
58
48
}
59
49
60
50
public function testConstraintWithWrongDomain ()
61
51
{
62
52
$ browser = $ this ->getBrowser ();
63
53
$ 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 ));
68
54
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". ' );
71
57
72
- $ this -> fail ( );
58
+ $ constraint -> evaluate ( $ browser );
73
59
}
74
60
75
61
private function getBrowser (): AbstractBrowser
0 commit comments