Monday, 15 August 2011

php - Testing async methods with PHPUnit -


I tried to use sleep and tried to approach but it sometimes fails what is the standard? Nothing can get clear around, thanks.

Function Fu ($ callback) {$ bar- & gt; AsyncCall ($ callback); } Function testFoo () {$ semaphore = 1; Fu (function () {$ semaphore = 0;}); $ Semaphore to sleep (5) == 0; }

With this approach testFoo () never returns sometimes. I suspect any deadlock.

By the way php scopes variable, you are not changing the same $ semaphore variable in your test You can change the foo (...) .

are creating a new variable in the anonymous method, you will need to mark var with the usage > keyword.

  function testFoo () {$ semaphore = 1; Use FU (function () ($ semaphore) {$ semaphore = 0;}); $ This- & gt; Emphasis value (0, $ semaphore); }  

There is no need for sleep, as we can see from here. More information will be needed on $ bar-> asynCall () . See more on the variable scope here:


No comments:

Post a Comment