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
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Rector\PHPUnit\Tests\PHPUnit120\Rector\Class_\PropertyCreateMockToCreateStubRector\Fixture;

use PHPUnit\Framework\TestCase;

abstract class SkipAbstractClass extends TestCase
{
private \PHPUnit\Framework\MockObject\MockObject $someMock;

protected function setUp(): void
{
$this->someMock = $this->createMock(\stdClass::class);
}

public function testThis()
{
$this->assertSame('...', $this->someMock);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Rector\PHPUnit\Tests\PHPUnit120\Rector\Class_\PropertyCreateMockToCreateStubRector\Fixture;

use PHPUnit\Framework\TestCase;

class AbstractSkipSomeClass extends TestCase
{
private \PHPUnit\Framework\MockObject\MockObject $someMock;

protected function setUp(): void
{
$this->someMock = $this->createMock(\stdClass::class);
}

public function testThis()
{
$this->assertSame('...', $this->someMock);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Rector\PHPUnit\Tests\PHPUnit120\Rector\Class_\PropertyCreateMockToCreateStubRector\Fixture;

use PHPUnit\Framework\TestCase;

class SkipSomeTestCase extends TestCase
{
private \PHPUnit\Framework\MockObject\MockObject $someMock;

protected function setUp(): void
{
$this->someMock = $this->createMock(\stdClass::class);
}

public function testThis()
{
$this->assertSame('...', $this->someMock);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ private function shouldSkipClass(Class_ $class): bool
return true;
}

// skip abstract/base test classes, as property can be mocked in child classes
if ($class->isAbstract()) {
return true;
}

if ($class->name instanceof Identifier) {
$shortClassName = $class->name->toString();
if (str_ends_with($shortClassName, 'TestCase') || str_starts_with($shortClassName, 'Abstract')) {
return true;
}
}

$setUpClassMethod = $class->getMethod(MethodName::SET_UP);

// the setup class method must be here, so we have a place where the createMock() is used
Expand Down
Loading