Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
72 lines (58 sloc) 1.62 KB
<?php
namespace Livewire\Testing\Concerns;
trait MakesCallsToComponent
{
public function emit($event, ...$parameters)
{
return $this->fireEvent($event, $parameters);
}
public function fireEvent($event, ...$parameters)
{
$this->sendMessage('fireEvent', [
'event' => $event,
'params' => $parameters,
]);
return $this;
}
public function call($method, ...$parameters)
{
return $this->runAction($method, ...$parameters);
}
public function runAction($method, ...$parameters)
{
$this->sendMessage('callMethod', [
'method' => $method,
'params' => $parameters,
'ref' => null,
]);
return $this;
}
public function set($name, $value = null)
{
return $this->updateProperty($name, $value);
}
public function updateProperty($name, $value = null)
{
if (is_array($name)) {
foreach ($name as $key => $value) {
$this->sendMessage('syncInput', [
'name' => $key,
'value' => $value,
]);
}
return $this;
}
$this->sendMessage('syncInput', [
'name' => $name,
'value' => $value,
]);
return $this;
}
public function sendMessage($message, $payload)
{
$this->lastResponse = $this->pretendWereSendingAComponentUpdateRequest($message, $payload);
if (! $this->lastResponse->exception) {
$this->updateComponent($this->lastResponse->original);
}
}
}
You can’t perform that action at this time.