-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathMocksForge.php
More file actions
133 lines (114 loc) · 4.05 KB
/
MocksForge.php
File metadata and controls
133 lines (114 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
namespace Tests;
use Illuminate\Support\Collection;
use Laravel\Forge\Forge;
use Laravel\Forge\Resources\PHPVersion;
use Laravel\Forge\Resources\Server;
use Laravel\Forge\Resources\Site;
use Laravel\Forge\Resources\Worker;
use Mockery;
trait MocksForge
{
protected $forge;
protected Collection $forgeServers;
protected Collection $forgeSites;
protected Collection $forgePhpVersions;
protected Collection $forgeWorkers;
protected function mockForge(): void
{
foreach (['Servers', 'Sites', 'PhpVersions', 'Workers'] as $resource) {
$this->{"forge{$resource}"} = new Collection;
}
$this->forge = $this->mock(Forge::class);
$this->forge->shouldReceive('server')->andReturnUsing(
fn ($id) => $this->forgeServers->firstWhere('id', $id)
);
$this->forge->shouldReceive('site')->andReturnUsing(
fn ($server, $site) => $this->forgeSites->firstWhere('id', $site)
);
$this->forge->shouldReceive('phpVersions')->andReturnUsing(
fn ($server) => $this->forgePhpVersions->toArray() // @todo differentiate by server?
);
$this->forge->shouldReceive('workers')->andReturnUsing(
fn ($server, $site) => $this->forgeWorkers->toArray() // @todo differentiate by server?
);
$this->forge->shouldReceive('siteDeploymentScript')->andReturnUsing(
fn ($server, $site) => ''
);
$this->forge->shouldReceive('webhooks')->andReturnUsing(
fn ($server, $site) => []
);
$this->forge->shouldReceive('daemons')->andReturnUsing(
fn ($server) => []
);
}
protected function withForgeServer(array $attributes = []): static
{
$this->forgeServers->push(
$this->app->make(Server::class, [
'attributes' => array_merge([
'id' => $this->forgeServers->count() + 1,
], $attributes),
])
);
return $this;
}
protected function withForgeSite(array $attributes = []): static
{
$this->forgeSites->push(
$this->app->make(Site::class, [
'attributes' => array_merge([
'id' => $this->forgeSites->count() + 1,
'server_id' => $this->forgeServers->last()->id,
], $attributes),
])
);
return $this;
}
protected function withForgePhpVersion(array $attributes = []): static
{
$this->forgePhpVersions->push(
$this->app->make(PHPVersion::class, [
'attributes' => array_merge([
'id' => $this->forgePhpVersions->count() + 1,
'version' => 'php80',
'used_as_default' => false,
'used_on_cli' => false,
], $attributes),
])
);
return $this;
}
protected function withForgeWorker(array $attributes = []): static
{
$this->forgeWorkers->push(
$this->app->make(Worker::class, [
'attributes' => array_merge([
'id' => $this->forgeWorkers->count() + 1,
'command' => 'php8.0 /home/forge',
'queue' => 'default',
'connection' => 'redis',
'daemon' => 0,
'timeout' => 60,
'processes' => 1,
'sleep' => 10,
'delay' => 0,
'tries' => null,
'environment' => null,
'force' => 0,
], $attributes),
])
);
return $this;
}
public function shouldCreateForgeWorker(array $attributes = []): static
{
$this->forge->expects()->createWorker(Mockery::any(), Mockery::any(), $attributes);
return $this;
}
public function shouldDeleteForgeWorker(int $id): static
{
$this->forge->expects()->deleteWorker(Mockery::any(), Mockery::any(), $id);
return $this;
}
}