diff --git a/src/Stub.php b/src/Stub.php index d9ce9dd..b45be05 100644 --- a/src/Stub.php +++ b/src/Stub.php @@ -462,6 +462,10 @@ private static function doGenerateMock($args, $isAbstract = false) $methodName = $isAbstract ? 'getMockForAbstractClass' : 'getMock'; } + if ($isAbstract && version_compare(PHPUnitVersion::series(), '12', '>=')) { + throw new RuntimeException('PHPUnit 12 or greater does not allow to mock abstract classes anymore'); + } + // PHPUnit 10.3 changed the namespace if (version_compare(PHPUnitVersion::series(), '10.3', '>=')) { $generatorClass = new Generator(); diff --git a/tests/StubTest.php b/tests/StubTest.php index 3b947df..20eb7b5 100644 --- a/tests/StubTest.php +++ b/tests/StubTest.php @@ -19,6 +19,7 @@ final class StubTest extends TestCase public function setUp(): void { + require_once $file = __DIR__. '/_data/DummyAbstractClass.php'; require_once $file = __DIR__. '/_data/DummyOverloadableClass.php'; require_once $file = __DIR__. '/_data/DummyClass.php'; $this->dummy = new DummyClass(true); @@ -404,6 +405,17 @@ public function testStubMakeEmptyInterface() $stub = Stub::makeEmpty(Countable::class, ['count' => 5]); $this->assertEquals(5, $stub->count()); } + + public function testStubMakeEmptyAbstractClass() + { + if (version_compare(PHPUnitVersion::id(), '12', '>=')) { + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('PHPUnit 12 or greater does not allow to mock abstract classes anymore'); + } + + $stub = Stub::make('DummyAbstractClass'); + $this->assertInstanceOf('DummyAbstractClass', $stub); + } } class MyClassWithPrivateProperties diff --git a/tests/_data/DummyAbstractClass.php b/tests/_data/DummyAbstractClass.php new file mode 100644 index 0000000..bfbb928 --- /dev/null +++ b/tests/_data/DummyAbstractClass.php @@ -0,0 +1,7 @@ +