summaryrefslogtreecommitdiff
path: root/server/vendor/guzzlehttp/promises/tests/RejectedPromiseTest.php
diff options
context:
space:
mode:
authorLoic GUEGAN <loic@Manzerbredes>2016-01-23 14:37:24 +0100
committerLoic GUEGAN <loic@Manzerbredes>2016-01-23 14:37:24 +0100
commit189f7a9ef4c6265dbac232e5c5685aebbbfc7c53 (patch)
treed397facc1e45cee4713ea95b0eaa4ffa9cbf0921 /server/vendor/guzzlehttp/promises/tests/RejectedPromiseTest.php
parent2984adf171c49940e683fa997e8cdc60fcf1d60b (diff)
parenta44cc1d2e3c0f147e91a5c052ac7fd879e34e706 (diff)
Merge branch 'develop' of github.com:manzerbredes/istic-openstack into develop
Diffstat (limited to 'server/vendor/guzzlehttp/promises/tests/RejectedPromiseTest.php')
-rw-r--r--server/vendor/guzzlehttp/promises/tests/RejectedPromiseTest.php143
1 files changed, 143 insertions, 0 deletions
diff --git a/server/vendor/guzzlehttp/promises/tests/RejectedPromiseTest.php b/server/vendor/guzzlehttp/promises/tests/RejectedPromiseTest.php
new file mode 100644
index 0000000..60f926e
--- /dev/null
+++ b/server/vendor/guzzlehttp/promises/tests/RejectedPromiseTest.php
@@ -0,0 +1,143 @@
+<?php
+namespace GuzzleHttp\Promise\Tests;
+
+use GuzzleHttp\Promise\Promise;
+use GuzzleHttp\Promise\RejectedPromise;
+
+/**
+ * @covers GuzzleHttp\Promise\RejectedPromise
+ */
+class RejectedPromiseTest extends \PHPUnit_Framework_TestCase
+{
+ public function testThrowsReasonWhenWaitedUpon()
+ {
+ $p = new RejectedPromise('foo');
+ $this->assertEquals('rejected', $p->getState());
+ try {
+ $p->wait(true);
+ $this->fail();
+ } catch (\Exception $e) {
+ $this->assertEquals('rejected', $p->getState());
+ $this->assertContains('foo', $e->getMessage());
+ }
+ }
+
+ public function testCannotCancel()
+ {
+ $p = new RejectedPromise('foo');
+ $p->cancel();
+ $this->assertEquals('rejected', $p->getState());
+ }
+
+ /**
+ * @expectedException \LogicException
+ * @exepctedExceptionMessage Cannot resolve a rejected promise
+ */
+ public function testCannotResolve()
+ {
+ $p = new RejectedPromise('foo');
+ $p->resolve('bar');
+ }
+
+ /**
+ * @expectedException \LogicException
+ * @exepctedExceptionMessage Cannot reject a rejected promise
+ */
+ public function testCannotReject()
+ {
+ $p = new RejectedPromise('foo');
+ $p->reject('bar');
+ }
+
+ public function testCanRejectWithSameValue()
+ {
+ $p = new RejectedPromise('foo');
+ $p->reject('foo');
+ }
+
+ public function testThrowsSpecificException()
+ {
+ $e = new \Exception();
+ $p = new RejectedPromise($e);
+ try {
+ $p->wait(true);
+ $this->fail();
+ } catch (\Exception $e2) {
+ $this->assertSame($e, $e2);
+ }
+ }
+
+ /**
+ * @expectedException \InvalidArgumentException
+ */
+ public function testCannotResolveWithPromise()
+ {
+ new RejectedPromise(new Promise());
+ }
+
+ public function testReturnsSelfWhenNoOnReject()
+ {
+ $p = new RejectedPromise('a');
+ $this->assertSame($p, $p->then());
+ }
+
+ public function testInvokesOnRejectedAsynchronously()
+ {
+ $p = new RejectedPromise('a');
+ $r = null;
+ $f = function ($reason) use (&$r) { $r = $reason; };
+ $p->then(null, $f);
+ $this->assertNull($r);
+ \GuzzleHttp\Promise\queue()->run();
+ $this->assertEquals('a', $r);
+ }
+
+ public function testReturnsNewRejectedWhenOnRejectedFails()
+ {
+ $p = new RejectedPromise('a');
+ $f = function () { throw new \Exception('b'); };
+ $p2 = $p->then(null, $f);
+ $this->assertNotSame($p, $p2);
+ try {
+ $p2->wait();
+ $this->fail();
+ } catch (\Exception $e) {
+ $this->assertEquals('b', $e->getMessage());
+ }
+ }
+
+ public function testWaitingIsNoOp()
+ {
+ $p = new RejectedPromise('a');
+ $p->wait(false);
+ }
+
+ public function testOtherwiseIsSugarForRejections()
+ {
+ $p = new RejectedPromise('foo');
+ $p->otherwise(function ($v) use (&$c) { $c = $v; });
+ \GuzzleHttp\Promise\queue()->run();
+ $this->assertSame('foo', $c);
+ }
+
+ public function testCanResolveThenWithSuccess()
+ {
+ $actual = null;
+ $p = new RejectedPromise('foo');
+ $p->otherwise(function ($v) {
+ return $v . ' bar';
+ })->then(function ($v) use (&$actual) {
+ $actual = $v;
+ });
+ \GuzzleHttp\Promise\queue()->run();
+ $this->assertEquals('foo bar', $actual);
+ }
+
+ public function testDoesNotTryToRejectTwiceDuringTrampoline()
+ {
+ $fp = new RejectedPromise('a');
+ $t1 = $fp->then(null, function ($v) { return $v . ' b'; });
+ $t1->resolve('why!');
+ $this->assertEquals('why!', $t1->wait());
+ }
+}