1
0
Fork 0
mirror of synced 2024-07-19 13:25:42 +12:00
appwrite/tests/unit/Usage/StatsTest.php

72 lines
2 KiB
PHP
Raw Normal View History

2021-08-08 20:24:23 +12:00
<?php
2022-08-28 08:07:55 +12:00
namespace Tests\Unit\Usage;
2021-08-08 20:24:23 +12:00
2023-08-21 00:29:43 +12:00
use Appwrite\Usage\Stats;
2021-08-08 20:24:23 +12:00
use PHPUnit\Framework\TestCase;
use Utopia\App;
class StatsTest extends TestCase
{
2023-08-21 00:29:43 +12:00
/**
* @var Stats
*/
protected $object = null;
2023-01-15 23:03:52 +13:00
public function setUp(): void
{
2023-08-21 00:29:43 +12:00
$host = App::getEnv('_APP_STATSD_HOST', 'telegraf');
$port = App::getEnv('_APP_STATSD_PORT', 8125);
$connection = new \Domnikl\Statsd\Connection\UdpSocket($host, $port);
$statsd = new \Domnikl\Statsd\Client($connection);
$this->object = new Stats($statsd);
2023-01-15 23:03:52 +13:00
}
public function tearDown(): void
{
}
2023-08-21 00:29:43 +12:00
public function testNamespace(): void
{
$this->object->setNamespace('appwritetest.usage');
$this->assertEquals('appwritetest.usage', $this->object->getNamespace());
}
public function testParams(): void
2023-01-15 23:03:52 +13:00
{
2023-08-21 00:29:43 +12:00
$this->object
->setParam('projectId', 'appwrite_test')
->setParam('projectInternalId', 1)
->setParam('networkRequestSize', 100)
;
$this->assertEquals('appwrite_test', $this->object->getParam('projectId'));
$this->assertEquals(1, $this->object->getParam('projectInternalId'));
$this->assertEquals(100, $this->object->getParam('networkRequestSize'));
$this->object->submit();
$this->assertEquals(null, $this->object->getParam('projectId'));
$this->assertEquals(null, $this->object->getParam('networkRequestSize'));
}
public function testReset(): void
{
$this->object
->setParam('projectId', 'appwrite_test')
->setParam('networkRequestSize', 100)
;
$this->assertEquals('appwrite_test', $this->object->getParam('projectId'));
$this->assertEquals(100, $this->object->getParam('networkRequestSize'));
$this->object->reset();
$this->assertEquals(null, $this->object->getParam('projectId'));
$this->assertEquals(null, $this->object->getParam('networkRequestSize'));
$this->assertEquals('appwrite.usage', $this->object->getNamespace());
2023-01-15 23:03:52 +13:00
}
2021-08-08 20:24:23 +12:00
}