Skip to content

Commit e6449da

Browse files
authored
[12.x] Fix PendingRequest typehints for post, patch, put, delete (#54998)
* Update PendingRequest.php * other methods
1 parent ae4481f commit e6449da

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

src/Illuminate/Http/Client/PendingRequest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ public function head(string $url, $query = null)
794794
* Issue a POST request to the given URL.
795795
*
796796
* @param string $url
797-
* @param array $data
797+
* @param array|\JsonSerializable|\Illuminate\Contracts\Support\Arrayable $data
798798
* @return \Illuminate\Http\Client\Response
799799
*
800800
* @throws \Illuminate\Http\Client\ConnectionException
@@ -810,7 +810,7 @@ public function post(string $url, $data = [])
810810
* Issue a PATCH request to the given URL.
811811
*
812812
* @param string $url
813-
* @param array $data
813+
* @param array|\JsonSerializable|\Illuminate\Contracts\Support\Arrayable $data
814814
* @return \Illuminate\Http\Client\Response
815815
*
816816
* @throws \Illuminate\Http\Client\ConnectionException
@@ -826,7 +826,7 @@ public function patch(string $url, $data = [])
826826
* Issue a PUT request to the given URL.
827827
*
828828
* @param string $url
829-
* @param array $data
829+
* @param array|\JsonSerializable|\Illuminate\Contracts\Support\Arrayable $data
830830
* @return \Illuminate\Http\Client\Response
831831
*
832832
* @throws \Illuminate\Http\Client\ConnectionException
@@ -842,7 +842,7 @@ public function put(string $url, $data = [])
842842
* Issue a DELETE request to the given URL.
843843
*
844844
* @param string $url
845-
* @param array $data
845+
* @param array|\JsonSerializable|\Illuminate\Contracts\Support\Arrayable $data
846846
* @return \Illuminate\Http\Client\Response
847847
*
848848
* @throws \Illuminate\Http\Client\ConnectionException

tests/Http/HttpClientTest.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use Mockery as m;
3434
use OutOfBoundsException;
3535
use PHPUnit\Framework\AssertionFailedError;
36+
use PHPUnit\Framework\Attributes\DataProvider;
3637
use PHPUnit\Framework\TestCase;
3738
use Psr\Http\Message\RequestInterface;
3839
use Psr\Http\Message\ResponseInterface;
@@ -530,11 +531,12 @@ public function testCanSendFormData()
530531
});
531532
}
532533

533-
public function testCanSendArrayableFormData()
534+
#[DataProvider('methodsReceivingArrayableDataProvider')]
535+
public function testCanSendArrayableFormData(string $method)
534536
{
535537
$this->factory->fake();
536538

537-
$this->factory->asForm()->post('http://foo.com/form', new Fluent([
539+
$this->factory->asForm()->{$method}('http://foo.com/form', new Fluent([
538540
'name' => 'Taylor',
539541
'title' => 'Laravel Developer',
540542
]));
@@ -546,11 +548,12 @@ public function testCanSendArrayableFormData()
546548
});
547549
}
548550

549-
public function testCanSendJsonSerializableData()
551+
#[DataProvider('methodsReceivingArrayableDataProvider')]
552+
public function testCanSendJsonSerializableData(string $method)
550553
{
551554
$this->factory->fake();
552555

553-
$this->factory->asJson()->post('http://foo.com/form', new class implements JsonSerializable
556+
$this->factory->asJson()->{$method}('http://foo.com/form', new class implements JsonSerializable
554557
{
555558
public function jsonSerialize(): mixed
556559
{
@@ -568,11 +571,12 @@ public function jsonSerialize(): mixed
568571
});
569572
}
570573

571-
public function testPrefersJsonSerializableOverArrayableData()
574+
#[DataProvider('methodsReceivingArrayableDataProvider')]
575+
public function testPrefersJsonSerializableOverArrayableData(string $method)
572576
{
573577
$this->factory->fake();
574578

575-
$this->factory->asJson()->post('http://foo.com/form', new class implements JsonSerializable, Arrayable
579+
$this->factory->asJson()->{$method}('http://foo.com/form', new class implements JsonSerializable, Arrayable
576580
{
577581
public function jsonSerialize(): mixed
578582
{
@@ -3472,6 +3476,16 @@ public function testItCanCreatePendingRequest()
34723476

34733477
$this->assertInstanceOf(PendingRequest::class, $factory->createPendingRequest());
34743478
}
3479+
3480+
public static function methodsReceivingArrayableDataProvider()
3481+
{
3482+
return [
3483+
'patch' => ['patch'],
3484+
'put' => ['put'],
3485+
'post' => ['post'],
3486+
'delete' => ['delete'],
3487+
];
3488+
}
34753489
}
34763490

34773491
class CustomFactory extends Factory

0 commit comments

Comments
 (0)