当前位置: 首页>>代码示例>>PHP>>正文


PHP Assert类代码示例

本文整理汇总了PHP中Assert的典型用法代码示例。如果您正苦于以下问题:PHP Assert类的具体用法?PHP Assert怎么用?PHP Assert使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Assert类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testAsserts

 public function testAsserts()
 {
     $wrapper = new Assert();
     $this->assertEquals(
         file_get_contents(__DIR__ . '/_files/Asserts-origin.php'),
         $wrapper->process(file_get_contents(__DIR__ . '/_files/Asserts.php')));
 }
开发者ID:necromant2005,项目名称:AOP,代码行数:7,代码来源:AssertTest.php

示例2: __construct

 function __construct($name, $address)
 {
     Assert::isScalar($name);
     Assert::isScalar($address);
     $this->name = $name;
     $this->address = $address;
 }
开发者ID:phoebius,项目名称:phoebius.com,代码行数:7,代码来源:ViewLink.php

示例3: __construct

 /**
  * @param string $func name of the aggregate
  * @param string $expression property to be used for aggregation
  * @param string $alias optional label for the result of the aggregator
  */
 function __construct($func, $expression = null, $alias = null)
 {
     Assert::isScalar($func);
     $this->func = $func;
     $this->expression = $expression;
     $this->alias = $alias;
 }
开发者ID:phoebius,项目名称:phoebius,代码行数:12,代码来源:AggrProjection.class.php

示例4: castNumber

 protected function castNumber($number)
 {
     if (!$this->scalar && Assert::checkInteger($number)) {
         return (int) $number;
     }
     return $number;
 }
开发者ID:rero26,项目名称:onphp-framework,代码行数:7,代码来源:IdentifiablePrimitive.class.php

示例5: __construct

 /**
  * @param string $name name of the column
  * @param ISqlType $type SQL type of the column
  */
 function __construct($name, DBTable $table, ISqlType $type)
 {
     Assert::isScalar($name);
     $this->name = $name;
     $this->table = $table;
     $this->type = $type;
 }
开发者ID:phoebius,项目名称:phoebius,代码行数:11,代码来源:DBColumn.class.php

示例6: __construct

 public function __construct()
 {
     require ONPHP_META_AUTO_DIR . 'schema.php';
     Assert::isTrue(isset($schema));
     $this->schema = $schema;
     // in case of unclean shutdown of previous tests
     foreach (DBTestPool::me()->getPool() as $name => $db) {
         foreach ($this->schema->getTableNames() as $name) {
             try {
                 $db->queryRaw(OSQL::dropTable($name, true)->toDialectString($db->getDialect()));
             } catch (DatabaseException $e) {
                 // ok
             }
             if ($db->hasSequences()) {
                 foreach ($this->schema->getTableByName($name)->getColumns() as $columnName => $column) {
                     try {
                         if ($column->isAutoincrement()) {
                             $db->queryRaw("DROP SEQUENCE {$name}_id;");
                         }
                     } catch (DatabaseException $e) {
                         // ok
                     }
                 }
             }
         }
     }
 }
开发者ID:onphp-framework,项目名称:onphp-framework,代码行数:27,代码来源:TestTables.class.php

示例7: __construct

 /**
  * @param boolean whether to use include path or not
  * @param boolean whether to allow pre-scanning technique or not. PreScan is important for 
  * huge and distributed class locations
  */
 function __construct($useIncludePath = true, $allowPreScan = false)
 {
     Assert::isBoolean($allowPreScan);
     $this->allowPreScan = $allowPreScan;
     parent::__construct($useIncludePath);
     $this->setExtension(PHOEBIUS_TYPE_EXTENSION);
 }
开发者ID:phoebius,项目名称:phoebius,代码行数:12,代码来源:CSharpStyleClassResolver.class.php

