예제 #1
0
 /**
  * @return RestResponse
  */
 public function run()
 {
     $this->checkIsInit();
     try {
         if (!$this->isEntityExists($this->entityId)) {
             return (new RestResponse(false))->setStatusCode(RestResponse::STATUS_CODE_ENTITY_NOT_FOUND)->setMessage("Сущность {$this->className} с id={$this->entityId} не была найдена");
         }
         $requestContentAsObj = $this->convertRequestDataToObj($this->requestContent);
         $entity = $this->mergeDataFromRequestWithEntity($requestContentAsObj);
         /** @var ConstraintViolationList $validations */
         $validations = $this->validator->validate($entity);
         if ($validations->count() !== 0) {
             return (new RestResponse(false))->setStatusCode(RestResponse::STATUS_CODE_WRONG_INPUT_DATA)->setErrors($validations);
         }
         $entity = $this->em->merge($entity);
         $this->em->flush();
         if ($this->newPrimaryKeyValue !== null) {
             EntityHelper::changePKValueAndSave($this->em, $entity, $this->newPrimaryKeyValue);
         }
         return (new RestResponse(true))->setStatusCode(RestResponse::STATUS_CODE_OK)->setData($entity);
     } catch (\Exception $e) {
         return (new RestResponse(false))->setStatusCode(RestResponse::STATUS_CODE_WRONG_INPUT_DATA)->setMessage($e->getMessage());
     }
 }
 /**
  * @expectedException \LogicException
  * @expectedExceptionMessage Одно из названий ключа (soe) не было найдено среди ключей в сущности (id,ownerId)
  */
 public function testThrowExceptionIfUseChangePKValueWithArrayWithNotEnoughItemsWhenEntityWithCompositeKeys2()
 {
     /** @var Client $book */
     $book = $this->em->getRepository($this->bookFullClassName)->findOneBy(['id' => 1, 'ownerId' => 1]);
     EntityHelper::changePKValueAndSave($this->em, $book, ['soe' => 2, 'sad' => 3]);
 }