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\Factory; |
||||
10 | use Zenstruck\Foundry\Proxy; |
||||
11 | use Zenstruck\Foundry\RepositoryProxy; |
||||
12 | use Zenstruck\Foundry\Test\Factories; |
||||
13 | use Zenstruck\Foundry\Tests\Fixtures\Entity\Category; |
||||
14 | use Zenstruck\Foundry\Tests\Fixtures\Entity\Post; |
||||
15 | use function Zenstruck\Foundry\create; |
||||
16 | use function Zenstruck\Foundry\create_many; |
||||
17 | use function Zenstruck\Foundry\faker; |
||||
18 | use function Zenstruck\Foundry\instantiate; |
||||
19 | use function Zenstruck\Foundry\instantiate_many; |
||||
20 | use function Zenstruck\Foundry\repository; |
||||
21 | |||||
22 | /** |
||||
23 | * @author Kevin Bond <[email protected]> |
||||
24 | */ |
||||
25 | final class FunctionsTest extends TestCase |
||||
26 | { |
||||
27 | use Factories; |
||||
28 | |||||
29 | /** |
||||
30 | * @test |
||||
31 | */ |
||||
32 | public function faker(): void |
||||
33 | { |
||||
34 | $this->assertIsString(faker()->name()); |
||||
35 | } |
||||
36 | |||||
37 | /** |
||||
38 | * @test |
||||
39 | */ |
||||
40 | public function instantiate(): void |
||||
41 | { |
||||
42 | $proxy = instantiate(Post::class, ['title' => 'title', 'body' => 'body']); |
||||
43 | |||||
44 | $this->assertInstanceOf(Post::class, $proxy->object()); |
||||
45 | $this->assertFalse($proxy->isPersisted()); |
||||
46 | $this->assertSame('title', $proxy->getTitle()); |
||||
0 ignored issues
–
show
The method
getTitle() does not exist on Zenstruck\Foundry\Proxy . Since you implemented __call , consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
47 | } |
||||
48 | |||||
49 | /** |
||||
50 | * @test |
||||
51 | */ |
||||
52 | public function instantiate_many(): void |
||||
53 | { |
||||
54 | $objects = instantiate_many(3, Category::class); |
||||
55 | |||||
56 | $this->assertCount(3, $objects); |
||||
57 | $this->assertInstanceOf(Category::class, $objects[0]->object()); |
||||
58 | $this->assertFalse($objects[0]->isPersisted()); |
||||
59 | } |
||||
60 | |||||
61 | /** |
||||
62 | * @test |
||||
63 | */ |
||||
64 | public function create(): void |
||||
65 | { |
||||
66 | $registry = $this->createMock(ManagerRegistry::class); |
||||
67 | $registry |
||||
68 | ->method('getManagerForClass') |
||||
69 | ->with(Category::class) |
||||
70 | ->willReturn($this->createMock(ObjectManager::class)) |
||||
71 | ; |
||||
72 | |||||
73 | Factory::configuration()->setManagerRegistry($registry); |
||||
74 | |||||
75 | $object = create(Category::class); |
||||
76 | |||||
77 | $this->assertInstanceOf(Proxy::class, $object); |
||||
78 | } |
||||
79 | |||||
80 | /** |
||||
81 | * @test |
||||
82 | */ |
||||
83 | public function create_many(): void |
||||
84 | { |
||||
85 | $registry = $this->createMock(ManagerRegistry::class); |
||||
86 | $registry |
||||
87 | ->method('getManagerForClass') |
||||
88 | ->with(Category::class) |
||||
89 | ->willReturn($this->createMock(ObjectManager::class)) |
||||
90 | ; |
||||
91 | |||||
92 | Factory::configuration()->setManagerRegistry($registry); |
||||
93 | |||||
94 | $objects = create_many(3, Category::class); |
||||
95 | |||||
96 | $this->assertCount(3, $objects); |
||||
97 | } |
||||
98 | |||||
99 | /** |
||||
100 | * @test |
||||
101 | */ |
||||
102 | public function repository(): void |
||||
103 | { |
||||
104 | $registry = $this->createMock(ManagerRegistry::class); |
||||
105 | $registry |
||||
106 | ->expects($this->once()) |
||||
107 | ->method('getRepository') |
||||
108 | ->with(Category::class) |
||||
109 | ->willReturn($this->createMock(ObjectRepository::class)) |
||||
110 | ; |
||||
111 | |||||
112 | Factory::configuration()->setManagerRegistry($registry); |
||||
113 | |||||
114 | $this->assertInstanceOf(RepositoryProxy::class, repository(new Category())); |
||||
115 | } |
||||
116 | } |
||||
117 |
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