Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 12 additions & 0 deletions tests/StubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions tests/_data/DummyAbstractClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

abstract class DummyAbstractClass
{
}