/** * @see EntityStore::assignFreshId() * * @param EntityDocument $entity * * @throws StorageException */ public function assignFreshId(EntityDocument $entity) { if ($entity->getId() !== null) { throw new StorageException('This entity already has an ID!'); } $contentModelId = $this->contentFactory->getContentModelForType($entity->getType()); $numericId = $this->idGenerator->getNewId($contentModelId); //FIXME: this relies on setId() accepting numeric IDs! $entity->setId($numericId); }
/** * @dataProvider instanceProvider */ public function testGetNewId(IdGenerator $generator) { /** * @var IdGenerator $clone */ $clone = clone $generator; $id = $generator->getNewId('foo'); $this->assertInternalType('integer', $id); $id1 = $generator->getNewId('foo'); $this->assertInternalType('integer', $id1); $this->assertNotEquals($id, $id1); $id2 = $generator->getNewId('bar'); $this->assertInternalType('integer', $id2); $id3 = $clone->getNewId('foo'); $this->assertInternalType('integer', $id3); $this->assertTrue(!in_array($id3, array($id, $id1), true)); }