1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Zenstruck\Foundry\Tests\Unit; |
4
|
|
|
|
5
|
|
|
use Doctrine\Persistence\ManagerRegistry; |
6
|
|
|
use Doctrine\Persistence\ObjectManager; |
7
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
|
|
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
9
|
|
|
use Zenstruck\Foundry\Configuration; |
10
|
|
|
use Zenstruck\Foundry\ProxyGenerator; |
11
|
|
|
use Zenstruck\Foundry\Tests\Fixtures\Entity\Post; |
12
|
|
|
use Zenstruck\Foundry\Tests\Fixtures\Entity\Tag; |
13
|
|
|
|
14
|
|
|
class ProxyGeneratorTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
/** @var ObjectManager|MockObject */ |
17
|
|
|
private $objectManager; |
18
|
|
|
/** @var ManagerRegistry|MockObject */ |
19
|
|
|
private $managerRegistry; |
20
|
|
|
/** @var Configuration|MockObject */ |
21
|
|
|
private $config; |
22
|
|
|
/** @var ProxyGenerator */ |
23
|
|
|
private $generator; |
24
|
|
|
|
25
|
|
|
protected function setUp(): void |
26
|
|
|
{ |
27
|
|
|
$this->objectManager = $this->createMock(ObjectManager::class); |
28
|
|
|
$this->managerRegistry = $this->createMock(ManagerRegistry::class); |
29
|
|
|
$this->config = new Configuration(); |
30
|
|
|
$this->config->setManagerRegistry($this->managerRegistry); |
31
|
|
|
$this->generator = new ProxyGenerator($this->config); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** @test */ |
35
|
|
|
public function can_auto_refresh_all_methods(): void |
36
|
|
|
{ |
37
|
|
|
$tag = new Tag(); |
38
|
|
|
$this->managerRegistry->expects($this->any())->method('getManagerForClass')->with(Tag::class)->willReturn($this->objectManager); |
|
|
|
|
39
|
|
|
$proxyTag = $this->generator->generate($tag); |
40
|
|
|
|
41
|
|
|
$this->objectManager->expects($this->exactly(2))->method('refresh')->with($tag); |
|
|
|
|
42
|
|
|
$proxyTag->setName('proxy'); |
43
|
|
|
$this->assertEquals('proxy', $proxyTag->getName()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** @test */ |
47
|
|
|
public function can_only_auto_refresh_getters(): void |
48
|
|
|
{ |
49
|
|
|
$tag = new Tag(); |
50
|
|
|
$this->managerRegistry->expects($this->any())->method('getManagerForClass')->with(Tag::class)->willReturn($this->objectManager); |
51
|
|
|
$proxyTag = $this->generator->generate($tag, ['get*']); |
52
|
|
|
|
53
|
|
|
$this->objectManager->expects($this->once())->method('refresh')->with($tag); |
54
|
|
|
$proxyTag->setName('proxy'); |
55
|
|
|
$this->assertEquals('proxy', $proxyTag->getName()); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
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