1313
1414use PHPUnit \Framework \ExpectationFailedException ;
1515use PHPUnit \Framework \TestCase ;
16- use PHPUnit \Framework \TestFailure ;
1716use Symfony \Component \BrowserKit \AbstractBrowser ;
1817use Symfony \Component \BrowserKit \Cookie ;
1918use 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
0 commit comments