Esempio n. 1
0
 public function testRunController_convertsPDOException()
 {
     $this->service = $this->getMock('Psc\\CMS\\Service\\ControllerService', array('routeController', 'setResponseFromException'), array($this->project));
     // controller throws an Exception
     $controller = $this->getMock(__NAMESPACE__ . '\\TestController', array('pdoExceptionThrowingMethod'));
     $controller->expects($this->once())->method('pdoExceptionThrowingMethod')->will($this->throwException($pdoException = $this->doublesManager->createPDOUniqueConstraintException('my_unique_constraint', 'errorValue')));
     $doctrineException = \Psc\Doctrine\Exception::convertPDOException($pdoException);
     try {
         // run
         $this->service->runController($controller, 'pdoExceptionThrowingMethod', array());
     } catch (\Psc\Doctrine\UniqueConstraintException $e) {
         $this->assertEquals($doctrineException, $e);
         return;
     }
     $this->fail('Exception wurde nicht gecatched');
 }
Esempio n. 2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $project = \Psc\PSC::getProject();
     $em = $project->getModule('Doctrine')->getEntityManager($input->getOption('con'));
     try {
         $r = new \Psc\Form\EmailValidatorRule();
         $email = $r->validate($input->getArgument('email'));
     } catch (\Exception $e) {
         $output->writeln('FEHLER: E-Mail-Adresse ist nicht korrekt.');
         return 1;
     }
     if (($password = $input->getOption('password')) == NULL) {
         $password = \Webforge\Common\String::random(6);
     }
     $c = $project->getUserClass();
     if ($input->getOption('reset-password') == TRUE) {
         $userRep = $em->getRepository($c);
         $user = $userRep->find($email);
         if (!$user instanceof \Psc\CMS\User) {
             $output->writeln('User mit der Email: "' . $email . '" nicht gefunden.');
             return 2;
         }
         $output->writeln('Passwort Reset für: ' . $email);
     } else {
         $user = new $c($email);
     }
     $user->hashPassword($password);
     try {
         $em->persist($user);
         $em->flush();
     } catch (\PDOException $e) {
         if (\Psc\Doctrine\Exception::convertPDOException($e) instanceof \Psc\Doctrine\UniqueConstraintException) {
             $output->writeln('User existiert bereits. --reset-password / -r nehmen, um ein neues Passwort zu erzeugen');
             return 3;
         }
         throw $e;
     }
     $output->writeln(sprintf('Passwort: "%s"', $password));
     $output->writeln('done.');
     return 0;
 }
Esempio n. 3
0
 public function testCreatePDOUniqueConstraintException()
 {
     $this->assertInstanceOf('PDOException', $e = $this->manager->createPDOUniqueConstraintException('my_unique_constraint'));
     $this->assertInstanceOf('Psc\\Doctrine\\UniqueConstraintException', $dce = \Psc\Doctrine\Exception::convertPDOException($e));
     $this->assertEquals('my_unique_constraint', $dce->uniqueConstraint);
 }
Esempio n. 4
0
 /**
  * Führt den Controller aus
  *
  * catched dabei Exceptions und wandelt diese gegebenfalls in Error-Responses um
  */
 public function runController($controller, $method, array $params)
 {
     $transactional = $controller instanceof \Psc\CMS\Controller\TransactionalController;
     try {
         try {
             $this->logf('running Controller: %s::%s(%s)', Code::getClass($controller), $method, implode(', ', array_map(function ($param) {
                 return Code::varInfo($param);
             }, $params)));
             $cb = new Callback($controller, $method);
             $controllerResponse = $cb->call($params);
             $this->log('Converting Controller Response');
             $this->setResponseFromControllerResponse($controllerResponse);
             $this->log('Response Format: ' . ($this->response->getFormat() ?: 'null'));
             $this->log('successful run');
             $this->log('überprüfe ResponseMetadataController');
             if ($controller instanceof \Psc\CMS\Controller\ResponseMetadataController && ($meta = $controller->getResponseMetadata()) != NULL) {
                 $this->response->setMetadata($meta);
                 $this->log('Metadaten übertragen');
             }
             /* PDO Exceptions */
         } catch (\PDOException $e) {
             throw \Psc\Doctrine\Exception::convertPDOException($e);
         }
     } catch (\Exception $e) {
         if ($transactional && $controller->hasActiveTransaction()) {
             $controller->rollbackTransaction();
         }
         $this->handleException($e);
     }
 }