From: addshore Date: Sat, 2 Apr 2016 09:18:54 +0000 (+0300) Subject: Introduce NullStatsdDataFactory X-Git-Tag: 1.31.0-rc.0~7419 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22brouteur%22%2C%28%24id_rubrique%20?a=commitdiff_plain;h=6ae77e6984b9779775308217804c56363cbcdebb;p=lhc%2Fweb%2Fwiklou.git Introduce NullStatsdDataFactory I have left the phpdocs in NullStatsdDataFactory to clearly show the return types of the interface implemented. Change-Id: I96cb64b4af16fc087028269a53d539f8c132f81c --- diff --git a/autoload.php b/autoload.php index a4c09e0390..c62e99d3ee 100644 --- a/autoload.php +++ b/autoload.php @@ -893,6 +893,7 @@ $wgAutoloadLocalClasses = [ 'NullJob' => __DIR__ . '/includes/jobqueue/jobs/NullJob.php', 'NullLockManager' => __DIR__ . '/includes/filebackend/lockmanager/LockManager.php', 'NullRepo' => __DIR__ . '/includes/filerepo/NullRepo.php', + 'NullStatsdDataFactory' => __DIR__ . '/includes/libs/NullStatsdDataFactory.php', 'OOUIHTMLForm' => __DIR__ . '/includes/htmlform/OOUIHTMLForm.php', 'ORAField' => __DIR__ . '/includes/db/DatabaseOracle.php', 'ORAResult' => __DIR__ . '/includes/db/DatabaseOracle.php', diff --git a/includes/WatchedItemStore.php b/includes/WatchedItemStore.php index 4f3d640339..2aa294b639 100644 --- a/includes/WatchedItemStore.php +++ b/includes/WatchedItemStore.php @@ -57,20 +57,22 @@ class WatchedItemStore { /** * @param LoadBalancer $loadBalancer * @param HashBagOStuff $cache - * @param StatsdDataFactoryInterface $stats */ public function __construct( LoadBalancer $loadBalancer, - HashBagOStuff $cache, - StatsdDataFactoryInterface $stats + HashBagOStuff $cache ) { $this->loadBalancer = $loadBalancer; $this->cache = $cache; - $this->stats = $stats; + $this->stats = new NullStatsdDataFactory(); $this->deferredUpdatesAddCallableUpdateCallback = [ 'DeferredUpdates', 'addCallableUpdate' ]; $this->revisionGetTimestampFromIdCallback = [ 'Revision', 'getTimestampFromId' ]; } + public function setStatsdDataFactory( StatsdDataFactoryInterface $stats ) { + $this->stats = $stats; + } + /** * Overrides the DeferredUpdates::addCallableUpdate callback * This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined. @@ -155,9 +157,9 @@ class WatchedItemStore { if ( !self::$instance ) { self::$instance = new self( wfGetLB(), - new HashBagOStuff( [ 'maxKeys' => 100 ] ), - RequestContext::getMain()->getStats() + new HashBagOStuff( [ 'maxKeys' => 100 ] ) ); + self::$instance->setStatsdDataFactory( RequestContext::getMain()->getStats() ); } return self::$instance; } diff --git a/includes/libs/NullStatsdDataFactory.php b/includes/libs/NullStatsdDataFactory.php new file mode 100644 index 0000000000..3b272e216e --- /dev/null +++ b/includes/libs/NullStatsdDataFactory.php @@ -0,0 +1,111 @@ +setKey( $key ); + $data->setValue( $value ); + $data->setMetric( $metric ); + return $data; + } + +} diff --git a/tests/phpunit/includes/WatchedItemStoreUnitTest.php b/tests/phpunit/includes/WatchedItemStoreUnitTest.php index bc846d33d3..9dd38df069 100644 --- a/tests/phpunit/includes/WatchedItemStoreUnitTest.php +++ b/tests/phpunit/includes/WatchedItemStoreUnitTest.php @@ -86,8 +86,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase { private function newWatchedItemStore( LoadBalancer $loadBalancer, HashBagOStuff $cache ) { return new WatchedItemStore( $loadBalancer, - $cache, - $this->getMock( StatsdDataFactory::class ) + $cache ); }