From 27617450e40073a876c9fb15e48307e2e6c5c874 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Thu, 3 Oct 2024 18:16:25 +0530 Subject: [PATCH] Replace expectException with try/catch --- tests/DomainTest.php | 57 ++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/tests/DomainTest.php b/tests/DomainTest.php index 28e3f59..b3db186 100755 --- a/tests/DomainTest.php +++ b/tests/DomainTest.php @@ -28,16 +28,25 @@ public function testEdgecaseDomains(): void public function testEdgecaseDomainsError(): void { - $this->expectException('Exception'); - $this->expectExceptionMessage("'http://httpmydomain.com' must be a valid domain or hostname"); - $domain = new Domain('http://httpmydomain.com'); + try { + $domain = new Domain('http://httpmydomain.com'); + $this->fail('Expected exception was not thrown'); + } catch (Exception $e) { + $this->assertEquals( + "'http://httpmydomain.com' must be a valid domain or hostname", + $e->getMessage() + ); + } } public function testEdgecaseDomainsError2(): void { - $this->expectException('Exception'); - $this->expectExceptionMessage("'https://httpmydomain.com' must be a valid domain or hostname"); - $domain = new Domain('https://httpmydomain.com'); + try { + $domain = new Domain('https://httpmydomain.com'); + $this->fail("Expected exception not thrown."); + } catch (Exception $e) { + $this->assertEquals("'https://httpmydomain.com' must be a valid domain or hostname", $e->getMessage()); + } } public function testExampleCoUk(): void @@ -186,30 +195,42 @@ public function testPrivateTLD(): void public function testHTTPException1(): void { - $this->expectException(Exception::class); - - new Domain('http://www.facbook.com'); + try { + new Domain('http://www.facbook.com'); + $this->fail('Expected exception was not thrown'); + } catch (Exception $e) { + $this->assertInstanceOf(Exception::class, $e); + } } public function testHTTPException2(): void { - $this->expectException(Exception::class); - - new Domain('http://facbook.com'); + try { + new Domain('http://facbook.com'); + $this->fail('Expected exception was not thrown'); + } catch (Exception $e) { + $this->assertInstanceOf(Exception::class, $e); + } } public function testHTTPSException1(): void { - $this->expectException(Exception::class); - - new Domain('https://www.facbook.com'); + try { + new Domain('https://www.facbook.com'); + $this->fail('Expected exception was not thrown'); + } catch (Exception $e) { + $this->assertInstanceOf(Exception::class, $e); + } } public function testHTTPSException2(): void { - $this->expectException(Exception::class); - - new Domain('https://facbook.com'); + try { + new Domain('https://facbook.com'); + $this->fail('Expected exception was not thrown'); + } catch (Exception $e) { + $this->assertInstanceOf(Exception::class, $e); + } } public function testExampleExampleCk(): void