public function testHasEntityBeenAccessed() { $lookup = new RestrictedEntityLookup($this->getEntityLookup(), 200); $lookup->getEntity(new ItemId('Q2')); $this->assertTrue($lookup->entityHasBeenAccessed(new ItemId('Q2'))); $this->assertFalse($lookup->entityHasBeenAccessed(new ItemId('Q42'))); }
/** * Gets the entity and increments the expensive parser function count. * * @param Parser $parser * @param string $entityIdString * * @return EntityId|null */ private function getEntityIdFromString(Parser $parser, $entityIdString) { try { $entityId = $this->entityIdParser->parse($entityIdString); } catch (EntityIdParsingException $ex) { // Just ignore this return null; } // Getting a foreign item is expensive (unless we already loaded it and it's cached) if (!$this->restrictedEntityLookup->entityHasBeenAccessed($entityId)) { $parser->incrementExpensiveFunctionCount(); } return $entityId; }