Ejemplo n.º 1
0
 function it_executes_atomically(SqlManager $pdo)
 {
     $callable = function ($param) {
         return $param . 'bar';
     };
     $pdo->transactional($callable)->shouldBeCalled();
     $this->executeAtomically($callable);
 }
 function it_updates(SqlManager $pdo, \PDOStatement $statement, User $user, UserId $userId, UserEmail $email)
 {
     $user->id()->shouldBeCalled()->willReturn($userId);
     $userId->id()->shouldBeCalled()->willReturn('theid');
     $user->email()->shouldBeCalled()->willReturn($email);
     $email->getValue()->shouldBeCalled()->willReturn('*****@*****.**');
     $user->password()->shouldBeCalled()->willReturn('password');
     $pdo->execute(sprintf('SELECT COUNT(*) FROM %s WHERE id = :id', SqlUserRepository::TABLE_NAME), [':id' => 'theid'])->shouldBeCalled()->willReturn($statement);
     $statement->fetchColumn()->shouldBeCalled()->willReturn(1);
     $pdo->execute(sprintf('UPDATE %s SET email = :email, password = :password WHERE id = :id', SqlUserRepository::TABLE_NAME), ['id' => 'theid', 'email' => '*****@*****.**', 'password' => 'password'])->shouldBeCalled()->willReturn($statement);
     $this->save($user);
 }
Ejemplo n.º 3
0
 /**
  * Executes the sql given and returns the result in array of users.
  *
  * @param string $sql        The sql query
  * @param array  $parameters Array which contains the parameters
  *
  * @return array
  */
 private function retrieveAll($sql, array $parameters = [])
 {
     $statement = $this->pdo->execute($sql, $parameters);
     return array_map(function ($row) {
         return $this->buildUser($row);
     }, $statement->fetchAll(\PDO::FETCH_ASSOC));
 }
Ejemplo n.º 4
0
 /**
  * {@inheritDoc}
  */
 public function executeAtomically(callable $operation)
 {
     return $this->manager->transactional($operation);
 }
 function its_size(SqlManager $pdo, \PDOStatement $statement, SqlUserSpecification $specification)
 {
     $pdo->execute(sprintf('SELECT COUNT(*) FROM %s', SqlUserRepository::TABLE_NAME))->shouldBeCalled()->willReturn($statement);
     $statement->fetchColumn()->shouldBeCalled()->willReturn(2);
     $this->size()->shouldReturn(2);
 }