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,37 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromCreateMockAssignRector\Fixture;

use PHPUnit\Framework\TestCase;
use Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromCreateMockAssignRector\Source\SomeMockedClass;

final class OverrideExistingWrongType extends TestCase
{
public SomeMockedClass $someMock;

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

?>
-----
<?php

namespace Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromCreateMockAssignRector\Fixture;

use PHPUnit\Framework\TestCase;
use Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromCreateMockAssignRector\Source\SomeMockedClass;

final class OverrideExistingWrongType extends TestCase
{
public \PHPUnit\Framework\MockObject\MockObject $someMock;

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

?>
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ public function refactor(Node $node): ?Node
$hasChanged = false;

foreach ($node->getProperties() as $property) {
// already typed
if ($property->type instanceof Node) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should check if property->type already PHPUnit\Framework\MockObject\MockObject, then continue to next property, to avoid repetitive apply

I will create separate PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

continue;
}

if (count($property->props) !== 1) {
continue;
}
Expand Down