Skip to content

Commit 0ffdc22

Browse files
committed
add test
1 parent 4cfd04b commit 0ffdc22

5 files changed

Lines changed: 103 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symplify\PHPStanRules\Tests\Rules\Doctrine\NoDocumentMockingRule\Fixture;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Symplify\PHPStanRules\Tests\Rules\Doctrine\NoDocumentMockingRule\Source\Entity\AbstractSomeEntity;
9+
use Symplify\PHPStanRules\Tests\Rules\Doctrine\NoDocumentMockingRule\Source\Entity\SomeEntity;
10+
11+
final class SomeAbstractEntityMocking extends TestCase
12+
{
13+
public function test()
14+
{
15+
$someMock = $this->createMock(AbstractSomeEntity::class);
16+
}
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symplify\PHPStanRules\Tests\Rules\Doctrine\NoDocumentMockingRule\Fixture;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Symplify\PHPStanRules\Tests\Rules\Doctrine\NoDocumentMockingRule\Source\Entity\SomeEntity;
9+
10+
final class SomeEntityMocking extends TestCase
11+
{
12+
public function test()
13+
{
14+
$someMock = $this->createMock(SomeEntity::class);
15+
}
16+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symplify\PHPStanRules\Tests\Rules\Doctrine\NoDocumentMockingRule;
6+
7+
use Iterator;
8+
use PHPStan\Reflection\ReflectionProvider;
9+
use PHPStan\Rules\Rule;
10+
use PHPStan\Testing\RuleTestCase;
11+
use PHPUnit\Framework\Attributes\DataProvider;
12+
use Symplify\PHPStanRules\Rules\Doctrine\NoGetRepositoryOnServiceRepositoryEntityRule;
13+
use Symplify\PHPStanRules\Tests\Rules\Doctrine\NoGetRepositoryOnServiceRepositoryEntityRule\Source\Repository\SomeServiceRepository;
14+
15+
final class NoDocumentMockingRuleTest extends RuleTestCase
16+
{
17+
/**
18+
* @param array<int, array<string|int>> $expectedErrorMessagesWithLines
19+
*/
20+
#[DataProvider('provideData')]
21+
public function testRule(string $filePath, array $expectedErrorMessagesWithLines): void
22+
{
23+
$this->analyse([$filePath], $expectedErrorMessagesWithLines);
24+
}
25+
26+
/**
27+
* @return Iterator<array<array<int, mixed>, mixed>>
28+
*/
29+
public static function provideData(): Iterator
30+
{
31+
$errorMessage = sprintf(NoGetRepositoryOnServiceRepositoryEntityRule::ERROR_MESSAGE, 'SomeEntity', SomeServiceRepository::class);
32+
yield [__DIR__ . '/Fixture/SomeEntityMocking.php', [[
33+
$errorMessage,
34+
14,
35+
]]];
36+
37+
yield [__DIR__ . '/Fixture/SomeAbstractEntityMocking.php', []];
38+
}
39+
40+
protected function getRule(): Rule
41+
{
42+
$reflectionProvider = self::getContainer()->getByType(ReflectionProvider::class);
43+
44+
return new NoGetRepositoryOnServiceRepositoryEntityRule($reflectionProvider);
45+
}
46+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Symplify\PHPStanRules\Tests\Rules\Doctrine\NoDocumentMockingRule\Source\Entity;
4+
5+
use Doctrine\ORM\Mapping as ORM;
6+
7+
/**
8+
* @ORM\Entity()
9+
*/
10+
abstract class AbstractSomeEntity
11+
{
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Symplify\PHPStanRules\Tests\Rules\Doctrine\NoDocumentMockingRule\Source\Entity;
4+
5+
use Doctrine\ORM\Mapping as ORM;
6+
7+
/**
8+
* @ORM\Entity()
9+
*/
10+
class SomeEntity
11+
{
12+
}

0 commit comments

Comments
 (0)