示例8: set

 public function set($name, $value)
 {
     if (!isset($this->mapping[$name])) {
         throw new WrongArgumentException("knows nothing about property '{$name}'");
     }
     $primitive = $this->mapping[$name];
     $setter = 'set' . ucfirst($primitive->getName());
     if (!method_exists($this->object, $setter)) {
         throw new WrongArgumentException("cannot find mutator for '{$name}' in class " . get_class($this->object));
     }
     if (is_object($value)) {
         if ($primitive instanceof PrimitiveAnyType && $value instanceof PrototypedEntity) {
             $value = ObjectToDTOConverter::create($value->entityProto())->make($value);
         } else {
             $value = $this->dtoValue($value, $primitive);
         }
     } elseif (is_array($value) && is_object(current($value))) {
         $dtoValue = array();
         foreach ($value as $oneValue) {
             Assert::isTrue(is_object($oneValue), 'array must contain only objects');
             $dtoValue[] = $this->dtoValue($oneValue, $primitive);
         }
         $value = $dtoValue;
     }
     return $this->object->{$setter}($value);
 }
开发者ID:onphp-framework,项目名称:onphp-framework,代码行数:26,代码来源:DTOSetter.class.php

示例9: import

 public function import($scope)
 {
     if (!$this->className) {
         throw new WrongStateException("no class defined for PrimitiveIdentifierList '{$this->name}'");
     }
     if (!BasePrimitive::import($scope)) {
         return null;
     }
     if (!is_array($scope[$this->name])) {
         return false;
     }
     $list = array_unique($scope[$this->name]);
     $values = array();
     foreach ($list as $id) {
         if (!Assert::checkInteger($id)) {
             return false;
         }
         $values[] = $id;
     }
     $objectList = array();
     foreach ($values as $value) {
         $className = $this->className;
         $objectList[] = new $className($value);
     }
     if (count($objectList) == count($values)) {
         $this->value = $objectList;
         return true;
     }
     return false;
 }
开发者ID:onphp-framework,项目名称:onphp-framework,代码行数:30,代码来源:PrimitiveEnumList.class.php

示例10: __construct

 /**
  * @param string $field name of the column
  * @param string $table optional name of the table that owns the column
  */
 function __construct($field, $table = null)
 {
     Assert::isScalar($field);
     Assert::isScalarOrNull($table);
     $this->field = $field;
     $this->table = $table;
 }
开发者ID:phoebius,项目名称:phoebius,代码行数:11,代码来源:SqlColumn.class.php

示例11: setAllowedMethodsHeaders

 public static function setAllowedMethodsHeaders($allowed_methods_arr)
 {
     Assert::assert(is_array($allowed_methods_arr));
     self::setAccessControlAllowOriginHeader();
     header('Access-Control-Allow-Methods: ' . implode(', ', $allowed_methods_arr));
     header('Allow: ' . implode(', ', $allowed_methods_arr));
 }
开发者ID:o-log,项目名称:php-lib,代码行数:7,代码来源:Exits.php

示例12: setup

 /**
  * Configures PHP environment.
  * @return void
  */
 public static function setup()
 {
     self::$useColors = getenv('NETTE_TESTER_COLORS') !== FALSE ? (bool) getenv('NETTE_TESTER_COLORS') : PHP_SAPI === 'cli' && (function_exists('posix_isatty') && posix_isatty(STDOUT) || getenv('ConEmuANSI') === 'ON' || getenv('ANSICON') !== FALSE);
     class_exists('Tester\\Runner\\Job');
     class_exists('Tester\\Dumper');
     class_exists('Tester\\Assert');
     error_reporting(E_ALL | E_STRICT);
     ini_set('display_errors', TRUE);
     ini_set('html_errors', FALSE);
     ini_set('log_errors', FALSE);
     set_exception_handler(array(__CLASS__, 'handleException'));
     set_error_handler(function ($severity, $message, $file, $line) {
         if (in_array($severity, array(E_RECOVERABLE_ERROR, E_USER_ERROR)) || ($severity & error_reporting()) === $severity) {
             Environment::handleException(new \ErrorException($message, 0, $severity, $file, $line));
         }
         return FALSE;
     });
     register_shutdown_function(function () {
         Assert::$onFailure = array(__CLASS__, 'handleException');
         // note that Runner is unable to catch this errors in CLI & PHP 5.4.0 - 5.4.6 due PHP bug #62725
         $error = error_get_last();
         if (in_array($error['type'], array(E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE)) && ($error['type'] & error_reporting()) !== $error['type']) {
             register_shutdown_function(function () use($error) {
                 echo "\nFatal error: {$error['message']} in {$error['file']} on line {$error['line']}\n";
             });
         }
     });
 }
