public function testUuidConvertsToDatabaseValue() { $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); $expected = 'ff6f8cb0-c57d-11e1-9b21-0800200c9a66'; $actual = $this->type->convertToDatabaseValue($uuid, $this->platform); $this->assertEquals($expected, $actual); }
/** * @param string $value */ public function __construct(string $value) { if (!\Ramsey\Uuid\Uuid::isValid($value)) { throw new \InvalidArgumentException(sprintf('%s is not a valid Uuid.', $value)); } $this->value = \Ramsey\Uuid\Uuid::fromString($value); }
/** * @param string $uuidString * @return \Ramsey\Uuid\UuidInterface */ private function deserializeUuidValue($uuidString) { if (!Uuid::isValid($uuidString)) { throw new \Mhujer\JmsSerializer\Uuid\InvalidUuidException($uuidString); } return Uuid::fromString($uuidString); }
/** * @test */ public function it_should_create_video_proxy_from_the_video_source() { $videoProxyService = new VideoProxyService($this->entityManager); $this->entityManager->expects($this->once())->method('persist'); $proxyUuid = $videoProxyService->createFromSource("http://video-proxy.com"); $this->assertEquals($proxyUuid, (string) Uuid::fromString($proxyUuid)); }
public function testGenerate() { $id = UuidIdentifier::generate(); $this->assertTrue(Uuid::isValid($id)); $uuid = Uuid::fromString($id->toString()); $this->assertTrue($uuid->getVersion() == 4); }
public function deserializeUuid(VisitorInterface $visitor, $data, array $type, Context $context) { if (null === $data) { return null; } return Uuid::fromString($data); }
public static function fromString(string $uuid) { if (!Uuid::isValid($uuid)) { throw new \InvalidArgumentException(sprintf('%s is not valid uuid', $uuid)); } return new Id(Uuid::fromString($uuid)->toString()); }
/** * @return JsonModel */ public function getList() { $previousEventId = $this->params()->fromQuery('previousEventId'); $count = $this->params()->fromQuery('count', 10); if ($previousEventId) { $previousEventId = Uuid::fromString($previousEventId); } $iterator = $this->eventStore->iterate($previousEventId); $selfUrl = $this->url()->fromRoute(null, [], ['force_canonical' => true], true); $nextUrl = false; $lastEventId = $previousEventId; $events = []; $i = 0; /** @var EventMessageInterface $event */ foreach ($iterator as $event) { if ($i >= $count) { break; } $events[] = $event; $i++; $lastEventId = $event->getId()->toString(); } $nextUrl = $this->url()->fromRoute(null, [], ['force_canonical' => true, 'query' => ['previousEventId' => (string) $lastEventId]], true); $data = ['_links' => ['self' => $selfUrl, 'next' => $nextUrl], 'count' => count($events), '_embedded' => ['event' => array_values($events)]]; return new JsonModel($data); }
/** * @inheritdoc */ public function denormalize($data, $class, $format = null, array $context = array()) { if (null === $data) { return null; } return Uuid::fromString($data); }
public function testSerializeJson() { $uuid = Uuid::fromString('34ca79b8-6181-4b93-903a-ac658e0c5c35'); $object = new ObjectWithUuid($uuid); $json = $this->serializer->serialize($object, 'json'); $this->assertEquals('{"uuid":"34ca79b8-6181-4b93-903a-ac658e0c5c35"}', $json); }
public function convert($rawValue) { try { return Uuid::fromString($rawValue); } catch (\Exception $e) { return; } }
public function testUuidConvertsToPHPValue() { $uuid = $this->type->convertToPHPValue(hex2bin('ff6f8cb0c57d11e19b210800200c9a66'), $this->platform); $this->assertInstanceOf('Ramsey\\Uuid\\Uuid', $uuid); $this->assertEquals('ff6f8cb0-c57d-11e1-9b21-0800200c9a66', $uuid->toString()); $uuid = $this->type->convertToPHPValue('ff6f8cb0-c57d-11e1-9b21-0800200c9a66', $this->platform); $this->assertEquals('ff6f8cb0-c57d-11e1-9b21-0800200c9a66', Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66')->toString()); }
/** * @test */ public function it_returns_command_with_uuid_to_launch() { $this->commandCollector->getCommandByName('DummyCommandWithUuid')->willReturn(CommandReflection::fromClass(DummyCommandWithUuid::class)); $this->argumentsProcessor->process(['lorem ipsum', 'a1df6294-bcd9-43c5-8731-e3cd43401974'])->willReturn(['lorem ipsum', Uuid::fromString('a1df6294-bcd9-43c5-8731-e3cd43401974')]); $command = $this->sut->getCommandToLaunch('DummyCommandWithUuid', ['lorem ipsum', 'a1df6294-bcd9-43c5-8731-e3cd43401974']); $this->assertInstanceOf(DummyCommandWithUuid::class, $command); $this->assertTrue(Uuid::fromString('a1df6294-bcd9-43c5-8731-e3cd43401974')->equals($command->argument2)); }
protected function addReservation($reservationId, $bookId, \DateTime $givenAwayAt = null) { $reservation = new Reservation(Uuid::fromString($reservationId), Uuid::fromString($bookId), '*****@*****.**'); if (null !== $givenAwayAt) { $reservation->giveAway($givenAwayAt); } $this->reservations->save($reservation); }
/** * @param string $string * * @throws OrmException * * @return $this */ public function setUuidFromString($string) { if (!Uuid::isValid($string)) { throw OrmException::create()->setMessage('Invalid Uuid string provided.'); } $this->uuid = Uuid::fromString($string); return $this; }
public function getMatchers() { return ['beValidUUID' => function ($uuid) { return Uuid::isValid($uuid); }, 'beEqualUUID' => function ($uuid, $value) { return Uuid::fromString($uuid)->equals(Uuid::fromString($uuid)); }]; }
/** @test */ public function it_can_be_cleared() { $book1 = new Book(Uuid::fromString('a7f0a5b1-b65a-4f9b-905b-082e255f6038'), 'Domain-Driven Design', 'Eric Evans', '0321125215'); $book2 = new Book(Uuid::fromString('38483e7a-e815-4657-bc94-adc83047577e'), 'REST in Practice', 'Jim Webber, Savas Parastatidis, Ian Robinson', '978-0596805821'); $this->repository->save($book1); $this->repository->save($book2); $this->repository->clear(); $this->assertEmpty($this->repository->getAll()); }
public function testDeserializeUuidFromXml() { $expectedUuid = Uuid::fromString('86be949f-7f46-4457-9230-fad9783337aa'); $serializer = $this->getSerializer(); /** @var \Mhujer\JmsSerializer\Uuid\User $user */ $user = $serializer->deserialize('<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<result>' . "\n" . ' <id><![CDATA[86be949f-7f46-4457-9230-fad9783337aa]]></id>' . "\n" . '</result>' . "\n", User::class, 'xml'); $this->assertInstanceOf(User::class, $user); $this->assertTrue($user->id->equals($expectedUuid)); }
public function testSerialize() { $event = new SomeEvent(['foo' => 'bar', 'id' => Uuid::fromString('bd0a32dd-37f1-42ab-807f-c3c29261a9fe'), 'time' => new DateTimeImmutable('2014-08-15 10:12:14.654321', new DateTimeZone('Australia/Sydney')), 'object' => new stdClass()]); $serializer = new ReflectionSerializer(); $data = $serializer->serialize($event); // Make the test pass on 32bit system $data = strtr($data, ['DegradedUuid' => 'Uuid']); $this->assertEquals('{"php_class":"CQRSTest\\\\Serializer\\\\SomeEvent","foo":"bar","id":{"php_class":"Ramsey\\\\Uuid\\\\Uuid",' . '"uuid":"bd0a32dd-37f1-42ab-807f-c3c29261a9fe"},"time":{"php_class":"DateTimeImmutable",' . '"time":"2014-08-15T10:12:14.654321+1000"},"object":{"php_class":"stdClass"}}', $data); }
/** * @param null|string $uuid * * @return $this */ public function setUuid($uuid = null) { try { $this->uuid = $uuid instanceof Uuid ? $uuid : Uuid::fromString($uuid); } catch (\InvalidArgumentException $e) { $this->uuid = Uuid::uuid1(); } return $this; }
/** * {@inheritdoc} */ public function handle(MessageInterface $message) { /** @var ChangeCustomerNameCommand $message */ $name = new CustomerName($message->getGender(), $message->getFirstName(), $message->getLastName(), $message->getEmail()); /** @var Customer $customer */ $customer = $this->repository->findById(Uuid::fromString($message->getCustomerId())); $customer->changeName($name); $this->repository->save($customer); }
/** * @param Uuid|string $uuid */ public function __construct($uuid = null) { if ($uuid !== null && !$uuid instanceof Uuid) { $uuid = Uuid::fromString($uuid); } if ($uuid === null) { $uuid = Uuid::uuid4(); } $this->uuid = $uuid->toString(); }
public function executeRequest(RequestInterface $request) : ResponseInterface { try { $parentUuid = isset($request['parent_uuid']) ? Uuid::fromString($request['parent_uuid']) : null; return new Response(self::MESSAGE, ['data' => $this->pageRepository->getAllByParentUuid($parentUuid), 'parent_uuid' => $parentUuid, 'includes' => ['pageBlocks']], $request); } catch (\Throwable $e) { $this->log(LogLevel::ERROR, $e->getMessage()); throw new ResponseException('An error occurred during ListPagesHandler.', new ServerErrorResponse([], $request)); } }
public function it_can_handle_errors_when_executing_a_request(RequestInterface $request) { $tokenUuid = Uuid::uuid4()->toString(); $passCode = bin2hex(random_bytes(20)); $request->getAcceptContentType()->willReturn('*/*'); $request->offsetGet('token')->willReturn($tokenUuid); $request->offsetGet('pass_code')->willReturn($passCode); $this->tokenService->getToken(Uuid::fromString($tokenUuid), $passCode)->willThrow(new \RuntimeException()); $this->shouldThrow(ResponseException::class)->duringExecuteRequest($request); }
/** * @test */ public function it_returns_new_command_with_uuid_instance() { $argumentProcessor = new ArgumentsProcessor([new UuidConverter()]); $commandReflection = CommandReflection::fromClass(DummyCommandWithUuid::class); $commandParameters = ['lorem ipsum', '1a67b1de-e3cb-471e-90d3-005341a29b3d']; $command = $commandReflection->createCommand($commandParameters, $argumentProcessor); \PHPUnit_Framework_Assert::assertInstanceOf(DummyCommandWithUuid::class, $command); \PHPUnit_Framework_Assert::assertEquals('lorem ipsum', $command->argument1); \PHPUnit_Framework_Assert::assertTrue(Uuid::fromString('1a67b1de-e3cb-471e-90d3-005341a29b3d')->equals($command->argument2)); }
/** {@inheritdoc} */ public function executeRequest(RequestInterface $request) : ResponseInterface { try { $page = new Page(Uuid::uuid4(), $request['title'], $request['slug'], $request['short_title'], $request['parent_uuid'] ? Uuid::fromString($request['parent_uuid']) : null, $request['sort_order'], PageStatusValue::get($request['status'])); $this->pageRepository->create($page); return new Response(self::MESSAGE, ['data' => $page], $request); } catch (\Throwable $exception) { $this->log(LogLevel::ERROR, $exception->getMessage()); throw new ResponseException('An error occurred during CreatePageHandler.', new ServerErrorResponse([], $request)); } }
/** * @param string|Uuid $uuid * @param string $namespace * * @return Nonce|null */ public function find($uuid, $namespace) { if (!$uuid instanceof Uuid) { try { $uuid = Uuid::fromString($uuid); } catch (InvalidArgumentException $e) { return; } } return $this->getObjectManager()->getRepository($this->getEntityClass())->findOneBy(['uuid' => $uuid->toString(), 'namespace' => $namespace]); }
/** * {@inheritdoc} */ public function findByUuid($uuid) { if (!$uuid instanceof Uuid) { try { $uuid = Uuid::fromString($uuid); } catch (InvalidArgumentException $e) { return; } } return $this->objectManager->getRepository($this->entityClass)->findOneBy(['uuid' => $uuid->toString()]); }
/** @test */ public function it_returns_books_in_library_paginated() { $this->addBook(Uuid::fromString('a7f0a5b1-b65a-4f9b-905b-082e255f6038'), 'Domain-Driven Design', 'Eric Evans', '0321125215'); $this->addBook(Uuid::fromString('38483e7a-e815-4657-bc94-adc83047577e'), 'REST in Practice', 'Jim Webber, Savas Parastatidis, Ian Robinson', '978-0596805821'); $this->addBook(Uuid::fromString('979b4f4e-6c87-456a-a8b3-be6cff32b660'), 'Clean Code', 'Robert C. Martin', '978-0132350884'); $books = $this->projection->get(2, 2); $this->assertEquals('979b4f4e-6c87-456a-a8b3-be6cff32b660', $books[0]->bookId); $this->assertEquals('Clean Code', $books[0]->title); $this->assertEquals('Robert C. Martin', $books[0]->authors); $this->assertEquals('978-0132350884', $books[0]->isbn); }
/** * {@inheritDoc} * * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { if (!Uuid::isValid($input->getArgument('uuid'))) { throw new Exception('Invalid UUID (' . $input->getArgument('uuid') . ')'); } $uuid = Uuid::fromString($input->getArgument('uuid')); $table = $this->createTable($output); $this->setTableLayout($table); (new UuidFormatter())->write($table, $uuid); $table->render($output); }