66use PHPUnit \Framework \TestCase ;
77use Symfony \Component \BrowserKit \Client ;
88use Symfony \Component \BrowserKit \Response ;
9+ use Yoast \PHPUnitPolyfills \Polyfills \ExpectException ;
910
1011class ErrorHandlingTest extends TestCase
1112{
13+ use ExpectException;
14+
1215 /**
1316 * @var TestClient
1417 */
1518 private $ client ;
1619
17- protected function setUp ()
20+ /**
21+ * @before
22+ */
23+ protected function prepareClient ()
1824 {
1925 $ this ->client = new TestClient ();
2026 }
@@ -25,50 +31,45 @@ public function testGetClient()
2531 }
2632
2733 /**
28- * @expectedException \Behat\Mink\Exception\DriverException
29- * @expectedExceptionMessage Unable to access the response before visiting a page
30- *
3134 * Looks like we have to mark these tests as "legacy", otherwise we get deprecation errors.
3235 * Although the deprecations are handled, there's no way to avoid the deprecation message here.
3336 * @group legacy
3437 */
3538 public function testGetResponseHeaderWithoutVisit ()
3639 {
40+ $ this ->expectException ('\Behat\Mink\Exception\DriverException ' );
41+ $ this ->expectExceptionMessage ('Unable to access the response before visiting a page ' );
3742 $ this ->getDriver ()->getResponseHeaders ();
3843 }
3944
4045 /**
41- * @expectedException \Behat\Mink\Exception\DriverException
42- * @expectedExceptionMessage Unable to access the response content before visiting a page
43- *
4446 * Looks like we have to mark these tests as "legacy", otherwise we get deprecation errors.
4547 * Although the deprecations are handled, there's no way to avoid the deprecation message here.
4648 * @group legacy
4749 */
4850 public function testFindWithoutVisit ()
4951 {
52+ $ this ->expectException ('\Behat\Mink\Exception\DriverException ' );
53+ $ this ->expectExceptionMessage ('Unable to access the response content before visiting a page ' );
5054 $ this ->getDriver ()->find ('//html ' );
5155 }
5256
5357 /**
54- * @expectedException \Behat\Mink\Exception\DriverException
55- * @expectedExceptionMessage Unable to access the request before visiting a page
56- *
5758 * Looks like we have to mark these tests as "legacy", otherwise we get deprecation errors.
5859 * Although the deprecations are handled, there's no way to avoid the deprecation message here.
5960 * @group legacy
6061 */
6162 public function testGetCurrentUrlWithoutVisit ()
6263 {
64+ $ this ->expectException ('\Behat\Mink\Exception\DriverException ' );
65+ $ this ->expectExceptionMessage ('Unable to access the request before visiting a page ' );
6366 $ this ->getDriver ()->getCurrentUrl ();
6467 }
6568
66- /**
67- * @expectedException \Behat\Mink\Exception\DriverException
68- * @expectedExceptionMessage The selected node has an invalid form attribute (foo)
69- */
7069 public function testNotMatchingHtml5FormId ()
7170 {
71+ $ this ->expectException ('\Behat\Mink\Exception\DriverException ' );
72+ $ this ->expectExceptionMessage ('The selected node has an invalid form attribute (foo) ' );
7273 $ html = <<<'HTML'
7374<html>
7475<body>
@@ -87,12 +88,10 @@ public function testNotMatchingHtml5FormId()
8788 $ driver ->setValue ('//input[./@name="test"] ' , 'bar ' );
8889 }
8990
90- /**
91- * @expectedException \Behat\Mink\Exception\DriverException
92- * @expectedExceptionMessage The selected node has an invalid form attribute (foo)
93- */
9491 public function testInvalidHtml5FormId ()
9592 {
93+ $ this ->expectException ('\Behat\Mink\Exception\DriverException ' );
94+ $ this ->expectExceptionMessage ('The selected node has an invalid form attribute (foo) ' );
9695 $ html = <<<'HTML'
9796<html>
9897<body>
@@ -112,12 +111,10 @@ public function testInvalidHtml5FormId()
112111 $ driver ->setValue ('//input[./@name="test"] ' , 'bar ' );
113112 }
114113
115- /**
116- * @expectedException \Behat\Mink\Exception\DriverException
117- * @expectedExceptionMessage The selected node does not have a form ancestor.
118- */
119114 public function testManipulateInputWithoutForm ()
120115 {
116+ $ this ->expectException ('\Behat\Mink\Exception\DriverException ' );
117+ $ this ->expectExceptionMessage ('The selected node does not have a form ancestor. ' );
121118 $ html = <<<'HTML'
122119<html>
123120<body>
@@ -138,12 +135,10 @@ public function testManipulateInputWithoutForm()
138135 $ driver ->setValue ('//input[./@name="test"] ' , 'bar ' );
139136 }
140137
141- /**
142- * @expectedException \Behat\Mink\Exception\DriverException
143- * @expectedExceptionMessage Behat\Mink\Driver\BrowserKitDriver supports clicking on links and submit or reset buttons only. But "div" provided
144- */
145138 public function testClickOnUnsupportedElement ()
146139 {
140+ $ this ->expectException ('\Behat\Mink\Exception\DriverException ' );
141+ $ this ->expectExceptionMessage ('Behat\Mink\Driver\BrowserKitDriver supports clicking on links and submit or reset buttons only. But "div" provided ' );
147142 $ html = <<<'HTML'
148143<html>
149144<body>
0 commit comments