99
1010class AwaitTest extends TestCase
1111{
12- protected $ loop ;
13-
14- /**
15- * @before
16- */
17- public function setUpLoop ()
18- {
19- $ this ->loop = Loop::get ();
20- }
21-
2212 public function testAwaitOneRejected ()
2313 {
2414 $ promise = $ this ->createPromiseRejected (new \Exception ('test ' ));
2515
2616 $ this ->setExpectedException ('Exception ' , 'test ' );
27- React \Async \await ($ promise, $ this -> loop );
17+ React \Async \await ($ promise );
2818 }
2919
3020 public function testAwaitOneRejectedWithFalseWillWrapInUnexpectedValueException ()
@@ -36,7 +26,7 @@ public function testAwaitOneRejectedWithFalseWillWrapInUnexpectedValueException(
3626 $ promise = Promise \reject (false );
3727
3828 $ this ->setExpectedException ('UnexpectedValueException ' , 'Promise rejected with unexpected value of type bool ' );
39- React \Async \await ($ promise, $ this -> loop );
29+ React \Async \await ($ promise );
4030 }
4131
4232 public function testAwaitOneRejectedWithNullWillWrapInUnexpectedValueException ()
@@ -48,7 +38,7 @@ public function testAwaitOneRejectedWithNullWillWrapInUnexpectedValueException()
4838 $ promise = Promise \reject (null );
4939
5040 $ this ->setExpectedException ('UnexpectedValueException ' , 'Promise rejected with unexpected value of type NULL ' );
51- React \Async \await ($ promise, $ this -> loop );
41+ React \Async \await ($ promise );
5242 }
5343
5444 /**
@@ -59,7 +49,7 @@ public function testAwaitOneRejectedWithPhp7ErrorWillWrapInUnexpectedValueExcept
5949 $ promise = Promise \reject (new \Error ('Test ' , 42 ));
6050
6151 try {
62- React \Async \await ($ promise, $ this -> loop );
52+ React \Async \await ($ promise );
6353 $ this ->fail ();
6454 } catch (\UnexpectedValueException $ e ) {
6555 $ this ->assertEquals ('Promise rejected with unexpected Error: Test ' , $ e ->getMessage ());
@@ -74,7 +64,7 @@ public function testAwaitOneResolved()
7464 {
7565 $ promise = $ this ->createPromiseResolved (2 );
7666
77- $ this ->assertEquals (2 , React \Async \await ($ promise, $ this -> loop ));
67+ $ this ->assertEquals (2 , React \Async \await ($ promise ));
7868 }
7969
8070 public function testAwaitReturnsFulfilledValueWithoutGivingLoop ()
@@ -89,7 +79,7 @@ public function testAwaitOneInterrupted()
8979 $ promise = $ this ->createPromiseResolved (2 , 0.02 );
9080 $ this ->createTimerInterrupt (0.01 );
9181
92- $ this ->assertEquals (2 , React \Async \await ($ promise, $ this -> loop ));
82+ $ this ->assertEquals (2 , React \Async \await ($ promise ));
9383 }
9484
9585 public function testAwaitOneResolvesShouldNotCreateAnyGarbageReferences ()
@@ -101,7 +91,7 @@ public function testAwaitOneResolvesShouldNotCreateAnyGarbageReferences()
10191 gc_collect_cycles ();
10292
10393 $ promise = Promise \resolve (1 );
104- React \Async \await ($ promise, $ this -> loop );
94+ React \Async \await ($ promise );
10595 unset($ promise );
10696
10797 $ this ->assertEquals (0 , gc_collect_cycles ());
@@ -117,7 +107,7 @@ public function testAwaitOneRejectedShouldNotCreateAnyGarbageReferences()
117107
118108 $ promise = Promise \reject (new \RuntimeException ());
119109 try {
120- React \Async \await ($ promise, $ this -> loop );
110+ React \Async \await ($ promise );
121111 } catch (\Exception $ e ) {
122112 // no-op
123113 }
@@ -140,7 +130,7 @@ public function testAwaitNullValueShouldNotCreateAnyGarbageReferences()
140130
141131 $ promise = Promise \reject (null );
142132 try {
143- React \Async \await ($ promise, $ this -> loop );
133+ React \Async \await ($ promise );
144134 } catch (\Exception $ e ) {
145135 // no-op
146136 }
@@ -153,7 +143,7 @@ protected function createPromiseResolved($value = null, $delay = 0.01)
153143 {
154144 $ deferred = new Deferred ();
155145
156- $ this -> loop -> addTimer ($ delay , function () use ($ deferred , $ value ) {
146+ Loop:: addTimer ($ delay , function () use ($ deferred , $ value ) {
157147 $ deferred ->resolve ($ value );
158148 });
159149
@@ -164,7 +154,7 @@ protected function createPromiseRejected($value = null, $delay = 0.01)
164154 {
165155 $ deferred = new Deferred ();
166156
167- $ this -> loop -> addTimer ($ delay , function () use ($ deferred , $ value ) {
157+ Loop:: addTimer ($ delay , function () use ($ deferred , $ value ) {
168158 $ deferred ->reject ($ value );
169159 });
170160
@@ -173,9 +163,8 @@ protected function createPromiseRejected($value = null, $delay = 0.01)
173163
174164 protected function createTimerInterrupt ($ delay = 0.01 )
175165 {
176- $ loop = $ this ->loop ;
177- $ loop ->addTimer ($ delay , function () use ($ loop ) {
178- $ loop ->stop ();
166+ Loop::addTimer ($ delay , function () {
167+ Loop::stop ();
179168 });
180169 }
181170
0 commit comments