Skip to content

Commit 8a9a531

Browse files
authored
Add PHPDoc types to Testable (livewire#9219)
1 parent 241b5a4 commit 8a9a531

File tree

1 file changed

+103
-1
lines changed

1 file changed

+103
-1
lines changed

src/Features/SupportTesting/Testable.php

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ protected function __construct(
2626
protected ComponentState $lastState,
2727
) {}
2828

29+
/**
30+
* @param string $name
31+
* @param array $params
32+
* @param array $fromQueryString
33+
* @param array $cookies
34+
* @param array $headers
35+
*
36+
* @return static
37+
*/
2938
static function create($name, $params = [], $fromQueryString = [], $cookies = [], $headers = [])
3039
{
3140
$name = static::normalizeAndRegisterComponentName($name);
@@ -44,6 +53,11 @@ static function create($name, $params = [], $fromQueryString = [], $cookies = []
4453
return new static($requestBroker, $initialState);
4554
}
4655

56+
/**
57+
* @param string|array<string>|object $name
58+
*
59+
* @return string
60+
*/
4761
static function normalizeAndRegisterComponentName($name)
4862
{
4963
if (is_array($otherComponents = $name)) {
@@ -69,6 +83,11 @@ static function normalizeAndRegisterComponentName($name)
6983
return $name;
7084
}
7185

86+
/**
87+
* @param ?string $driver
88+
*
89+
* @return void
90+
*/
7291
static function actingAs(\Illuminate\Contracts\Auth\Authenticatable $user, $driver = null)
7392
{
7493
if (isset($user->wasRecentlyCreated) && $user->wasRecentlyCreated) {
@@ -84,21 +103,39 @@ function id() {
84103
return $this->lastState->getComponent()->getId();
85104
}
86105

106+
/**
107+
* @param string $key
108+
*/
87109
function get($key)
88110
{
89111
return data_get($this->lastState->getComponent(), $key);
90112
}
91113

114+
/**
115+
* @param bool $stripInitialData
116+
*
117+
* @return string
118+
*/
92119
function html($stripInitialData = false)
93120
{
94121
return $this->lastState->getHtml($stripInitialData);
95122
}
96123

124+
/**
125+
* @param string $name
126+
*
127+
* @return $this
128+
*/
97129
function updateProperty($name, $value = null)
98130
{
99131
return $this->set($name, $value);
100132
}
101133

134+
/**
135+
* @param array $values
136+
*
137+
* @return $this
138+
*/
102139
function fill($values)
103140
{
104141
foreach ($values as $name => $value) {
@@ -108,11 +145,21 @@ function fill($values)
108145
return $this;
109146
}
110147

148+
/**
149+
* @param string $name
150+
*
151+
* @return $this
152+
*/
111153
function toggle($name)
112154
{
113155
return $this->set($name, ! $this->get($name));
114156
}
115157

158+
/**
159+
* @param string|array<string mixed> $name
160+
*
161+
* @return $this
162+
*/
116163
function set($name, $value = null)
117164
{
118165
if (is_array($name)) {
@@ -126,6 +173,11 @@ function set($name, $value = null)
126173
return $this;
127174
}
128175

176+
/**
177+
* @param string $name
178+
*
179+
* @return $this
180+
*/
129181
function setProperty($name, $value)
130182
{
131183
if ($value instanceof \Illuminate\Http\UploadedFile) {
@@ -139,11 +191,21 @@ function setProperty($name, $value)
139191
return $this->update(updates: [$name => $value]);
140192
}
141193

194+
/**
195+
* @param string $method
196+
*
197+
* @return $this
198+
*/
142199
function runAction($method, ...$params)
143200
{
144201
return $this->call($method, ...$params);
145202
}
146203

204+
/**
205+
* @param string $method
206+
*
207+
* @return $this
208+
*/
147209
function call($method, ...$params)
148210
{
149211
if ($method === '$refresh') {
@@ -163,16 +225,28 @@ function call($method, ...$params)
163225
]);
164226
}
165227

228+
/**
229+
* @return $this
230+
*/
166231
function commit()
167232
{
168233
return $this->update();
169234
}
170235

236+
/**
237+
* @return $this
238+
*/
171239
function refresh()
172240
{
173241
return $this->update();
174242
}
175243

244+
/**
245+
* @param array $calls
246+
* @param array $updates
247+
*
248+
* @return $this
249+
*/
176250
function update($calls = [], $updates = [])
177251
{
178252
$newState = SubsequentRender::make(
@@ -188,7 +262,15 @@ function update($calls = [], $updates = [])
188262
return $this;
189263
}
190264

191-
/** @todo Move me outta here and into the file upload folder somehow... */
265+
/**
266+
* @todo Move me outta here and into the file upload folder somehow...
267+
*
268+
* @param string $name
269+
* @param array $files
270+
* @param bool $isMultiple
271+
*
272+
* @return $this
273+
*/
192274
function upload($name, $files, $isMultiple = false)
193275
{
194276
// This method simulates the calls Livewire's JavaScript
@@ -239,6 +321,9 @@ function upload($name, $files, $isMultiple = false)
239321
return $this;
240322
}
241323

324+
/**
325+
* @param string $key
326+
*/
242327
function viewData($key)
243328
{
244329
return $this->lastState->getView()->getData()[$key];
@@ -259,25 +344,37 @@ function invade()
259344
return \Livewire\invade($this->lastState->getComponent());
260345
}
261346

347+
/**
348+
* @return $this
349+
*/
262350
function dump()
263351
{
264352
dump($this->lastState->getHtml());
265353

266354
return $this;
267355
}
268356

357+
/**
358+
* @return void
359+
*/
269360
function dd()
270361
{
271362
dd($this->lastState->getHtml());
272363
}
273364

365+
/**
366+
* @return $this
367+
*/
274368
function tap($callback)
275369
{
276370
$callback($this);
277371

278372
return $this;
279373
}
280374

375+
/**
376+
* @param string $property
377+
*/
281378
function __get($property)
282379
{
283380
if ($property === 'effects') return $this->lastState->getEffects();
@@ -287,6 +384,11 @@ function __get($property)
287384
return $this->instance()->$property;
288385
}
289386

387+
/**
388+
* @param string $method
389+
*
390+
* @return $this
391+
*/
290392
function __call($method, $params)
291393
{
292394
if (static::hasMacro($method)) {

0 commit comments

Comments
 (0)