isType() public static method

public static isType ( $type )
コード例 #1
0
 /**
  * Asserts that a variable is not of a given type.
  *
  * @param  string $expected
  * @param  mixed  $actual
  * @param  string $message
  * @access public
  * @static
  * @since  Method available since Release 2.2.0
  */
 public static function assertNotType($expected, $actual, $message = '')
 {
     if (is_string($expected)) {
         if (PHPUnit_Util_Type::isType($expected)) {
             $constraint = new PHPUnit_Framework_Constraint_Not(new PHPUnit_Framework_Constraint_IsType($expected));
         } else {
             if (class_exists($expected) || interface_exists($expected)) {
                 $constraint = new PHPUnit_Framework_Constraint_Not(new PHPUnit_Framework_Constraint_IsInstanceOf($expected));
             } else {
                 throw new InvalidArgumentException();
             }
         }
     } else {
         throw new InvalidArgumentException();
     }
     self::assertThat($actual, $constraint, $message);
 }
コード例 #2
0
 /**
  * Backported from PHPUnit 3.4 in order to maintain backwards
  * compatibility: assertType() is deprecated in PHPUnit 3.5 (with PHP 5.2.7+),
  * but as SilverStripe 2.3 and 2.4 support PHP 5.1 we can't require it.
  */
 public static function assertType($expected, $actual, $message = '')
 {
     // PHPUnit_Util_DeprecatedFeature_Logger::log(
     //   'assertType() will be removed in PHPUnit 3.6 and should no longer ' .
     //   'be used. assertInternalType() should be used for asserting ' .
     //   'internal types such as "integer" or "string" whereas ' .
     //   'assertInstanceOf() should be used for asserting that an object is ' .
     //   'an instance of a specified class or interface.'
     // );
     if (is_string($expected)) {
         if (PHPUnit_Util_Type::isType($expected)) {
             $constraint = new PHPUnit_Framework_Constraint_IsType($expected);
         } else {
             if (class_exists($expected) || interface_exists($expected)) {
                 $constraint = new PHPUnit_Framework_Constraint_IsInstanceOf($expected);
             } else {
                 throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'class or interface name');
             }
         }
     } else {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
     }
     self::assertThat($actual, $constraint, $message);
 }
コード例 #3
0
ファイル: Assert.php プロジェクト: karnurik/zf2-turtorial
 /**
  * Asserts that a haystack does not contain only values of a given type.
  *
  * @param string $type
  * @param mixed  $haystack
  * @param bool   $isNativeType
  * @param string $message
  * @since  Method available since Release 3.1.4
  */
 public static function assertNotContainsOnly($type, $haystack, $isNativeType = null, $message = '')
 {
     if (!(is_array($haystack) || is_object($haystack) && $haystack instanceof Traversable)) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'array or traversable');
     }
     if ($isNativeType == null) {
         $isNativeType = PHPUnit_Util_Type::isType($type);
     }
     self::assertThat($haystack, new PHPUnit_Framework_Constraint_Not(new PHPUnit_Framework_Constraint_TraversableContainsOnly($type, $isNativeType)), $message);
 }
コード例 #4
0
ファイル: Assert.php プロジェクト: redlion09/pcppi
 /**
  * Asserts that a variable is not of a given type.
  *
  * @param  string $expected
  * @param  mixed  $actual
  * @param  string $message
  * @since  Method available since Release 2.2.0
  */
 public static function assertNotType($expected, $actual, $message = '')
 {
     if (is_string($expected)) {
         if (PHPUnit_Util_Type::isType($expected)) {
             if (class_exists($expected) || interface_exists($expected)) {
                 throw new InvalidArgumentException(sprintf('"%s" is ambigious', $expected));
             }
             $constraint = new PHPUnit_Framework_Constraint_Not(new PHPUnit_Framework_Constraint_IsType($expected));
         } else {
             if (class_exists($expected) || interface_exists($expected)) {
                 $constraint = new PHPUnit_Framework_Constraint_Not(new PHPUnit_Framework_Constraint_IsInstanceOf($expected));
             } else {
                 throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'class or interface name');
             }
         }
     } else {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
     }
     self::assertThat($actual, $constraint, $message);
 }