Esempio n. 1
0
 /**
  * From key to object
  *
  * {@inheritDoc}
  */
 public function reverseTransform($value)
 {
     if (null !== $value && !is_scalar($value)) {
         throw new TransformationFailedException('Expected a scalar.');
     }
     if (!$this->existsNickname($value)) {
         throw new TransformationFailedException("{$value} is an invalid choice");
     }
     $found = $this->repository->findByNickname($value);
     if (is_null($found)) {
         throw new TransformationFailedException("Author {$value} is not found");
     }
     return $found->getAuthor();
 }
Esempio n. 2
0
 protected function benchmark(Netizen $user, $counter)
 {
     $key = $user->getUsername();
     $stopwatch = microtime(true);
     for ($k = 0; $k < $counter; $k++) {
         $this->repository->persist($user);
     }
     printf(" write %s %.1f ms\n", $key, (microtime(true) - $stopwatch) * 1000 / $counter);
     $stopwatch = microtime(true);
     for ($k = 0; $k < $counter; $k++) {
         $user = $this->repository->findByNickname($key);
     }
     printf(" read %s %.1f ms\n", $user->getUsername(), (microtime(true) - $stopwatch) * 1000 / $counter);
 }
Esempio n. 3
0
 public function testAlreadyExisting()
 {
     $obj = $this->factory->create('mcleod', 'facebook', '456456456');
     // registered with another provider
     $this->repository->persist($obj);
     $submitted = ['nickname' => 'mcleod', 'gender' => 'xy'];
     $this->sut->submit($submitted);
     $this->assertRegexp('#already used#', $this->sut->get('nickname')->getErrors()[0]->getMessage());
 }