Esempio n. 1
0
 /**
  * @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;
 }
Esempio n. 2
0
 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);
 }
 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);
 }
Esempio n. 4
0
 /**
  * @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;
 }
 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);
 }