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


PHP Assert::isMatching方法代码示例

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


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

示例1: error

 /**
  * Checks if the function generates PHP error or throws exception.
  * @param  callable
  * @param  int|string|array
  * @param  string message
  * @return null|Exception
  */
 public static function error($function, $expectedType, $expectedMessage = NULL)
 {
     if (is_string($expectedType) && !preg_match('#^E_[A-Z_]+\\z#', $expectedType)) {
         return static::exception($function, $expectedType, $expectedMessage);
     }
     $expected = is_array($expectedType) ? $expectedType : array(array($expectedType, $expectedMessage));
     foreach ($expected as &$item) {
         list($expectedType, $expectedMessage) = $item;
         if (is_int($expectedType)) {
             $item[2] = Helpers::errorTypeToString($expectedType);
         } elseif (is_string($expectedType)) {
             $item[0] = constant($item[2] = $expectedType);
         } else {
             throw new \Exception('Error type must be E_* constant.');
         }
     }
     set_error_handler(function ($severity, $message, $file, $line) use(&$expected) {
         if (($severity & error_reporting()) !== $severity) {
             return;
         }
         $errorStr = Helpers::errorTypeToString($severity) . ($message ? " ({$message})" : '');
         list($expectedType, $expectedMessage, $expectedTypeStr) = array_shift($expected);
         if ($expectedType === NULL) {
             restore_error_handler();
             Assert::fail("Generated more errors than expected: {$errorStr} was generated in file {$file} on line {$line}");
         } elseif ($severity !== $expectedType) {
             restore_error_handler();
             Assert::fail("{$expectedTypeStr} was expected, but {$errorStr} was generated in file {$file} on line {$line}");
         } elseif ($expectedMessage && !Assert::isMatching($expectedMessage, $message)) {
             restore_error_handler();
             Assert::fail("{$expectedTypeStr} with a message matching %2 was expected but got %1", $message, $expectedMessage);
         }
     });
     reset($expected);
     call_user_func($function);
     restore_error_handler();
     if ($expected) {
         self::fail('Error was expected, but was not generated');
     }
 }
开发者ID:jakuborava,项目名称:walletapp,代码行数:47,代码来源:Assert.php


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