Skip to content

Commit cae80ef

Browse files
authored
Feature/bump react promise support (#61)
* chore(deps): bump support for react/promise [bump-react-promise-support] * chore(Php): Add ci tests for PHP 8.0 to 8.4 [bump-react-promise-support]
1 parent 1926fbb commit cae80ef

10 files changed

Lines changed: 34 additions & 19 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- 8080:80
1212
strategy:
1313
matrix:
14-
php-versions: [ '8.0', '8.1' ]
14+
php-versions: [ '8.0', '8.1', '8.2', '8.3', '8.4' ]
1515
composer-options: [ '--prefer-lowest', '']
1616
runs-on: ubuntu-latest
1717
steps:

Curl/CurlErrorException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99

1010
namespace evaisse\SimpleHttpBundle\Curl;
1111

12+
use Exception;
13+
1214
class CurlErrorException extends \RuntimeException
1315
{
14-
public function __construct($message="", $code=0, \Exception $previous=null) {
16+
public function __construct($message="", $code=0, ?Exception $previous=null) {
1517
parent::__construct($message,$code,$previous);
1618
}
1719
}

Curl/MultiManager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ class MultiManager implements CurlRequest
5757
* @param boolean $blocking Whether the execution should block until finished or wait until
5858
* the destructor is called to block
5959
*/
60-
public function __construct(EventDispatcherInterface $dispatcher=null,$blocking=true) {
60+
public function __construct(?EventDispatcherInterface $dispatcher = null, $blocking = true)
61+
{
6162
$this->dispatcher = $dispatcher;
6263
$this->handle = curl_multi_init();
6364
$this->blocking = $blocking;

Http/Exception/RequestException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class RequestException extends Exception
2626
* @param int $code error code
2727
* @param Exception $previous optionnal previous exception
2828
*/
29-
public function __construct(Request $request, $message = "", $code = 0, Exception $previous = null)
29+
public function __construct(Request $request, $message = "", $code = 0, ?Exception $previous = null)
3030
{
3131
parent::__construct($message, $code, $previous); // TODO: Change the autogenerated stub
3232
$this->setRequest($request);

Http/Statement.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,11 @@ public function onProgress(callable $callable)
427427
*/
428428
public function onFinish(callable $callable)
429429
{
430-
$this->getPromise()->always($callable);
430+
if (method_exists(object_or_class: $this->getPromise(), method: 'finally')) {
431+
$this->getPromise()->finally($callable);
432+
} else {
433+
$this->getPromise()->always($callable);
434+
}
431435
return $this;
432436
}
433437

Service/Helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function createCookieJar(?SessionInterface $session = null): SessionCooki
5858
* @param Kernel|null $client http client proxy to use
5959
* @return Helper given service list
6060
*/
61-
public function execute(array $servicesList, ?SessionCookieJar $cookieJar = null, Kernel $client = null): static
61+
public function execute(array $servicesList, ?SessionCookieJar $cookieJar = null, ?Kernel $client = null): static
6262
{
6363
$httpClient = $client ? $client : $this->httpKernel;
6464

Tests/Unit/AbstractTests.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public function __construct(?string $name = null, array $data = [], $dataName =
2424
}
2525

2626

27+
/**
28+
* @return array{0: Helper, 1: Kernel}
29+
*/
2730
protected function createContext()
2831
{
2932
$eventDispatcher = new EventDispatcher();

Tests/Unit/PromisesTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace evaisse\SimpleHttpBundle\Tests\Unit;
1010

11+
use React\Promise\Promise;
1112
use Symfony\Component\HttpKernel\Exception\HttpException;
1213

1314
class PromisesTest extends AbstractTests
@@ -37,11 +38,14 @@ public function testPromises($code, $expectedResults)
3738

3839
$events = new \ArrayObject();
3940

41+
$finallyMethod = method_exists(object_or_class: Promise::class, method: 'always') ? 'always' : 'finally';
42+
$catchMethod = method_exists(object_or_class: Promise::class, method: 'catch') ? 'catch' : 'otherwise';
43+
4044
$stmt->getPromise()->then(function () use ($events) {
4145
$events[] = 'success';
42-
})->otherwise(function () use ($events) {
46+
})->$catchMethod(function () use ($events) {
4347
$events[] = 'error';
44-
})->done(function () use ($events) {
48+
})->$finallyMethod(function () use ($events) {
4549
$events[] = 'done';
4650
});
4751

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"homepage": "https://github.com/evaisse/SimpleHttpBundle",
1515
"require": {
1616
"php": "^8.0",
17-
"react/promise": "^2.2",
17+
"react/promise": "^2.2 || ^3.0",
1818
"symfony/http-foundation": "^5.4 || ^6.0",
1919
"symfony/browser-kit": "^5.4 || ^6.0",
2020
"symfony/event-dispatcher": "^5.4 || ^6.0",

composer.lock

Lines changed: 11 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)