1 | <?php |
||
2 | |||
3 | namespace Zenstruck\Foundry\Tests\Unit; |
||
4 | |||
5 | use Doctrine\Persistence\ManagerRegistry; |
||
6 | use Doctrine\Persistence\ObjectManager; |
||
7 | use Doctrine\Persistence\ObjectRepository; |
||
8 | use PHPUnit\Framework\TestCase; |
||
0 ignored issues
–
show
|
|||
9 | use Zenstruck\Foundry\ChainManagerRegistry; |
||
10 | use Zenstruck\Foundry\Tests\Fixtures\Entity\Post; |
||
11 | |||
12 | final class ChainManagerRegistryTest extends TestCase |
||
13 | { |
||
14 | /** |
||
15 | * @test |
||
16 | */ |
||
17 | public function can_get_repository(): void |
||
18 | { |
||
19 | $managerRegistry1 = $this->createMock(ManagerRegistry::class); |
||
20 | $managerRegistry2 = $this->createMock(ManagerRegistry::class); |
||
21 | |||
22 | $managerRegistry2->expects($this->once())->method('getRepository')->willReturn( |
||
23 | $repository = $this->createMock(ObjectRepository::class) |
||
24 | ); |
||
25 | |||
26 | $chainManagerRegistry = new ChainManagerRegistry([$managerRegistry1, $managerRegistry2]); |
||
27 | |||
28 | $this->assertSame($repository, $chainManagerRegistry->getRepository(Post::class)); |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * @test |
||
33 | */ |
||
34 | public function throws_exception_if_repository_not_found(): void |
||
35 | { |
||
36 | $class = Post::class; |
||
37 | $this->expectException(\LogicException::class); |
||
38 | $this->expectExceptionMessage("Cannot find repository for class {$class}"); |
||
39 | |||
40 | $managerRegistry1 = $this->createMock(ManagerRegistry::class); |
||
41 | $managerRegistry2 = $this->createMock(ManagerRegistry::class); |
||
42 | |||
43 | $chainManagerRegistry = new ChainManagerRegistry([$managerRegistry1, $managerRegistry2]); |
||
44 | |||
45 | $chainManagerRegistry->getRepository($class); |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @test |
||
50 | */ |
||
51 | public function can_get_manager_from_class(): void |
||
52 | { |
||
53 | $managerRegistry1 = $this->createMock(ManagerRegistry::class); |
||
54 | $managerRegistry2 = $this->createMock(ManagerRegistry::class); |
||
55 | |||
56 | $managerRegistry2->expects($this->once())->method('getManagerForClass')->willReturn( |
||
57 | $objectManager = $this->createMock(ObjectManager::class) |
||
58 | ); |
||
59 | |||
60 | $chainManagerRegistry = new ChainManagerRegistry([$managerRegistry1, $managerRegistry2]); |
||
61 | |||
62 | $this->assertSame($objectManager, $chainManagerRegistry->getManagerForClass(Post::class)); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @test |
||
67 | */ |
||
68 | public function returns_null_if_no_manager_found(): void |
||
69 | { |
||
70 | $managerRegistry1 = $this->createMock(ManagerRegistry::class); |
||
71 | $managerRegistry2 = $this->createMock(ManagerRegistry::class); |
||
72 | |||
73 | $chainManagerRegistry = new ChainManagerRegistry([$managerRegistry1, $managerRegistry2]); |
||
74 | |||
75 | $this->assertNull($chainManagerRegistry->getManagerForClass(Post::class)); |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * @test |
||
80 | */ |
||
81 | public function can_get_managers(): void |
||
82 | { |
||
83 | $managerRegistry1 = $this->createMock(ManagerRegistry::class); |
||
84 | $managerRegistry2 = $this->createMock(ManagerRegistry::class); |
||
85 | |||
86 | $managerRegistry1->expects($this->once())->method('getManagers')->willReturn( |
||
87 | [$objectManager1 = $this->createMock(ObjectManager::class)] |
||
88 | ); |
||
89 | |||
90 | $managerRegistry2->expects($this->once())->method('getManagers')->willReturn( |
||
91 | [ |
||
92 | $objectManager2 = $this->createMock(ObjectManager::class), |
||
93 | $objectManager3 = $this->createMock(ObjectManager::class), |
||
94 | ] |
||
95 | ); |
||
96 | |||
97 | $chainManagerRegistry = new ChainManagerRegistry([$managerRegistry1, $managerRegistry2]); |
||
98 | |||
99 | $this->assertSame( |
||
100 | [$objectManager1, $objectManager2, $objectManager3], |
||
101 | $chainManagerRegistry->getManagers() |
||
102 | ); |
||
103 | } |
||
104 | } |
||
105 |
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