2019-12-26 23:00:29 +13:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Appwrite\Tests;
|
|
|
|
|
2020-03-25 06:56:32 +13:00
|
|
|
use Appwrite\Event\Event;
|
2019-12-26 23:00:29 +13:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2020-06-29 08:45:36 +12:00
|
|
|
use Utopia\App;
|
2019-12-26 23:00:29 +13:00
|
|
|
|
2019-12-26 23:20:09 +13:00
|
|
|
class EventTest extends TestCase
|
2019-12-26 23:00:29 +13:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var Event
|
|
|
|
*/
|
|
|
|
protected $object = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $queue = '';
|
|
|
|
|
2020-10-01 10:52:28 +13:00
|
|
|
public function setUp(): void
|
2019-12-26 23:00:29 +13:00
|
|
|
{
|
2020-06-29 08:45:36 +12:00
|
|
|
$redisHost = App::getEnv('_APP_REDIS_HOST', '');
|
|
|
|
$redisPort = App::getEnv('_APP_REDIS_PORT', '');
|
2019-12-26 23:00:29 +13:00
|
|
|
\Resque::setBackend($redisHost.':'.$redisPort);
|
|
|
|
|
|
|
|
$this->queue = 'v1-tests' . uniqid();
|
|
|
|
$this->object = new Event($this->queue, 'TestsV1');
|
|
|
|
}
|
|
|
|
|
2020-10-01 10:52:28 +13:00
|
|
|
public function tearDown(): void
|
2019-12-26 23:00:29 +13:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-12-07 21:51:12 +13:00
|
|
|
public function testQueue()
|
|
|
|
{
|
|
|
|
$this->assertEquals($this->queue, $this->object->getQueue());
|
|
|
|
|
|
|
|
$this->object->setQueue('demo');
|
|
|
|
|
|
|
|
$this->assertEquals('demo', $this->object->getQueue());
|
|
|
|
|
|
|
|
$this->object->setQueue($this->queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testClass()
|
|
|
|
{
|
|
|
|
$this->assertEquals('TestsV1', $this->object->getClass());
|
|
|
|
|
|
|
|
$this->object->setClass('TestsV2');
|
|
|
|
|
|
|
|
$this->assertEquals('TestsV2', $this->object->getClass());
|
|
|
|
|
|
|
|
$this->object->setClass('TestsV1');
|
|
|
|
}
|
|
|
|
|
2019-12-26 23:00:29 +13:00
|
|
|
public function testParams()
|
|
|
|
{
|
|
|
|
$this->object
|
2020-10-30 11:20:32 +13:00
|
|
|
->setParam('eventKey1', 'eventValue1')
|
|
|
|
->setParam('eventKey2', 'eventValue2')
|
2019-12-26 23:00:29 +13:00
|
|
|
;
|
|
|
|
|
|
|
|
$this->object->trigger();
|
|
|
|
|
2020-10-30 11:20:32 +13:00
|
|
|
$this->assertEquals(null, $this->object->getParam('eventKey1'));
|
|
|
|
$this->assertEquals(null, $this->object->getParam('eventKey2'));
|
|
|
|
$this->assertEquals(null, $this->object->getParam('eventKey3'));
|
2019-12-26 23:00:29 +13:00
|
|
|
$this->assertEquals(\Resque::size($this->queue), 1);
|
|
|
|
}
|
2020-07-05 01:06:23 +12:00
|
|
|
|
|
|
|
public function testReset()
|
|
|
|
{
|
|
|
|
$this->object
|
2020-10-30 11:20:32 +13:00
|
|
|
->setParam('eventKey1', 'eventValue1')
|
|
|
|
->setParam('eventKey2', 'eventValue2')
|
2020-07-05 01:06:23 +12:00
|
|
|
;
|
|
|
|
|
2020-10-30 11:20:32 +13:00
|
|
|
$this->assertEquals('eventValue1', $this->object->getParam('eventKey1'));
|
|
|
|
$this->assertEquals('eventValue2', $this->object->getParam('eventKey2'));
|
2020-07-05 01:06:23 +12:00
|
|
|
|
|
|
|
$this->object->reset();
|
|
|
|
|
2020-10-30 11:20:32 +13:00
|
|
|
$this->assertEquals(null, $this->object->getParam('eventKey1'));
|
|
|
|
$this->assertEquals(null, $this->object->getParam('eventKey2'));
|
|
|
|
$this->assertEquals(null, $this->object->getParam('eventKey3'));
|
2020-07-05 01:06:23 +12:00
|
|
|
}
|
2020-10-01 10:52:28 +13:00
|
|
|
}
|