开发者ID:jakuborava,项目名称:walletapp,代码行数:32,代码来源:Environment.php

示例13: run_is_true_with_four_chains

/**
 * @param int $iterations
 * @return array
 */
function run_is_true_with_four_chains($iterations)
{
    $start = microtime(true);
    for ($i = 0; $i < $iterations; $i++) {
        Assert::argument()->is_true(true)->is_true(true)->is_true(true)->is_true(true);
    }
    $end = microtime(true);
    $assert_time = $end - $start;
    $start = microtime(true);
    for ($i = 0; $i < $iterations; $i++) {
        Assert::argument()->is_true(true)->is_true(true)->is_true(true)->is_true(true);
    }
    $end = microtime(true);
    $assert_time = $end - $start;
    $start = microtime(true);
    for ($i = 0; $i < $iterations; $i++) {
        if (!(true === true)) {
            throw new InvalidArgumentException("unacceptable!");
        }
        if (!(true === true)) {
            throw new InvalidArgumentException("unacceptable!");
        }
        if (!(true === true)) {
            throw new InvalidArgumentException("unacceptable!");
        }
        if (!(true === true)) {
            throw new InvalidArgumentException("unacceptable!");
        }
    }
    $end = microtime(true);
    $base_time = $end - $start;
    return [$base_time, $assert_time, $assert_time];
}
开发者ID:tempbottle,项目名称:augmented_types,代码行数:37,代码来源:bench.php

示例14: admin_index

 /**
  * undocumented function
  *
  * @return void
  * @access public
  */
 function admin_index()
 {
     Assert::true(User::allowed($this->name, $this->action), '403');
     $defaults = array('model' => null, 'user_id' => null, 'my_limit' => 20, 'custom_limit' => false, 'start_date_day' => '01', 'start_date_year' => date('Y'), 'start_date_month' => '01', 'end_date_day' => '31', 'end_date_year' => date('Y'), 'end_date_month' => '12');
     $params = am($defaults, $this->params['url'], $this->params['named']);
     unset($params['ext']);
     unset($params['url']);
     if (is_numeric($params['custom_limit'])) {
         if ($params['custom_limit'] > 75) {
             $params['custom_limit'] = 75;
         }
         if ($params['custom_limit'] == 0) {
             $params['custom_limit'] = 50;
         }
         $params['my_limit'] = $params['custom_limit'];
     }
     $conditions = array();
     if (!empty($params['model'])) {
         $conditions['Log.model'] = $params['model'];
     }
     if (!empty($params['user_id'])) {
         $conditions['Log.user_id'] = $params['user_id'];
     }
     $conditions = $this->Log->dateRange($conditions, $params, 'created');
     $this->Session->write('logs_filter_conditions', $conditions);
     $userOptions = ClassRegistry::init('User')->find('list', array('conditions' => array('User.office_id' => $this->Session->read('Office.id'))));
     $this->paginate['Log'] = array('conditions' => $conditions, 'contain' => array('User', 'Gift', 'Transaction'), 'limit' => $params['my_limit'], 'order' => array('Log.continuous_id' => 'desc'));
     $logs = $this->paginate($this->Log);
     $this->set(compact('logs', 'params', 'userOptions'));
 }
开发者ID:stripthis,项目名称:donate,代码行数:36,代码来源:logs_controller.php

示例15: __construct

 function __construct($title = null, $block = false)
 {
     Assert::isScalarOrNull($title);
     Assert::isBoolean($block);
     $this->title = $title;
     $this->block = $block;
 }
开发者ID:phoebius,项目名称:phoebius.com,代码行数:7,代码来源:SiteDocChapter.class.php


注:本文中的Assert类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。