|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Zenstruck\Foundry\Tests\Unit\Proxy; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
6
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata; |
|
7
|
|
|
use Doctrine\ORM\UnitOfWork; |
|
8
|
|
|
use Doctrine\Persistence\ManagerRegistry; |
|
9
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
|
|
|
|
|
10
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
|
|
11
|
|
|
use Zenstruck\Foundry\Configuration; |
|
12
|
|
|
use Zenstruck\Foundry\Proxy\ProxyGenerator; |
|
13
|
|
|
use Zenstruck\Foundry\Tests\Fixtures\Entity\Tag; |
|
14
|
|
|
|
|
15
|
|
|
class ProxyGeneratorTest extends TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
/** @var EntityManagerInterface|MockObject */ |
|
18
|
|
|
private $objectManager; |
|
19
|
|
|
/** @var ManagerRegistry|MockObject */ |
|
20
|
|
|
private $managerRegistry; |
|
21
|
|
|
/** @var Configuration|MockObject */ |
|
22
|
|
|
private $config; |
|
23
|
|
|
/** @var ProxyGenerator */ |
|
24
|
|
|
private $generator; |
|
25
|
|
|
|
|
26
|
|
|
protected function setUp(): void |
|
27
|
|
|
{ |
|
28
|
|
|
$unitOfWork = $this->createMock(UnitOfWork::class); |
|
29
|
|
|
$unitOfWork->expects($this->any())->method('getEntityChangeSet')->willReturn([]); |
|
30
|
|
|
|
|
31
|
|
|
$this->objectManager = $this->createMock(EntityManagerInterface::class); |
|
32
|
|
|
$this->objectManager->expects($this->any())->method('contains')->willReturn(true); |
|
33
|
|
|
$this->objectManager->expects($this->any())->method('getClassMetadata')->willReturn($this->createMock(ClassMetadata::class)); |
|
34
|
|
|
$this->objectManager->expects($this->any())->method('getUnitOfWork')->willReturn($unitOfWork); |
|
35
|
|
|
|
|
36
|
|
|
$this->managerRegistry = $this->createMock(ManagerRegistry::class); |
|
37
|
|
|
|
|
38
|
|
|
$this->config = new Configuration(); |
|
39
|
|
|
$this->config->setManagerRegistry($this->managerRegistry); |
|
40
|
|
|
$this->generator = new ProxyGenerator($this->config); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** @test */ |
|
44
|
|
|
public function can_auto_refresh_all_methods(): void |
|
45
|
|
|
{ |
|
46
|
|
|
$tag = new Tag(); |
|
47
|
|
|
$this->managerRegistry->expects($this->any())->method('getManagerForClass')->with(Tag::class)->willReturn($this->objectManager); |
|
|
|
|
|
|
48
|
|
|
$proxyTag = $this->generator->generate($tag); |
|
49
|
|
|
|
|
50
|
|
|
$this->objectManager->expects($this->exactly(2))->method('refresh')->with($tag); |
|
|
|
|
|
|
51
|
|
|
$proxyTag->setName('proxy'); |
|
52
|
|
|
$this->assertEquals('proxy', $proxyTag->getName()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** @test */ |
|
56
|
|
|
public function can_only_auto_refresh_getters(): void |
|
57
|
|
|
{ |
|
58
|
|
|
$tag = new Tag(); |
|
59
|
|
|
$this->managerRegistry->expects($this->any())->method('getManagerForClass')->with(Tag::class)->willReturn($this->objectManager); |
|
60
|
|
|
$proxyTag = $this->generator->generate($tag, ['get*']); |
|
61
|
|
|
|
|
62
|
|
|
$this->objectManager->expects($this->once())->method('refresh')->with($tag); |
|
63
|
|
|
$proxyTag->setName('proxy'); |
|
64
|
|
|
$this->assertEquals('proxy', $proxyTag->getName()); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths