From 204079a780db993b9392a08024945d08dd8cd0f0 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Thu, 1 Feb 2024 14:08:24 +0100 Subject: [PATCH] Add tests --- tests/_files/mock-object/ExtendableClass.php | 12 ++++++++++++ .../Framework/MockObject/Creation/CreateMockTest.php | 8 ++++++++ .../Framework/MockObject/Creation/CreateStubTest.php | 8 ++++++++ 3 files changed, 28 insertions(+) diff --git a/tests/_files/mock-object/ExtendableClass.php b/tests/_files/mock-object/ExtendableClass.php index 9a3150b74e1..e4c1e1c7137 100644 --- a/tests/_files/mock-object/ExtendableClass.php +++ b/tests/_files/mock-object/ExtendableClass.php @@ -11,6 +11,10 @@ class ExtendableClass { + public function __destruct() + { + } + public function doSomething(): bool { return $this->doSomethingElse(); @@ -20,4 +24,12 @@ public function doSomethingElse(): bool { return false; } + + final public function finalMethod(): void + { + } + + private function privateMethod(): void + { + } } diff --git a/tests/unit/Framework/MockObject/Creation/CreateMockTest.php b/tests/unit/Framework/MockObject/Creation/CreateMockTest.php index 08a0b18b9e0..2b322702cc0 100644 --- a/tests/unit/Framework/MockObject/Creation/CreateMockTest.php +++ b/tests/unit/Framework/MockObject/Creation/CreateMockTest.php @@ -16,6 +16,7 @@ use PHPUnit\Framework\MockObject\Generator\ClassIsEnumerationException; use PHPUnit\Framework\MockObject\Generator\ClassIsFinalException; use PHPUnit\Framework\MockObject\Generator\ClassIsReadonlyException; +use PHPUnit\Framework\MockObject\Generator\UnknownTypeException; use PHPUnit\Framework\TestCase; use PHPUnit\TestFixture\MockObject\AnInterface; use PHPUnit\TestFixture\MockObject\Enumeration; @@ -67,4 +68,11 @@ public function testCannotCreateMockObjectForEnumeration(): void $this->createMock(Enumeration::class); } + + public function testCannotCreateMockObjectForUnknownType(): void + { + $this->expectException(UnknownTypeException::class); + + $this->createMock('this\does\not\exist'); + } } diff --git a/tests/unit/Framework/MockObject/Creation/CreateStubTest.php b/tests/unit/Framework/MockObject/Creation/CreateStubTest.php index e1525e1d421..e6d056ef677 100644 --- a/tests/unit/Framework/MockObject/Creation/CreateStubTest.php +++ b/tests/unit/Framework/MockObject/Creation/CreateStubTest.php @@ -16,6 +16,7 @@ use PHPUnit\Framework\MockObject\Generator\ClassIsEnumerationException; use PHPUnit\Framework\MockObject\Generator\ClassIsFinalException; use PHPUnit\Framework\MockObject\Generator\ClassIsReadonlyException; +use PHPUnit\Framework\MockObject\Generator\UnknownTypeException; use PHPUnit\Framework\TestCase; use PHPUnit\TestFixture\MockObject\AnInterface; use PHPUnit\TestFixture\MockObject\Enumeration; @@ -67,4 +68,11 @@ public function testCannotCreateTestStubForEnumeration(): void $this->createStub(Enumeration::class); } + + public function testCannotCreateTestStubForUnknownType(): void + { + $this->expectException(UnknownTypeException::class); + + $this->createStub('this\does\not\exist'); + } }