File tree 4 files changed +9
-45
lines changed
4 files changed +9
-45
lines changed Original file line number Diff line number Diff line change @@ -25,24 +25,14 @@ class ClientManager extends BaseClientManager
25
25
*/
26
26
protected $ em ;
27
27
28
- /**
29
- * @var EntityRepository
30
- */
31
- protected $ repository ;
32
-
33
28
/**
34
29
* @var string
35
30
*/
36
31
protected $ class ;
37
32
38
33
public function __construct (EntityManagerInterface $ em , $ class )
39
34
{
40
- // NOTE: bug in Doctrine, hinting EntityRepository|ObjectRepository when only EntityRepository is expected
41
- /** @var EntityRepository $repository */
42
- $ repository = $ em ->getRepository ($ class );
43
-
44
35
$ this ->em = $ em ;
45
- $ this ->repository = $ repository ;
46
36
$ this ->class = $ class ;
47
37
}
48
38
@@ -59,7 +49,7 @@ public function getClass()
59
49
*/
60
50
public function findClientBy (array $ criteria )
61
51
{
62
- return $ this ->repository ->findOneBy ($ criteria );
52
+ return $ this ->getRepository () ->findOneBy ($ criteria );
63
53
}
64
54
65
55
/**
@@ -79,4 +69,11 @@ public function deleteClient(ClientInterface $client)
79
69
$ this ->em ->remove ($ client );
80
70
$ this ->em ->flush ();
81
71
}
72
+
73
+ private function getRepository (): EntityRepository
74
+ {
75
+ $ repository = $ this ->em ->getRepository ($ this ->class );
76
+
77
+ return $ repository ;
78
+ }
82
79
}
Original file line number Diff line number Diff line change @@ -85,15 +85,9 @@ public function deleteExpired()
85
85
return $ qb ->getQuery ()->execute ();
86
86
}
87
87
88
- /**
89
- * @return EntityRepository
90
- */
91
- protected function getRepository (): EntityRepository
88
+ private function getRepository (): EntityRepository
92
89
{
93
90
$ repository = $ this ->em ->getRepository ($ this ->class );
94
- if (!($ repository instanceof EntityRepository)) {
95
- throw new \RuntimeException ('EntityRepository needed ' );
96
- }
97
91
98
92
return $ repository ;
99
93
}
Original file line number Diff line number Diff line change @@ -58,7 +58,6 @@ public function setUp()
58
58
$ this ->className = 'RandomClassName ' .\random_bytes (5 );
59
59
60
60
$ this ->entityManager
61
- ->expects ($ this ->once ())
62
61
->method ('getRepository ' )
63
62
->with ($ this ->className )
64
63
->willReturn ($ this ->repository )
@@ -72,7 +71,6 @@ public function setUp()
72
71
public function testConstructWillSetParameters ()
73
72
{
74
73
$ this ->assertAttributeSame ($ this ->entityManager , 'em ' , $ this ->instance );
75
- $ this ->assertAttributeSame ($ this ->repository , 'repository ' , $ this ->instance );
76
74
$ this ->assertAttributeSame ($ this ->className , 'class ' , $ this ->instance );
77
75
}
78
76
Original file line number Diff line number Diff line change @@ -227,29 +227,4 @@ public function testDeleteExpired()
227
227
228
228
$ this ->assertSame ($ randomResult , $ this ->instance ->deleteExpired ());
229
229
}
230
-
231
- public function testExceptionWithObjectRepository ()
232
- {
233
- $ this ->repository = $ this ->getMockBuilder (ObjectRepository::class)
234
- ->disableOriginalConstructor ()
235
- ->getMock ()
236
- ;
237
-
238
- $ this ->entityManager = $ this ->getMockBuilder (EntityManager::class)
239
- ->disableOriginalConstructor ()
240
- ->getMock ()
241
- ;
242
-
243
- $ this ->entityManager
244
- ->expects ($ this ->once ())
245
- ->method ('getRepository ' )
246
- ->with ($ this ->className )
247
- ->willReturn ($ this ->repository )
248
- ;
249
-
250
- $ this ->instance = new TokenManager ($ this ->entityManager , $ this ->className );
251
-
252
- $ this ->expectException (\RuntimeException::class);
253
- $ this ->instance ->findTokenBy ([]);
254
- }
255
230
}
You can’t perform that action at this time.
0 commit comments