From 7317f27b2caf5c1132183cf56022cf6746e7f455 Mon Sep 17 00:00:00 2001 From: Andrew Coulton Date: Fri, 11 Aug 2023 20:21:43 +0100 Subject: [PATCH] Move `expectException` to cover only the expected throwing method Make the timeout test more robust by moving the `expectException` call immediately before the method that is expected to throw (and after all the setup methods). This will provide better long-term confidence/guarantees that the test is working as expected and only throwing during the final `->getContent` call. --- tests/ChromeDriverConnectionTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/ChromeDriverConnectionTest.php b/tests/ChromeDriverConnectionTest.php index f6e1f17..d2cefc3 100644 --- a/tests/ChromeDriverConnectionTest.php +++ b/tests/ChromeDriverConnectionTest.php @@ -38,11 +38,12 @@ public function testTimeoutExceptionIfResponseBlocked() 'socketTimeout' => 1, ]; $this->driver = new ChromeDriver('http://localhost:9222', null, 'about:blank', $options); - $this->expectException(TimeoutException::class); $script = "confirm('Is the browser blocked? (yes, it is)');"; $this->driver->visit('about:blank'); $this->driver->evaluateScript($script); + // Content read is necessary to trigger timeout. + $this->expectException(TimeoutException::class); $this->driver->getContent(); }