Skip to content
Closed
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
5 changes: 5 additions & 0 deletions src/Rules/Doctrine/NoDocumentMockingRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ private function shouldSkipDocumentClass(ConstantStringType $constantStringType)
if ($classReflection->isInterface()) {
return true;
}

// repositories live in the Entity/Document namespace too, but cannot be created directly
if ($classReflection->isSubclassOf('Doctrine\\Persistence\\ObjectRepository')) {
return true;
}
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace Doctrine\Bundle\DoctrineBundle\Repository;

use Doctrine\Persistence\ObjectRepository;

if (class_exists('Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository')) {
return;
}

abstract class ServiceEntityRepository
abstract class ServiceEntityRepository implements ObjectRepository
{
}
11 changes: 11 additions & 0 deletions stubs/Doctrine/Persistence/ObjectRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Doctrine\Persistence;

if (interface_exists('Doctrine\Persistence\ObjectRepository')) {
return;
}

interface ObjectRepository
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Symplify\PHPStanRules\Tests\Rules\Doctrine\NoDocumentMockingRule\Fixture;

use PHPUnit\Framework\TestCase;
use Symplify\PHPStanRules\Tests\Rules\Doctrine\NoDocumentMockingRule\Source\Entity\SomeRepository;

final class SomeRepositoryMocking extends TestCase
{
public function test()
{
$someMock = $this->createMock(SomeRepository::class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public static function provideData(): Iterator
]]];

yield [__DIR__ . '/Fixture/SomeAbstractEntityMocking.php', []];

yield [__DIR__ . '/Fixture/SomeRepositoryMocking.php', []];
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Symplify\PHPStanRules\Tests\Rules\Doctrine\NoDocumentMockingRule\Source\Entity;

use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;

final class SomeRepository extends ServiceEntityRepository
{
}
Loading