1
0
Fork 0
mirror of synced 2024-05-20 20:52:36 +12:00

Reset event after trigger

This commit is contained in:
Eldad Fux 2020-07-04 16:06:23 +03:00
parent 154d281fec
commit c3c6a5fea0
2 changed files with 30 additions and 4 deletions

View file

@ -27,7 +27,7 @@ class Event
* @param string $queue
* @param string $class
*/
public function __construct($queue, $class)
public function __construct(string $queue, string $class)
{
$this->queue = $queue;
$this->class = $class;
@ -39,7 +39,7 @@ class Event
*
* @return $this
*/
public function setParam($key, $value)
public function setParam(string $key, $value): self
{
$this->params[$key] = $value;
@ -51,7 +51,7 @@ class Event
*
* @return mixed|null
*/
public function getParam($key)
public function getParam(string $key)
{
return (isset($this->params[$key])) ? $this->params[$key] : null;
}
@ -59,8 +59,17 @@ class Event
/**
* Execute Event.
*/
public function trigger()
public function trigger(): void
{
Resque::enqueue($this->queue, $this->class, $this->params);
$this->reset();
}
public function reset(): self
{
$this->params = [];
return $this;
}
}

View file

@ -46,4 +46,21 @@ class EventTest extends TestCase
$this->assertEquals(null, $this->object->getParam('key3'));
$this->assertEquals(\Resque::size($this->queue), 1);
}
public function testReset()
{
$this->object
->setParam('key1', 'value1')
->setParam('key2', 'value2')
;
$this->assertEquals('value1', $this->object->getParam('key1'));
$this->assertEquals('value2', $this->object->getParam('key2'));
$this->object->reset();
$this->assertEquals(null, $this->object->getParam('key1'));
$this->assertEquals(null, $this->object->getParam('key2'));
$this->assertEquals(null, $this->object->getParam('key3'));
}
}