/** * Applies the given ChangeOp to the given Entity. * Any ChangeOpException is converted into a UsageException with the code 'modification-failed'. * * @since 0.5 * * @param ChangeOp $changeOp * @param Entity $entity * @param Summary $summary The summary object to update with information about the change. * * @throws UsageException */ protected function applyChangeOp(ChangeOp $changeOp, Entity $entity, Summary $summary = null) { try { $result = $changeOp->validate($entity); if (!$result->isValid()) { throw new ChangeOpValidationException($result); } $changeOp->apply($entity, $summary); } catch (ChangeOpException $ex) { $this->errorReporter->dieException($ex, 'modification-failed'); } }
/** * @dataProvider validateProvider * * @param ChangeOp $changeOp * @param bool $valid */ public function testValidate(ChangeOp $changeOp, $valid) { $entity = $this->provideNewEntity(); $oldLabels = $entity->getFingerprint()->getLabels()->toTextArray(); $result = $changeOp->validate($entity); $this->assertEquals($valid, $result->isValid(), 'isValid()'); // labels should not have changed during validation $newLabels = $entity->getFingerprint()->getLabels()->toTextArray(); $this->assertEquals($oldLabels, $newLabels, 'Labels modified by validation!'); }
/** * Applies the given ChangeOp to the given Entity. * If validation fails, a ChangeOpValidationException is thrown. * * @since 0.5 * * @param ChangeOp $changeOp * @param EntityDocument $entity * @param Summary|null $summary The summary object to update with information about the change. * * @throws ChangeOpException */ protected function applyChangeOp(ChangeOp $changeOp, EntityDocument $entity, Summary $summary = null) { $result = $changeOp->validate($entity); if (!$result->isValid()) { throw new ChangeOpValidationException($result); } $changeOp->apply($entity, $summary); }