MediaWiki  1.33.0
SiteStatsUpdateTest.php
Go to the documentation of this file.
1 <?php
2 
3 use Wikimedia\TestingAccessWrapper;
4 
13  public function testFactoryAndMerge() {
14  $update1 = SiteStatsUpdate::factory( [ 'pages' => 1, 'users' => 2 ] );
15  $update2 = SiteStatsUpdate::factory( [ 'users' => 1, 'images' => 1 ] );
16 
17  $update1->merge( $update2 );
18  $wrapped = TestingAccessWrapper::newFromObject( $update1 );
19 
20  $this->assertEquals( 1, $wrapped->pages );
21  $this->assertEquals( 3, $wrapped->users );
22  $this->assertEquals( 1, $wrapped->images );
23  $this->assertEquals( 0, $wrapped->edits );
24  $this->assertEquals( 0, $wrapped->articles );
25  }
26 
31  public function testDoUpdate() {
32  $this->setMwGlobals( 'wgSiteStatsAsyncFactor', false );
33  $this->setMwGlobals( 'wgCommandLineMode', false ); // disable opportunistic updates
34 
35  $dbw = wfGetDB( DB_MASTER );
36  $statsInit = new SiteStatsInit( $dbw );
37  $statsInit->refresh();
38 
39  $ei = SiteStats::edits(); // trigger load
40  $pi = SiteStats::pages();
41  $ui = SiteStats::users();
42  $fi = SiteStats::images();
43  $ai = SiteStats::articles();
44 
45  $dbw->begin( __METHOD__ ); // block opportunistic updates
46 
47  $update = SiteStatsUpdate::factory( [ 'pages' => 2, 'images' => 1, 'edits' => 2 ] );
48  $this->assertEquals( 0, DeferredUpdates::pendingUpdatesCount() );
49  $update->doUpdate();
50  $this->assertEquals( 1, DeferredUpdates::pendingUpdatesCount() );
51 
52  // Still the same
54  $this->assertEquals( $pi, SiteStats::pages(), 'page count' );
55  $this->assertEquals( $ei, SiteStats::edits(), 'edit count' );
56  $this->assertEquals( $ui, SiteStats::users(), 'user count' );
57  $this->assertEquals( $fi, SiteStats::images(), 'file count' );
58  $this->assertEquals( $ai, SiteStats::articles(), 'article count' );
59  $this->assertEquals( 1, DeferredUpdates::pendingUpdatesCount() );
60 
61  $dbw->commit( __METHOD__ );
62 
63  $this->assertEquals( 1, DeferredUpdates::pendingUpdatesCount() );
65  $this->assertEquals( 0, DeferredUpdates::pendingUpdatesCount() );
66 
68  $this->assertEquals( $pi + 2, SiteStats::pages(), 'page count' );
69  $this->assertEquals( $ei + 2, SiteStats::edits(), 'edit count' );
70  $this->assertEquals( $ui, SiteStats::users(), 'user count' );
71  $this->assertEquals( $fi + 1, SiteStats::images(), 'file count' );
72  $this->assertEquals( $ai, SiteStats::articles(), 'article count' );
73 
74  $statsInit = new SiteStatsInit();
75  $statsInit->refresh();
76  }
77 }
SiteStats\articles
static articles()
Definition: SiteStats.php:103
SiteStats\users
static users()
Definition: SiteStats.php:121
SiteStats\pages
static pages()
Definition: SiteStats.php:112
SiteStatsUpdateTest\testDoUpdate
testDoUpdate()
SiteStatsUpdate::doUpdate() SiteStatsInit::refresh()
Definition: SiteStatsUpdateTest.php:31
SiteStatsInit
Class designed for counting of stats.
Definition: SiteStatsInit.php:26
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
SiteStats\images
static images()
Definition: SiteStats.php:139
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2636
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:709
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
SiteStatsUpdate\factory
static factory(array $deltas)
Definition: SiteStatsUpdate.php:66
DB_MASTER
const DB_MASTER
Definition: defines.php:26
SiteStats\unload
static unload()
Trigger a reload next time a field is accessed.
Definition: SiteStats.php:38
DeferredUpdates\doUpdates
static doUpdates( $mode='run', $stage=self::ALL)
Do any deferred updates and clear the list.
Definition: DeferredUpdates.php:133
DeferredUpdates\pendingUpdatesCount
static pendingUpdatesCount()
Definition: DeferredUpdates.php:353
SiteStatsUpdateTest
Database.
Definition: SiteStatsUpdateTest.php:8
SiteStatsUpdateTest\testFactoryAndMerge
testFactoryAndMerge()
SiteStatsUpdate::factory SiteStatsUpdate::merge.
Definition: SiteStatsUpdateTest.php:13
SiteStats\edits
static edits()
Definition: SiteStats.php:94