-
-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit testing #30
Comments
You need to call wait on the promise or manually tick the promise queue.
|
Can you tell me where? I tried changing the method to: /**
* Tests unit testing with callbacks.
*/
public function testFoo() {
$p = new FulfilledPromise("");
$me = $this;
$p->then(function() use ($me) {
$me->assertTrue(TRUE, "Foo promise returning method succeeded.");
print (sprintf("%s::%s line %s: Success callback executed\n", get_class($this), __FUNCTION__, __LINE__));
}, function() use ($me) {
$me->assertTrue(FALSE, "Foo promise returning method succeeded.");
print (sprintf("%s::%s line %s: Failure callback executed\n", get_class($this), __FUNCTION__, __LINE__));
});
$p->wait();
} but the problem remains. 1 test, 0 assertions |
Oh wow. I'm highly overcomplicating this. /**
* Tests unit testing with callbacks.
*/
public function testFoo() {
$p = new FulfilledPromise(TRUE);
$result = $p->then(function() {
return TRUE;
}, function() {
return FALSE;
})->wait();
$this->assertTrue($result, "Testing foo");
} Nm. :) |
And thank you, by the way. Appreciate the help. |
Hi,
I'm attempting to do some unit testing using a class that utilizes the promises library. Here's the general approach (in a file MyTest.php):
The test completes without any assertions occurring (at least, none whose output is recognized by the testing suite). It appears the callbacks execute after the unit test completes:
PHPUnit 5.2.9 by Sebastian Bergmann and contributors. Runtime: PHP 5.6.18 with Xdebug 2.3.3 Configuration: [excluded] . 1 / 1 (100%) Time: 154 ms, Memory: 5.25Mb OK (1 test, 0 assertions) MyTest::{closure} line 91: Success callback executed
Do you know of a decent approach to using PHPUnit with Guzzle promises?
The text was updated successfully, but these errors were encountered: