本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}