/** * Validiert die gespeicherte Rule * * Achtung! nicht bool zurückgeben, stattdessen irgendeine Exception schmeissen * @return $data */ public function validate($data) { if (isset($this->callback)) { return $this->callback->call(array($data)); } throw new \Psc\Exception('empty rule!'); }
public function testCalledChangesState() { $callback = new Callback(function () { // empty }); $this->assertFalse($callback->wasCalled()); $this->assertEquals(0, $callback->getCalled()); $callback->call(); $this->assertTrue($callback->wasCalled()); $this->assertEquals(1, $callback->getCalled()); $callback->call(); $this->assertEquals(2, $callback->getCalled()); }
public function validate($data) { $e = new EmptyDataException(); $e->setDefaultValue(array()); if ($data === NULL) { throw $e; } if (trim($data) == ',') { throw $e; } $cb = new Callback($this->tagsClass, 'toCollection'); return $cb->call(array($data)); }
public function testErrorHandler() { $rec = '*****@*****.**'; $eh = new ErrorHandler(); $this->assertInstanceOf($this->c, $eh->setRecipient($rec)); $this->assertEquals($rec, $eh->getRecipient()); $eh->setRecipient(NULL); // denn mail können wir lokal nicht // wir "faken" einen Error //trigger_error('Hier ist ein FakeFehler', E_USER_ERROR); // dies ist der var export wenn man das oben ausführt $errorParams = array(0 => 256, 1 => 'Hier ist ein FakeFehler', 2 => 'D:\\www\\psc-cms\\Umsetzung\\base\\src\\psc\\tests\\Code\\ErrorHandlerTest.php', 3 => 23, 4 => array('rec' => '*****@*****.**', 'eh' => $eh)); // hier der Fake $cb = new Callback($eh, 'handle'); try { $cb->call($errorParams); } catch (\ErrorException $e) { $this->assertEquals(256, $e->getSeverity()); $this->assertEquals(0, $e->getCode()); $this->assertEquals('Hier ist ein FakeFehler', $e->getMessage()); } // wie asserten wir hier, dass error_log() was geschrieben hat? }
/** * 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); } }