Skip to content
This repository was archived by the owner on Jan 6, 2024. It is now read-only.

Commit 7cf87f6

Browse files
committed
Merge pull request #22 from php-http/fix_wrong_rejection_detection
Set state to rejected when the rejection callback is called
2 parents 0bd4f75 + 0482ade commit 7cf87f6

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

src/Guzzle6Promise.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ public function __construct(PromiseInterface $promise, RequestInterface $request
5555

5656
return $response;
5757
}, function ($reason) use ($request) {
58+
$this->state = self::REJECTED;
59+
5860
if ($reason instanceof HttplugException) {
59-
$this->state = self::REJECTED;
6061
$this->exception = $reason;
6162
} elseif ($reason instanceof GuzzleExceptions\GuzzleException) {
62-
$this->state = self::REJECTED;
6363
$this->exception = $this->handleException($reason, $request);
6464
} elseif ($reason instanceof \Exception) {
65-
throw new \RuntimeException('Invalid exception returned from Guzzle6', 0, $reason);
65+
$this->exception = new \RuntimeException('Invalid exception returned from Guzzle6', 0, $reason);
6666
} else {
67-
throw new \UnexpectedValueException('Reason returned from Guzzle6 must be an Exception', 0, $reason);
67+
$this->exception = new \UnexpectedValueException('Reason returned from Guzzle6 must be an Exception', 0, $reason);
6868
}
6969

7070
throw $this->exception;

tests/Guzzle6PromiseTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Http\Adapter\Tests;
4+
5+
use GuzzleHttp\Exception as GuzzleExceptions;
6+
use GuzzleHttp\Promise\RejectedPromise;
7+
use Http\Adapter\Guzzle6Promise;
8+
9+
/**
10+
* @author Márk Sági-Kazár <[email protected]>
11+
*/
12+
class Guzzle6PromiseTest extends \PHPUnit_Framework_TestCase
13+
{
14+
/**
15+
* @expectedException \Exception
16+
*/
17+
public function testNonDomainExceptionIsHandled()
18+
{
19+
$request = $this->prophesize('Psr\Http\Message\RequestInterface');
20+
$promise = new RejectedPromise(new \Exception());
21+
22+
$guzzlePromise = new Guzzle6Promise($promise, $request->reveal());
23+
24+
$guzzlePromise->wait();
25+
}
26+
}

0 commit comments

Comments
 (0)