33
33
use Mockery as m ;
34
34
use OutOfBoundsException ;
35
35
use PHPUnit \Framework \AssertionFailedError ;
36
+ use PHPUnit \Framework \Attributes \DataProvider ;
36
37
use PHPUnit \Framework \TestCase ;
37
38
use Psr \Http \Message \RequestInterface ;
38
39
use Psr \Http \Message \ResponseInterface ;
@@ -530,11 +531,12 @@ public function testCanSendFormData()
530
531
});
531
532
}
532
533
533
- public function testCanSendArrayableFormData ()
534
+ #[DataProvider('methodsReceivingArrayableDataProvider ' )]
535
+ public function testCanSendArrayableFormData (string $ method )
534
536
{
535
537
$ this ->factory ->fake ();
536
538
537
- $ this ->factory ->asForm ()->post ('http://foo.com/form ' , new Fluent ([
539
+ $ this ->factory ->asForm ()->{ $ method } ('http://foo.com/form ' , new Fluent ([
538
540
'name ' => 'Taylor ' ,
539
541
'title ' => 'Laravel Developer ' ,
540
542
]));
@@ -546,11 +548,12 @@ public function testCanSendArrayableFormData()
546
548
});
547
549
}
548
550
549
- public function testCanSendJsonSerializableData ()
551
+ #[DataProvider('methodsReceivingArrayableDataProvider ' )]
552
+ public function testCanSendJsonSerializableData (string $ method )
550
553
{
551
554
$ this ->factory ->fake ();
552
555
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
554
557
{
555
558
public function jsonSerialize (): mixed
556
559
{
@@ -568,11 +571,12 @@ public function jsonSerialize(): mixed
568
571
});
569
572
}
570
573
571
- public function testPrefersJsonSerializableOverArrayableData ()
574
+ #[DataProvider('methodsReceivingArrayableDataProvider ' )]
575
+ public function testPrefersJsonSerializableOverArrayableData (string $ method )
572
576
{
573
577
$ this ->factory ->fake ();
574
578
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
576
580
{
577
581
public function jsonSerialize (): mixed
578
582
{
@@ -3472,6 +3476,16 @@ public function testItCanCreatePendingRequest()
3472
3476
3473
3477
$ this ->assertInstanceOf (PendingRequest::class, $ factory ->createPendingRequest ());
3474
3478
}
3479
+
3480
+ public static function methodsReceivingArrayableDataProvider ()
3481
+ {
3482
+ return [
3483
+ 'patch ' => ['patch ' ],
3484
+ 'put ' => ['put ' ],
3485
+ 'post ' => ['post ' ],
3486
+ 'delete ' => ['delete ' ],
3487
+ ];
3488
+ }
3475
3489
}
3476
3490
3477
3491
class CustomFactory extends Factory
0 commit comments