Skip to content

Commit

Permalink
Merge pull request #12 from clue-labs/block
Browse files Browse the repository at this point in the history
Use clue/block-react for blocking tests
  • Loading branch information
clue committed Sep 4, 2015
2 parents bae99b1 + 7e4c297 commit 384485c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 25 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
"react/event-loop": "0.3.*|0.4.*",
"react/promise": "~1.0|~2.0",
"ext-soap": "*"
},
"require-dev": {
"clue/block-react": "~0.3.0"
}
}
9 changes: 5 additions & 4 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Clue\React\Soap\Factory;
use Clue\React\Soap\Client;
use Clue\React\Soap\Proxy;
use Clue\React\Block;

class FunctionalTest extends TestCase
{
Expand All @@ -17,7 +18,7 @@ public function setUp()
$promise = $factory->createClient('http://www.thomas-bayer.com/axis2/services/BLZService?wsdl');

$this->expectPromiseResolve($promise);
$this->client = $this->waitForPromise($promise, $this->loop);
$this->client = Block\await($promise, $this->loop);
/* @var $client Client */
}

Expand All @@ -31,7 +32,7 @@ public function testBlzService()
$promise = $api->getBank(array('blz' => '12070000'));

$this->expectPromiseResolve($promise);
$result = $this->waitForPromise($promise, $this->loop);
$result = Block\await($promise, $this->loop);

$this->assertInternalType('object', $result);
}
Expand All @@ -45,7 +46,7 @@ public function testBlzServiceWithInvalidBlz()
$this->expectPromiseReject($promise);

$this->setExpectedException('Exception');
$this->waitForPromise($promise, $this->loop);
Block\await($promise, $this->loop);
}

public function testBlzServiceWithInvalidMethod()
Expand All @@ -57,6 +58,6 @@ public function testBlzServiceWithInvalidMethod()
$this->expectPromiseReject($promise);

$this->setExpectedException('Exception');
$this->waitForPromise($promise, $this->loop);
Block\await($promise, $this->loop);
}
}
22 changes: 1 addition & 21 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use React\Promise\PromiseInterface;
use React\EventLoop\LoopInterface;

require_once __DIR__ . '/../vendor/autoload.php';

class TestCase extends PHPUnit_Framework_TestCase
Expand Down Expand Up @@ -71,27 +72,6 @@ protected function expectPromiseReject($promise)

return $promise;
}

protected function waitForPromise(PromiseInterface $promise, LoopInterface $loop)
{
$fulfillment = null;
$value = null;

$promise->then(
function ($result) use (&$fulfillment, &$value) { $fulfillment = true; $value = $result; },
function ($error) use (&$fulfillment, &$value) { $fulfillment = false; $value = $error; }
);

while ($fulfillment === null) {
$loop->tick();
}

if (!$fulfillment) {
throw $value;
}

return $value;
}
}

class CallableStub
Expand Down

0 comments on commit 384485c

Please sign in to comment.