コード例 #1
0
 public function it_can_update_a_user(User $user, \PDOStatement $statement)
 {
     $user->getUuid()->willReturn($uuid = Uuid::uuid4());
     $user->getEmailAddress()->willReturn(EmailAddress::get($email = '*****@*****.**'));
     $user->getPassword()->willReturn($password = password_hash('no.jedi.please', PASSWORD_BCRYPT));
     $user->getDisplayName()->willReturn($displayName = 'Nute Gunray');
     $user->metaDataSetUpdateTimestamp(new Argument\Token\TypeToken(\DateTimeInterface::class))->shouldBeCalled();
     $this->pdo->beginTransaction()->shouldBeCalled();
     $this->pdo->prepare(new Argument\Token\StringContainsToken('UPDATE users'))->willReturn($statement);
     $statement->execute(['user_uuid' => $uuid->getBytes(), 'email_address' => $email, 'password' => $password, 'display_name' => $displayName])->shouldBeCalled();
     $statement->rowCount()->willReturn(1);
     $this->objectRepository->update(User::TYPE, $uuid)->shouldBeCalled();
     $this->pdo->commit()->shouldBeCalled();
     $this->update($user);
 }
コード例 #2
0
 public function it_can_delete_a_collection(ConfigCollection $collection)
 {
     $uuid = Uuid::uuid4();
     $collection->getUuid()->willReturn($uuid);
     $this->objectRepository->delete(ConfigCollection::TYPE, $uuid)->shouldBeCalled();
     $this->delete($collection);
 }
コード例 #3
0
 public function it_can_will_error_and_roll_back_when_delete_fails(File $file)
 {
     $uuid = Uuid::uuid4();
     $file->getUuid()->willReturn($uuid);
     $this->pdo->beginTransaction()->shouldBeCalled();
     $this->fileSystem->delete($uuid->toString())->willReturn(false);
     $this->objectRepository->delete(File::TYPE, $uuid)->shouldNotBeCalled();
     $this->pdo->rollBack()->shouldBeCalled();
     $this->shouldThrow(\RuntimeException::class)->duringDelete($file);
 }
コード例 #4
0
 public function deleteBlockFromPage(PageBlock $block, Page $page)
 {
     if (!$page->getUuid()->equals($block->getPage()->getUuid())) {
         throw new \OutOfBoundsException('PageBlock must belong to page to be added to it.');
     }
     // The database constraint should cascade the delete to the page
     $this->objectRepository->delete(PageBlock::TYPE, $block->getUuid());
     $page->removeBlock($block);
     $this->objectRepository->update(Page::TYPE, $page->getUuid());
     $page->metaDataSetUpdateTimestamp(new \DateTimeImmutable());
     $block->setStatus(PageStatusValue::get(PageStatusValue::DELETED));
 }
コード例 #5
0
 public function update(User $user)
 {
     $this->pdo->beginTransaction();
     try {
         $query = $this->executeSql('
             UPDATE users
                SET email_address = :email_address,
                    password = :password,
                    display_name = :display_name
              WHERE user_uuid = :user_uuid
         ', ['user_uuid' => $user->getUuid()->getBytes(), 'email_address' => $user->getEmailAddress()->toString(), 'password' => $user->getPassword(), 'display_name' => $user->getDisplayName()]);
         // When at least one of the fields changes, the rowCount will be 1 and an update occurred
         if ($query->rowCount() === 1) {
             $this->objectRepository->update(User::TYPE, $user->getUuid());
             $user->metaDataSetUpdateTimestamp(new \DateTimeImmutable());
         }
         $this->pdo->commit();
     } catch (\Throwable $exception) {
         $this->pdo->rollBack();
         throw $exception;
     }
 }
コード例 #6
0
 public function it_can_delete_a_block_from_a_page(Page $page, PageBlock $block)
 {
     $uuid = Uuid::uuid4();
     $page->getUuid()->willReturn($uuid);
     $page->removeBlock($block)->shouldBeCalled();
     $page->metaDataSetUpdateTimestamp(new Argument\Token\TypeToken(\DateTimeImmutable::class))->shouldBeCalled();
     $blockUuid = Uuid::uuid4();
     $block->getUuid()->willReturn($blockUuid);
     $block->getPage()->willReturn($page);
     $block->setStatus(PageStatusValue::get('deleted'))->shouldBeCalled();
     $this->objectRepository->delete(PageBlock::TYPE, $blockUuid)->shouldBeCalled();
     $this->objectRepository->update(Page::TYPE, $uuid)->shouldBeCalled();
     $this->deleteBlockFromPage($block, $page);
 }
コード例 #7
0
 public function delete(File $file)
 {
     $this->pdo->beginTransaction();
     try {
         if (!$this->fileSystem->delete($file->getUuid()->toString())) {
             throw new \RuntimeException('Failed to delete file');
         }
         $this->objectRepository->delete(File::TYPE, $file->getUuid());
         $this->pdo->commit();
     } catch (\Throwable $exception) {
         $this->pdo->rollBack();
         throw $exception;
     }
 }
コード例 #8
0
 public function delete(ConfigCollection $collection)
 {
     // The database constraint should cascade the delete to the collection and its items
     $this->objectRepository->delete(ConfigCollection::TYPE, $collection->getUuid());
 }