本文整理汇总了PHP中PHPUnit_Util_Type::isType方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Util_Type::isType方法的具体用法?PHP PHPUnit_Util_Type::isType怎么用?PHP PHPUnit_Util_Type::isType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPUnit_Util_Type
的用法示例。
在下文中一共展示了PHPUnit_Util_Type::isType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: assertNotType
/**
* 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: assertType
/**
* 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: assertNotContainsOnly
/**
* 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: assertNotType
/**
* 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);
}