/** * @test */ function isApplied_() { assertThat($this->table->isApplied("987654"), isFalse()); $this->table->fixVersion("987654"); assertThat($this->table->isApplied("987654"), isTrue()); assertThat($this->table->isApplied("123456"), isFalse()); }
public function testBoolean() { isTrue(true); isFalse(false); isNull(null); isNotNull(false); isNotNull(''); isNotNull(0); isNotNull(0.0); }
public function send() { // Don't send in development... if (isTrue(AppConfig::getValue('development'))) { (new Log(INFO_LOG))->logMessage('email (' . $this->mailer->Subject . ') sent to ' . (count($this->mailer->getToAddresses()) > 1 ? print_r($this->mailer->getToAddresses(), true) : $this->mailer->getToAddresses()[0][0]) . ', body: ' . $this->mailer->Body); return true; } // Test the Outcome (log errors) if (($status = $this->mailer->send()) === false) { $log = new Log(ERROR_LOG); $log->logMessage(__METHOD__ . ' failed, ' . $this->mailer->ErrorInfo); return false; } else { (new Log(INFO_LOG))->logMessage('email (' . $this->mailer->Subject . ') sent to ' . (count($this->mailer->getToAddresses()) > 1 ? print_r($this->mailer->getToAddresses(), true) : $this->mailer->getToAddresses()[0][0]) . ', body: ' . $this->mailer->Body); return true; } }
public function run() { // Determine the Correct Route $router = RouteController::getController(); $route = $router->findRouteForURL($this->request->url()); // Found Route? (default if not) if ($route) { // CSRF Protection (allow Stripe to avoid) -- if route name changes, it needs to change here! if ($route->action() != 'stripeNotification') { (new CSRFProtection())->enable(); } // Determine the Target Details... $target = array("controller" => $route->controller(), "method" => $route->method(), "args" => $route->extractArgs($this->request->url())); // Check Class & Method Exists... if (@method_exists($target['controller'], $target['method'])) { // Object Instantiation $instance = is_a($this, $target['controller']) ? $this : new $target['controller'](); // don't re-instantiate the AppController (self) if we're the target $instance->route_args = $target['args']; // provide target controller access to arguments in the route URL // Handover Control $instance->{$target['method']}(); // args are optional, can be null // Log the Performance Data... if (isTrue(AppConfig::getValue('log_performance'))) { PerformanceMonitor::logPerformanceData(); } // We need to return at this point, or we'll drop into the 404 code... return true; } } // Show a Friendly Error Page (fallback) $this->view = new HTMLView(true); $this->view->includeTemplate('error.not-found', ['app_name' => AppConfig::getValue('app_name')]); $this->view->render(true); }
public function testUndefinedRule() { isTrue(val('1 undefined')->isRule('eur')); }
public function testGetUri() { isTrue($this->_cms['request']->getUri()); }
public function testCompare() { isTrue($this->val('10kb')->compare('81920bit')); }
public function isUserAuthenticated($auth_required = true) { // Cached Result... (if checked before, return the result) if ($this->authentication != self::AUTH_UNKNOWN) { return $this->authentication == self::AUTH_PASSED; } // Check Token Validity -- Avoid DB Overhead if (self::isSessionIDValid($this->id)) { $db = Database::getConnection(); $query = $db->query("SELECT user_id, update_timestamp, persistent FROM " . self::TABLE_NAME . " WHERE (id=:id) AND (expiry_timestamp > :now)", array(":id" => $this->id, ":now" => Carbon::now())); } else { if (!$auth_required) { return false; } } // Check Query Result (and that it was executed) if (isset($query) && $query && $query->rowCount()) { $db_row = $query->fetch(PDO::FETCH_ASSOC); $this->user_id = $db_row['user_id']; // only set here, force people to call this function first before being allowed to look at the ID // We need to renew sessions on a regular basis in order for us to determine when sessions become inactive... if (Carbon::parse($db_row['update_timestamp'])->diffInSeconds(Carbon::now()) > self::SESSION_RENEWAL_PERIOD_SECONDS) { $this->create($db_row['user_id'], isTrue($db_row['persistent'])); } // renew $this->authentication = self::AUTH_PASSED; return true; } else { if ($auth_required) { // Determine the Current Target/Action $request = RequestModel::currentRequest(); $router = RouteController::getController(); $route = $router->findRouteForURL($request->url()); // Add Query Params? $url = $router->urlForAction($route->action(), $route->extractArgs($request->url())); if (count($request->queryArgArray())) { $url = addQueryParams($url, $request->queryArgArray()); } // Request a Login AppController::requestUserLogin($url); // we need to extract and re-inject any args or we lose context... } else { $this->authentication = self::AUTH_FAILED; return false; } } }
equals($name->default, "default name"); isTrue($name->nullable); equals($name->max, 128); isTrue($test->isString()); isFalse($test->primary); isFalse($test->increment); isNull($test->default); isTrue($test->nullable); equals($test->max, 255); isTrue($body->isText()); isFalse($body->primary); isFalse($body->increment); isNull($body->default); isFalse($body->nullable); isTrue($bool->isBool()); isFalse($bool->primary); isFalse($bool->increment); isFalse($bool->default); isTrue($bool->nullable); isNull($hoge->ft); isNull($hoge->dbl); isNull($hoge->sint); isNull($hoge->bint); Sabel_Db_Connection::closeAll(); $path = RUN_BASE . "/migration/tmp/1_Hoge_create.php"; system("php exec.php {$path} " . CONNAME . " downgrade"); $accessor = Sabel_Db::createMetadata(CONNAME); $tables = $accessor->getTableList(); isFalse(in_array("hoge", $tables)); Sabel_Db_Connection::closeAll(); echo "\n";
public function testGetLogs() { $logs = val()->logs(); isTrue(is_array($logs)); }
ini_set("auto_detect_line_endings", true); $file_name = 'csv/chain_list.csv'; $file_handle = fopen($file_name, "r"); /** * chain_id,chain_name */ $line_number = 0; $header_line = null; $schema_array = array(); while (($line = fgetcsv($file_handle, $file_name)) !== FALSE) { $line_number++; //Skip first line as they are the column headers in excel sheet if ($line_number == 1) { $header_line = $line; continue; } $attribute_name = $line[0]; $is_mandatory = $header_line[2]; $schema_array[$attribute_name] = array($is_mandatory => isTrue($line[2])); } $chain_list_schema_json = json_encode($schema_array); file_put_contents("schema/chain_list.json", $chain_list_schema_json); fclose($file_handle); function isTrue($value) { if (strcasecmp($value, "true") === 0) { return true; } else { return false; } }
/** @test */ public function itValidateAResponse() { $expectedViolations = [new ConstraintViolation('id', 'String value found, but an integer is required', 'type', 'body'), new ConstraintViolation('X-Required-Header', 'The property X-Required-Header is required', 'required', 'header')]; $headersSchema = $this->toObject(['type' => 'object', 'required' => ['X-Required-Header'], 'properties' => ['X-Required-Header' => ['type' => 'string']]]); $bodySchema = $this->toObject(['type' => 'object', 'properties' => ['id' => ['type' => 'integer', 'format' => 'int32']]]); $response = $this->prophesize(ResponseInterface::class); $response->getStatusCode()->willReturn('200'); $response->getBody()->willReturn('{"id": "invalid"}'); $response->getHeaderLine('Content-Type')->willReturn('application/json'); $response->getHeaders()->willReturn([]); $responseDefinition = $this->prophesize(RequestDefinition::class); $responseDefinition->getContentTypes()->willReturn(['application/json']); $responseDefinition->hasBodySchema()->willReturn(true); $responseDefinition->getBodySchema()->willReturn($bodySchema); $responseDefinition->hasHeadersSchema()->willReturn(true); $responseDefinition->getHeadersSchema()->willReturn($headersSchema); $definition = $this->prophesize(RequestDefinition::class); $definition->getResponseDefinition('200')->willReturn($responseDefinition); $this->messageValidator->validateResponse($response->reveal(), $definition->reveal()); assertThat($this->messageValidator->hasViolations(), isTrue()); assertThat($this->messageValidator->getViolations(), containsOnlyInstancesOf(ConstraintViolation::class)); assertThat($this->messageValidator->getViolations(), equalTo($expectedViolations)); }
//Skip first line as they are the column headers in excel sheet if ($line_number == 1) { $header_line = $line; continue; } $attribute_name = $line[0]; $form_display_text = $header_line[1]; $data_type = $header_line[3]; $is_multi_valued = $header_line[4]; $is_mandatory = $header_line[5]; $allowed_values = $header_line[6]; $default_value = $header_line[7]; $dependencies = $header_line[8]; $activate_dependency_on = $header_line[9]; $ui_element_prefix = $header_line[10]; $schema_array[$attribute_name] = array($form_display_text => trim($line[1]), $data_type => $line[3], $is_mandatory => isTrue($line[5]), $is_multi_valued => isTrue($line[4])); if (empty($line[6]) === false) { $values = explode(",", $line[6]); $schema_array[$attribute_name][$allowed_values] = cleanData($values); } if (empty($line[7]) === false) { $schema_array[$attribute_name][$default_value] = trim($line[7]); } if (empty($line[8]) === false) { $values = explode(",", $line[8]); $schema_array[$attribute_name][$dependencies] = cleanData($values); } if (empty($line[9]) === false) { $schema_array[$attribute_name][$activate_dependency_on] = trim($line[9]); } if (empty($line[10]) === false) {
$line_array = array(); while (($line = fgetcsv($file_handle, $file_name)) !== FALSE) { $line_number++; array_push($line_array, $line); //Skip first line as they are the column headers in excel sheet if ($line_number == 1) { $header_line = $line; continue; } $attribute_name = $line[0]; $is_mandatory = $header_line[2]; $is_multi_valued = $header_line[3]; $is_required_for_sms_verification = $header_line[4]; $dependencies = $header_line[5]; $allowed_values = $header_line[6]; $schema_array[$attribute_name] = array($is_mandatory => isTrue($line[2]), $is_multi_valued => isTrue($line[3]), $is_required_for_sms_verification => isTrue($line[4])); if (empty($line[5]) === false) { $schema_array[$attribute_name][$dependencies] = explode(",", $line[5]); } if (empty($line[6]) === false) { $schema_array[$attribute_name][$allowed_values] = explode(",", $line[6]); } } file_put_contents("schema/core_attributes.json", json_encode($schema_array)); fclose($file_handle); function isTrue($value) { if (strcasecmp($value, "true") === 0) { return true; } else { return false;
/** * @SuppressWarnings(PHPMD.Superglobals) * @backupGlobals */ public function testCyrillic() { isTrue(true); // Don't check it }
private function boolToString($bValue, $pt = "") { if (isTrue($bValue)) { if ($pt == "") { return "true"; } else { return "Yes"; } } else { if ($pt == "") { return "false"; } else { return "No"; } } }