當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Bootstrap::setIdToEntity方法代碼示例

本文整理匯總了PHP中Test\Bootstrap::setIdToEntity方法的典型用法代碼示例。如果您正苦於以下問題:PHP Bootstrap::setIdToEntity方法的具體用法?PHP Bootstrap::setIdToEntity怎麽用?PHP Bootstrap::setIdToEntity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Test\Bootstrap的用法示例。


在下文中一共展示了Bootstrap::setIdToEntity方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getBookEntityWithRandomData

 /**
  * @param bool $withRandomId
  *
  * @return BookEntity
  */
 public function getBookEntityWithRandomData($withRandomId = true)
 {
     $bookEntity = new BookEntity();
     $bookEntity->setTitle(uniqid('title'))->setDescription(uniqid('description'))->setPublisher(uniqid('publisher'))->setYear(mt_rand(1900, date('Y')))->setPrice(mt_rand(1, 10000) / 100)->setIsbn($this->getIsbn13Random());
     if ($withRandomId) {
         Bootstrap::setIdToEntity($bookEntity, mt_rand(1, 999));
     }
     return $bookEntity;
 }
開發者ID:omusico,項目名稱:zf2-demo,代碼行數:14,代碼來源:BookEntityProvider.php

示例2: testUpdate_WithValidResponse

 public function testUpdate_WithValidResponse()
 {
     $bookEntity = $this->bookEntityProvider->getBookEntityWithRandomData();
     $newBookEntity = $this->bookEntityProvider->getBookEntityWithRandomData($withRandomId = false);
     $data = $this->bookEntityProvider->getDataFromBookEntity($newBookEntity);
     Bootstrap::setIdToEntity($newBookEntity, $bookEntity->getId());
     $filterMock = $this->getMock(InputFilterInterface::class);
     $filterMock->expects($this->once())->method('isValid')->will($this->returnValue(true));
     $filterMock->expects($this->once())->method('getValues')->will($this->returnValue($data));
     $this->bookRepositoryMock->expects($this->once())->method('hydrate')->with($bookEntity, $data)->will($this->returnValue($newBookEntity));
     $this->bookRepositoryMock->expects($this->once())->method('save')->with($newBookEntity);
     $result = $this->testedObj->update($bookEntity, $filterMock);
     $this->assertSame($newBookEntity, $result);
 }
開發者ID:omusico,項目名稱:zf2-demo,代碼行數:14,代碼來源:CrudServiceTest.php

示例3: testCreateRequest_WithValidData

 public function testCreateRequest_WithValidData()
 {
     $this->authenticateUser();
     $bookEntity = $this->bookEntityProvider->getBookEntityWithRandomData(false);
     $dataBeforeSaving = $this->bookEntityProvider->getDataFromBookEntity($bookEntity);
     Bootstrap::setIdToEntity($bookEntity, mt_rand(1, 999));
     $dataAfterSaving = $this->bookEntityProvider->getDataFromBookEntity($bookEntity);
     $this->filter->setData($dataBeforeSaving);
     $this->serviceMock->expects($this->once())->method('create')->with($this->filter)->will($this->returnValue($bookEntity));
     $this->serviceMock->expects($this->once())->method('extractEntity')->with($bookEntity)->will($this->returnValue($dataAfterSaving));
     $this->dispatch(self::CREATE_URL, Request::METHOD_POST, $dataBeforeSaving);
     $expectedJson = Json::encode($dataAfterSaving);
     $this->assertSame($expectedJson, $this->getResponse()->getContent());
     $this->assertResponseStatusCode(Response::STATUS_CODE_201);
 }
開發者ID:omusico,項目名稱:zf2-demo,代碼行數:15,代碼來源:CreateControllerFunctionalTest.php

示例4: createEntityWithRandomData

 /**
  * @param array $params
  *
  * @return UserEntity
  */
 public static function createEntityWithRandomData(array $params = [])
 {
     $withId = true;
     $entityId = mt_rand(1, 999);
     $name = uniqid('name');
     $email = uniqid('email');
     $login = uniqid('login');
     $password = uniqid('password');
     $role = UserEntityInterface::ROLE_ADMIN;
     extract($params);
     $userEntity = new UserEntity();
     $userEntity->setName($name)->setEmail($email)->setLogin($login)->setPassword($password)->setRole($role);
     if ($withId) {
         Bootstrap::setIdToEntity($userEntity, $entityId);
     }
     return $userEntity;
 }
開發者ID:omusico,項目名稱:zf2-demo,代碼行數:22,代碼來源:UserEntityProvider.php

示例5: testUpdateRequest_WithValidData

 public function testUpdateRequest_WithValidData()
 {
     $this->authenticateUser();
     $bookEntity = $this->bookEntityProvider->getBookEntityWithRandomData();
     $id = $bookEntity->getId();
     $newBookEntity = $this->bookEntityProvider->getBookEntityWithRandomData(false);
     $postData = $this->bookEntityProvider->getDataFromBookEntity($newBookEntity);
     Bootstrap::setIdToEntity($newBookEntity, $id);
     $dataAfterSaving = $this->bookEntityProvider->getDataFromBookEntity($newBookEntity);
     $this->serviceMock->expects($this->once())->method('getById')->with($id)->will($this->returnValue($bookEntity));
     $this->filter->setData($postData);
     $this->serviceMock->expects($this->once())->method('update')->with($bookEntity, $this->filter)->will($this->returnValue($newBookEntity));
     $this->serviceMock->expects($this->once())->method('extractEntity')->with($newBookEntity)->will($this->returnValue($dataAfterSaving));
     $this->dispatch(sprintf(self::UPDATE_URL, $id), Request::METHOD_PUT, $postData);
     $expectedJson = Json::encode($dataAfterSaving);
     $this->assertSame($expectedJson, $this->getResponse()->getContent());
     $this->assertResponseStatusCode(Response::STATUS_CODE_200);
 }
開發者ID:omusico,項目名稱:zf2-demo,代碼行數:18,代碼來源:UpdateControllerFunctionalTest.php


注:本文中的Test\Bootstrap::setIdToEntity方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。