@@ -44,27 +44,6 @@ protected function setUp(): void
4444 $ this ->ldapService = $ this ->createStub (HordeLdapService::class);
4545 }
4646
47- /**
48- * Create a stub of Horde_Ldap_Search without calling constructor/destructor
49- */
50- private function createSearchStub (): Horde_Ldap_Search
51- {
52- return $ this ->getMockBuilder (Horde_Ldap_Search::class)
53- ->disableOriginalConstructor ()
54- ->disableOriginalClone ()
55- ->getMock ();
56- }
57-
58- /**
59- * Create a stub of Horde_Ldap_Entry without calling constructor
60- */
61- private function createEntryStub (): Horde_Ldap_Entry
62- {
63- return $ this ->getMockBuilder (Horde_Ldap_Entry::class)
64- ->disableOriginalConstructor ()
65- ->getMock ();
66- }
67-
6847 public function testGetValueFromHordePerson (): void
6948 {
7049 $ ldapAdapter = $ this ->createStub (Horde_Ldap::class);
@@ -212,18 +191,23 @@ public function testGetAllInScope(): void
212191 $ ldapAdapter = $ this ->createStub (Horde_Ldap::class);
213192 $ ldapAdapter ->method ('findUserDN ' )->willReturn ('uid=alice,ou=users,dc=example,dc=com ' );
214193
215- $ search = $ this ->createSearchStub ();
216- $ search ->method ('count ' )->willReturn (1 );
194+ $ search = $ this ->getMockBuilder (Horde_Ldap_Search::class)
195+ ->disableOriginalConstructor ()
196+ ->disableOriginalClone ()
197+ ->getMock ();
198+ $ search ->expects ($ this ->once ())->method ('count ' )->willReturn (1 );
217199
218- $ entry = $ this ->createEntryStub ();
219- $ entry ->method ('getValues ' )->willReturn ([
200+ $ entry = $ this ->getMockBuilder (Horde_Ldap_Entry::class)
201+ ->disableOriginalConstructor ()
202+ ->getMock ();
203+ $ entry ->expects ($ this ->once ())->method ('getValues ' )->willReturn ([
220204 'cn ' => ['Alice ' ],
221205 'hordePrefhordeTheme ' => ['silver ' ],
222206 'hordePrefhordeLanguage ' => ['en_US ' ],
223207 'hordePrefimpLayout ' => ['wide ' ],
224208 ]);
225209
226- $ search ->method ('shiftEntry ' )->willReturn ($ entry );
210+ $ search ->expects ( $ this -> once ())-> method ('shiftEntry ' )->willReturn ($ entry );
227211 $ ldapAdapter ->method ('search ' )->willReturn ($ search );
228212
229213 $ this ->ldapService ->method ('getAdapter ' )->willReturn ($ ldapAdapter );
@@ -243,15 +227,20 @@ public function testGetAllInScopeEmpty(): void
243227 $ ldapAdapter = $ this ->createStub (Horde_Ldap::class);
244228 $ ldapAdapter ->method ('findUserDN ' )->willReturn ('uid=alice,ou=users,dc=example,dc=com ' );
245229
246- $ search = $ this ->createSearchStub ();
247- $ search ->method ('count ' )->willReturn (1 );
230+ $ search = $ this ->getMockBuilder (Horde_Ldap_Search::class)
231+ ->disableOriginalConstructor ()
232+ ->disableOriginalClone ()
233+ ->getMock ();
234+ $ search ->expects ($ this ->once ())->method ('count ' )->willReturn (1 );
248235
249- $ entry = $ this ->createEntryStub ();
250- $ entry ->method ('getValues ' )->willReturn ([
236+ $ entry = $ this ->getMockBuilder (Horde_Ldap_Entry::class)
237+ ->disableOriginalConstructor ()
238+ ->getMock ();
239+ $ entry ->expects ($ this ->once ())->method ('getValues ' )->willReturn ([
251240 'cn ' => ['Alice ' ],
252241 ]);
253242
254- $ search ->method ('shiftEntry ' )->willReturn ($ entry );
243+ $ search ->expects ( $ this -> once ())-> method ('shiftEntry ' )->willReturn ($ entry );
255244 $ ldapAdapter ->method ('search ' )->willReturn ($ search );
256245
257246 $ this ->ldapService ->method ('getAdapter ' )->willReturn ($ ldapAdapter );
@@ -267,12 +256,17 @@ public function testExistsTrue(): void
267256 $ ldapAdapter = $ this ->createStub (Horde_Ldap::class);
268257 $ ldapAdapter ->method ('findUserDN ' )->willReturn ('uid=alice,ou=users,dc=example,dc=com ' );
269258
270- $ search = $ this ->createSearchStub ();
271- $ search ->method ('count ' )->willReturn (1 );
259+ $ search = $ this ->getMockBuilder (Horde_Ldap_Search::class)
260+ ->disableOriginalConstructor ()
261+ ->disableOriginalClone ()
262+ ->getMock ();
263+ $ search ->expects ($ this ->once ())->method ('count ' )->willReturn (1 );
272264
273- $ entry = $ this ->createEntryStub ();
274- $ entry ->method ('getValue ' )->willReturn ('silver ' );
275- $ search ->method ('shiftEntry ' )->willReturn ($ entry );
265+ $ entry = $ this ->getMockBuilder (Horde_Ldap_Entry::class)
266+ ->disableOriginalConstructor ()
267+ ->getMock ();
268+ $ entry ->expects ($ this ->once ())->method ('getValue ' )->willReturn ('silver ' );
269+ $ search ->expects ($ this ->once ())->method ('shiftEntry ' )->willReturn ($ entry );
276270
277271 $ ldapAdapter ->method ('search ' )->willReturn ($ search );
278272
@@ -300,8 +294,11 @@ public function testAttributeNaming(): void
300294 $ ldapAdapter = $ this ->createStub (Horde_Ldap::class);
301295 $ ldapAdapter ->method ('findUserDN ' )->willReturn ('uid=alice,ou=users,dc=example,dc=com ' );
302296
303- $ search = $ this ->createSearchStub ();
304- $ search ->method ('count ' )->willReturn (0 );
297+ $ search = $ this ->getMockBuilder (Horde_Ldap_Search::class)
298+ ->disableOriginalConstructor ()
299+ ->disableOriginalClone ()
300+ ->getMock ();
301+ $ search ->expects ($ this ->once ())->method ('count ' )->willReturn (0 );
305302 $ ldapAdapter ->method ('search ' )->willReturn ($ search );
306303
307304 $ entry = $ this ->createMock (Horde_Ldap_Entry::class);
0 commit comments