File tree Expand file tree Collapse file tree 4 files changed +24
-40
lines changed Expand file tree Collapse file tree 4 files changed +24
-40
lines changed Original file line number Diff line number Diff line change 14
14
namespace FOS \OAuthServerBundle \Document ;
15
15
16
16
use Doctrine \ODM \MongoDB \DocumentManager ;
17
- use Doctrine \ODM \MongoDB \DocumentRepository ;
18
17
use FOS \OAuthServerBundle \Model \ClientInterface ;
19
18
use FOS \OAuthServerBundle \Model \ClientManager as BaseClientManager ;
20
19
@@ -25,24 +24,14 @@ class ClientManager extends BaseClientManager
25
24
*/
26
25
protected $ dm ;
27
26
28
- /**
29
- * @var DocumentRepository
30
- */
31
- protected $ repository ;
32
-
33
27
/**
34
28
* @var string
35
29
*/
36
30
protected $ class ;
37
31
38
32
public function __construct (DocumentManager $ dm , $ class )
39
33
{
40
- // NOTE: bug in Doctrine, hinting DocumentRepository|ObjectRepository when only DocumentRepository is expected
41
- /** @var DocumentRepository $repository */
42
- $ repository = $ dm ->getRepository ($ class );
43
-
44
34
$ this ->dm = $ dm ;
45
- $ this ->repository = $ repository ;
46
35
$ this ->class = $ class ;
47
36
}
48
37
@@ -59,7 +48,7 @@ public function getClass()
59
48
*/
60
49
public function findClientBy (array $ criteria )
61
50
{
62
- return $ this ->repository ->findOneBy ($ criteria );
51
+ return $ this ->dm -> getRepository ( $ this -> class ) ->findOneBy ($ criteria );
63
52
}
64
53
65
54
/**
Original file line number Diff line number Diff line change 14
14
namespace FOS \OAuthServerBundle \Document ;
15
15
16
16
use Doctrine \ODM \MongoDB \DocumentManager ;
17
- use Doctrine \ODM \MongoDB \DocumentRepository ;
18
17
use FOS \OAuthServerBundle \Model \TokenInterface ;
19
18
use FOS \OAuthServerBundle \Model \TokenManager as BaseTokenManager ;
20
19
@@ -25,24 +24,14 @@ class TokenManager extends BaseTokenManager
25
24
*/
26
25
protected $ dm ;
27
26
28
- /**
29
- * @var DocumentRepository
30
- */
31
- protected $ repository ;
32
-
33
27
/**
34
28
* @var string
35
29
*/
36
30
protected $ class ;
37
31
38
32
public function __construct (DocumentManager $ dm , $ class )
39
33
{
40
- // NOTE: bug in Doctrine, hinting DocumentRepository|ObjectRepository when only DocumentRepository is expected
41
- /** @var DocumentRepository $repository */
42
- $ repository = $ dm ->getRepository ($ class );
43
-
44
34
$ this ->dm = $ dm ;
45
- $ this ->repository = $ repository ;
46
35
$ this ->class = $ class ;
47
36
}
48
37
@@ -59,7 +48,7 @@ public function getClass()
59
48
*/
60
49
public function findTokenBy (array $ criteria )
61
50
{
62
- return $ this ->repository ->findOneBy ($ criteria );
51
+ return $ this ->dm -> getRepository ( $ this -> class ) ->findOneBy ($ criteria );
63
52
}
64
53
65
54
/**
@@ -86,7 +75,7 @@ public function deleteToken(TokenInterface $token)
86
75
public function deleteExpired ()
87
76
{
88
77
$ result = $ this
89
- ->repository
78
+ ->dm -> getRepository ( $ this -> class )
90
79
->createQueryBuilder ()
91
80
->remove ()
92
81
->field ('expiresAt ' )->lt (time ())
Original file line number Diff line number Diff line change @@ -61,13 +61,6 @@ public function setUp()
61
61
;
62
62
$ this ->className = 'RandomClassName ' .\random_bytes (5 );
63
63
64
- $ this ->documentManager
65
- ->expects ($ this ->once ())
66
- ->method ('getRepository ' )
67
- ->with ($ this ->className )
68
- ->willReturn ($ this ->repository )
69
- ;
70
-
71
64
$ this ->instance = new ClientManager ($ this ->documentManager , $ this ->className );
72
65
73
66
parent ::setUp ();
@@ -76,7 +69,6 @@ public function setUp()
76
69
public function testConstructWillSetParameters ()
77
70
{
78
71
$ this ->assertAttributeSame ($ this ->documentManager , 'dm ' , $ this ->instance );
79
- $ this ->assertAttributeSame ($ this ->repository , 'repository ' , $ this ->instance );
80
72
$ this ->assertAttributeSame ($ this ->className , 'class ' , $ this ->instance );
81
73
}
82
74
@@ -92,6 +84,13 @@ public function testFindClientBy()
92
84
\random_bytes (5 ),
93
85
];
94
86
87
+ $ this ->documentManager
88
+ ->expects ($ this ->once ())
89
+ ->method ('getRepository ' )
90
+ ->with ($ this ->className )
91
+ ->willReturn ($ this ->repository )
92
+ ;
93
+
95
94
$ this ->repository
96
95
->expects ($ this ->once ())
97
96
->method ('findOneBy ' )
Original file line number Diff line number Diff line change @@ -65,13 +65,6 @@ public function setUp()
65
65
->getMock ()
66
66
;
67
67
68
- $ this ->documentManager
69
- ->expects ($ this ->once ())
70
- ->method ('getRepository ' )
71
- ->with ($ this ->className )
72
- ->willReturn ($ this ->repository )
73
- ;
74
-
75
68
$ this ->instance = new TokenManager ($ this ->documentManager , $ this ->className );
76
69
}
77
70
@@ -80,6 +73,13 @@ public function testFindTokenByToken()
80
73
$ randomToken = \random_bytes (5 );
81
74
$ randomResult = \random_bytes (5 );
82
75
76
+ $ this ->documentManager
77
+ ->expects ($ this ->once ())
78
+ ->method ('getRepository ' )
79
+ ->with ($ this ->className )
80
+ ->willReturn ($ this ->repository )
81
+ ;
82
+
83
83
$ this ->repository
84
84
->expects ($ this ->once ())
85
85
->method ('findOneBy ' )
@@ -145,6 +145,13 @@ public function testDeleteToken()
145
145
146
146
public function testDeleteExpired ()
147
147
{
148
+ $ this ->documentManager
149
+ ->expects ($ this ->once ())
150
+ ->method ('getRepository ' )
151
+ ->with ($ this ->className )
152
+ ->willReturn ($ this ->repository )
153
+ ;
154
+
148
155
$ queryBuilder = $ this ->getMockBuilder (Builder::class)
149
156
->disableOriginalConstructor ()
150
157
->getMock ()
You can’t perform that action at this time.
0 commit comments