/**
  * @since 2.2
  *
  * @param Store $store
  * @param Callable|null $reporterCallback
  *
  * @return PropertyStatisticsRebuilder
  */
 public function newPropertyStatisticsRebuilder(Store $store, $reporterCallback = null)
 {
     $messageReporter = MessageReporterFactory::getInstance()->newObservableMessageReporter();
     $messageReporter->registerReporterCallback($reporterCallback);
     $propertyStatisticsTable = new PropertyStatisticsTable($store->getConnection('mw.db'), SQLStore::PROPERTY_STATISTICS_TABLE);
     $propertyStatisticsRebuilder = new PropertyStatisticsRebuilder($store, $propertyStatisticsTable);
     $propertyStatisticsRebuilder->setMessageReporter($messageReporter);
     return $propertyStatisticsRebuilder;
 }
 public function testRebuildWithValidPropertyStatisticsStoreInsertUsageCount()
 {
     $arbitraryPropertyTableName = 'allornothing';
     $propertySelectRow = new \stdClass();
     $propertySelectRow->count = 1111;
     $selectResult = array('smw_title' => 'Foo', 'smw_id' => 9999);
     $selectResultWrapper = new FakeResultWrapper(array((object) $selectResult));
     $database = $this->getMockBuilder('\\SMW\\MediaWiki\\Database')->disableOriginalConstructor()->getMock();
     $database->expects($this->atLeastOnce())->method('select')->will($this->returnValue($selectResultWrapper));
     $database->expects($this->once())->method('selectRow')->with($this->stringContains($arbitraryPropertyTableName), $this->anything(), $this->equalTo(array('p_id' => 9999)), $this->anything())->will($this->returnValue($propertySelectRow));
     $store = $this->getMockBuilder('\\SMWSQLStore3')->disableOriginalConstructor()->getMock();
     $store->expects($this->atLeastOnce())->method('getConnection')->will($this->returnValue($database));
     $store->expects($this->atLeastOnce())->method('getPropertyTables')->will($this->returnValue(array($this->getNonFixedPropertyTable($arbitraryPropertyTableName))));
     $propertyStatisticsStore = $this->getMockBuilder('\\SMW\\Store\\PropertyStatisticsStore')->disableOriginalConstructor()->getMock();
     $propertyStatisticsStore->expects($this->atLeastOnce())->method('insertUsageCount');
     $instance = new PropertyStatisticsRebuilder($store, $propertyStatisticsStore);
     $instance->rebuild();
 }