55namespace RTCKit \React \Redlock ;
66
77use PHPUnit \Framework \TestCase ;
8- use React \EventLoop \Factory ;
8+ use React \EventLoop \Loop ;
99use React \Promise \PromiseInterface ;
1010use function React \Promise \resolve ;
1111
1414 */
1515class CustodianTest extends TestCase
1616{
17- private $ loop ;
1817 private $ client ;
1918
2019 /**
2120 * @before
2221 */
2322 public function setUpFactory ()
2423 {
25- $ this ->loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
2624 $ this ->client = $ this ->getMockBuilder ('Clue\React\Redis\Client ' )->getMock ();
2725 }
2826
2927 public function testConstructor ()
3028 {
31- $ custodian = new Custodian ($ this ->loop , $ this -> client );
29+ $ custodian = new Custodian ($ this ->client );
3230
3331 $ this ->assertNotNull ($ custodian );
3432 $ this ->assertInstanceOf (Custodian::class, $ custodian );
@@ -41,7 +39,7 @@ public function testSuccessfulAcquire()
4139 ->with ('set ' , ['resource ' , 'r4nd0m ' , 'NX ' , 'PX ' , 60000 ])
4240 ->willReturn (resolve ('OK ' ));
4341
44- $ custodian = new Custodian ($ this ->loop , $ this -> client );
42+ $ custodian = new Custodian ($ this ->client );
4543
4644 $ promise = $ custodian ->acquire ('resource ' , 60 , 'r4nd0m ' );
4745
@@ -64,7 +62,7 @@ public function testFailedAcquire()
6462 ->with ('set ' , ['2fail ' , 'r4nd0m ' , 'NX ' , 'PX ' , 60000 ])
6563 ->willReturn (resolve (null ));
6664
67- $ custodian = new Custodian ($ this ->loop , $ this -> client );
65+ $ custodian = new Custodian ($ this ->client );
6866
6967 $ promise = $ custodian ->acquire ('2fail ' , 60 , 'r4nd0m ' );
7068
@@ -82,7 +80,7 @@ public function testAcquireOptionalToken()
8280 ->method ('__call ' )
8381 ->willReturn (resolve ('OK ' ));
8482
85- $ custodian = new Custodian ($ this ->loop , $ this -> client );
83+ $ custodian = new Custodian ($ this ->client );
8684
8785 $ promise = $ custodian ->acquire ('resource ' , 60 );
8886
@@ -100,8 +98,6 @@ public function testAcquireOptionalToken()
10098
10199 public function testSuccessfulSpin ()
102100 {
103- $ loop = Factory::create ();
104-
105101 $ this ->client ->expects ($ this ->exactly (5 ))
106102 ->method ('__call ' )
107103 ->with ('set ' , ['resource ' , 'r4nd0m ' , 'NX ' , 'PX ' , 60000 ])
@@ -113,30 +109,28 @@ public function testSuccessfulSpin()
113109 resolve ('OK ' )
114110 );
115111
116- $ custodian = new Custodian ($ loop , $ this ->client );
112+ $ custodian = new Custodian ($ this ->client );
117113
118114 $ promise = $ custodian ->spin (5 , 0.000001 , 'resource ' , 60 , 'r4nd0m ' );
119115
120116 $ this ->assertNotNull ($ promise );
121117 $ this ->assertInstanceOf (PromiseInterface::class, $ promise );
122118
123- $ promise ->then (function (?Lock $ lock ) use ( $ loop ) {
119+ $ promise ->then (function (?Lock $ lock ) {
124120 $ this ->assertNotNull ($ lock );
125121 $ this ->assertInstanceOf (Lock::class, $ lock );
126122 $ this ->assertEquals ('resource ' , $ lock ->getResource ());
127123 $ this ->assertEquals (60 , $ lock ->getTTL ());
128124 $ this ->assertEquals ('r4nd0m ' , $ lock ->getToken ());
129125
130- $ loop -> stop ();
126+ Loop:: stop ();
131127 });
132128
133- $ loop -> run ();
129+ Loop:: run ();
134130 }
135131
136132 public function testFailedSpin ()
137133 {
138- $ loop = Factory::create ();
139-
140134 $ this ->client ->expects ($ this ->exactly (5 ))
141135 ->method ('__call ' )
142136 ->with ('set ' , ['resource ' , 'r4nd0m ' , 'NX ' , 'PX ' , 60000 ])
@@ -148,20 +142,20 @@ public function testFailedSpin()
148142 resolve (null )
149143 );
150144
151- $ custodian = new Custodian ($ loop , $ this ->client );
145+ $ custodian = new Custodian ($ this ->client );
152146
153147 $ promise = $ custodian ->spin (5 , 0.000001 , 'resource ' , 60 , 'r4nd0m ' );
154148
155149 $ this ->assertNotNull ($ promise );
156150 $ this ->assertInstanceOf (PromiseInterface::class, $ promise );
157151
158- $ promise ->then (function (?Lock $ lock ) use ( $ loop ) {
152+ $ promise ->then (function (?Lock $ lock ) {
159153 $ this ->assertNull ($ lock );
160154
161- $ loop -> stop ();
155+ Loop:: stop ();
162156 });
163157
164- $ loop -> run ();
158+ Loop:: run ();
165159 }
166160
167161 public function testSuccessfulRelease ()
@@ -172,7 +166,7 @@ public function testSuccessfulRelease()
172166 ->willReturn (resolve ('1 ' ));
173167
174168 $ lock = new Lock ('release ' , 60 , 'r4nd0m ' );
175- $ custodian = new Custodian ($ this ->loop , $ this -> client );
169+ $ custodian = new Custodian ($ this ->client );
176170
177171 $ promise = $ custodian ->release ($ lock );
178172
@@ -192,7 +186,7 @@ public function testFailedRelease()
192186 ->willReturn (resolve ('0 ' ));
193187
194188 $ lock = new Lock ('release ' , 60 , 'r4nd0m ' );
195- $ custodian = new Custodian ($ this ->loop , $ this -> client );
189+ $ custodian = new Custodian ($ this ->client );
196190
197191 $ promise = $ custodian ->release ($ lock );
198192
0 commit comments