Skip to content
This repository was archived by the owner on Nov 20, 2025. It is now read-only.

Commit 9a09859

Browse files
mattkingshottNoelDeMartin
authored andcommitted
Add HTTP Client fake
1 parent feb0ace commit 9a09859

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/Fakes/HttpFake.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace NoelDeMartin\LaravelDusk\Fakes;
4+
5+
use Illuminate\Http\Client\Factory;
6+
7+
class HttpFake extends Factory
8+
{
9+
protected $config = [];
10+
11+
public function __construct(mixed $config = null)
12+
{
13+
$this->config = json_decode(json_encode($config), true);
14+
15+
parent::__construct(null);
16+
17+
if (! empty($this->config)) {
18+
parent::fake($this->config);
19+
}
20+
}
21+
22+
public function __sleep() : array
23+
{
24+
return [
25+
'recording',
26+
'recorded',
27+
'preventStrayRequests',
28+
'allowedStrayRequestUrls',
29+
'config',
30+
];
31+
}
32+
33+
public function __wakeup() : void
34+
{
35+
$this->stubCallbacks = collect();
36+
37+
if (! empty($this->config)) {
38+
parent::fake($this->config);
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)