appwrite/tests/unit/Usage/StatsTest.php

42 lines
1.1 KiB
PHP
Raw Normal View History

2021-08-08 08:24:23 +00:00
<?php
2022-08-27 20:07:55 +00:00
namespace Tests\Unit\Usage;
2021-08-08 08:24:23 +00:00
use PHPUnit\Framework\TestCase;
2023-10-25 07:39:59 +00:00
use Utopia\Queue\Client;
use Utopia\Queue\Connection;
2021-08-08 08:24:23 +00:00
class StatsTest extends TestCase
{
2023-10-25 07:39:59 +00:00
protected ?Connection $connection = null;
protected ?Client $client = null;
protected const QUEUE_NAME = 'usage-test-q';
2023-01-15 10:03:52 +00:00
public function setUp(): void
{
2024-10-31 12:12:03 +00:00
global $register;
$connection = $register->get('pools')->get('queue')->pop()->getResource();
$this->connection = $connection;
2023-10-25 07:39:59 +00:00
$this->client = new Client(self::QUEUE_NAME, $this->connection);
2023-01-15 10:03:52 +00:00
}
public function tearDown(): void
{
}
2023-10-25 07:39:59 +00:00
public function testSamePayload(): void
2023-01-15 10:03:52 +00:00
{
2023-10-25 07:39:59 +00:00
$inToQueue = [
'key_1' => 'value_1',
'key_2' => 'value_2',
];
$result = $this->client->enqueue($inToQueue);
$this->assertTrue($result);
$outFromQueue = $this->connection->leftPopArray('utopia-queue.queue.' . self::QUEUE_NAME, 0)['payload'];
$this->assertNotEmpty($outFromQueue);
$this->assertSame($inToQueue, $outFromQueue);
2023-01-15 10:03:52 +00:00
}
2021-08-08 08:24:23 +00:00
}