2020-09-10 19:59:26 +00:00
|
|
|
<?php
|
|
|
|
|
|
2025-01-16 07:54:02 +00:00
|
|
|
namespace BlaxSoftware\LaravelWebSockets\Test;
|
2020-09-10 19:59:26 +00:00
|
|
|
|
|
|
|
|
class StatisticsCleanTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
public function test_clean_statistics_for_app_id()
|
|
|
|
|
{
|
|
|
|
|
$rick = $this->newActiveConnection(['public-channel']);
|
|
|
|
|
$morty = $this->newActiveConnection(['public-channel'], 'TestKey2');
|
|
|
|
|
|
|
|
|
|
$this->statisticsCollector->save();
|
|
|
|
|
|
|
|
|
|
$this->assertCount(2, $records = $this->statisticsStore->getRecords());
|
|
|
|
|
|
|
|
|
|
foreach ($this->statisticsStore->getRawRecords() as $record) {
|
|
|
|
|
$record->update(['created_at' => now()->subDays(10)]);
|
2020-09-10 19:59:49 +00:00
|
|
|
}
|
2020-09-10 19:59:26 +00:00
|
|
|
|
|
|
|
|
$this->artisan('websockets:clean', [
|
|
|
|
|
'appId' => '12345',
|
|
|
|
|
'--days' => 1,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertCount(1, $records = $this->statisticsStore->getRecords());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_clean_statistics_older_than_given_days()
|
|
|
|
|
{
|
|
|
|
|
$rick = $this->newActiveConnection(['public-channel']);
|
|
|
|
|
$morty = $this->newActiveConnection(['public-channel'], 'TestKey2');
|
|
|
|
|
|
|
|
|
|
$this->statisticsCollector->save();
|
|
|
|
|
|
|
|
|
|
$this->assertCount(2, $records = $this->statisticsStore->getRecords());
|
|
|
|
|
|
|
|
|
|
foreach ($this->statisticsStore->getRawRecords() as $record) {
|
|
|
|
|
$record->update(['created_at' => now()->subDays(10)]);
|
2020-09-10 19:59:49 +00:00
|
|
|
}
|
2020-09-10 19:59:26 +00:00
|
|
|
|
|
|
|
|
$this->artisan('websockets:clean', ['--days' => 1]);
|
|
|
|
|
|
|
|
|
|
$this->assertCount(0, $records = $this->statisticsStore->getRecords());
|
|
|
|
|
}
|
|
|
|
|
}
|