wiki.techinc.nl/tests/phpunit/includes/SiteStatsTest.php
Amir Sarabadani e182010622 Reorg: Move SiteStats*.php to SiteStats/
It's going to be a bit small and narrow but it's better than sitting in
the root of includes/ plus I hope we can hollow out SiteStatsUpdate
class into the third one and or move this under a better directory in
the future.

Bug: T321882
Change-Id: Ia503b53b31ca00600f8c18b61a2652c3e146494e
2023-04-27 01:16:29 +02:00

50 lines
1.3 KiB
PHP

<?php
use MediaWiki\SiteStats\SiteStats;
/**
* @group Database
*/
class SiteStatsTest extends MediaWikiIntegrationTestCase {
/**
* @covers SiteStats::jobs
*/
public function testJobsCountGetCached() {
$cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
$this->setService( 'MainWANObjectCache', $cache );
$jobq = $this->getServiceContainer()->getJobQueueGroup();
$jobq->push( new NullJob( [] ) );
$this->assertSame( 1, SiteStats::jobs(),
'A single job enqueued bumps jobscount stat to 1' );
$jobq->push( new NullJob( [] ) );
$this->assertSame( 1, SiteStats::jobs(),
'SiteStats::jobs() count does not reflect addition ' .
'of a second job (cached)'
);
$jobq->get( 'null' )->delete(); // clear jobqueue
$this->assertSame( 0, $jobq->get( 'null' )->getSize(),
'Job queue for NullJob has been cleaned' );
$cache->delete( $cache->makeKey( 'SiteStats', 'jobscount' ) );
$this->assertSame( 1, SiteStats::jobs(),
'jobs count is kept in process cache' );
$cache->clearProcessCache();
$this->assertSame( 0, SiteStats::jobs() );
}
/**
* @covers SiteStats
*/
public function testInit() {
$this->db->delete( 'site_stats', IDatabase::ALL_ROWS, __METHOD__ );
SiteStats::unload();
SiteStats::edits();
$this->assertNotFalse( $this->db->selectRow( 'site_stats', '1', IDatabase::ALL_ROWS, __METHOD__ ) );
}
}