wiki.techinc.nl/tests/phpunit/includes/SiteStatsTest.php
Derick Alangi 83cdb69ed2 Avoid deprecated usage of Job::factory()
Change-Id: Ia2b8b71159ed8d387ae31f921ddcfd0d9136118c
2023-01-25 13:25:40 +02:00

35 lines
1 KiB
PHP

<?php
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() );
}
}