Skip to content

Commit

Permalink
MINOR Added deprecated SapphireTest->assertType() in order to support…
Browse files Browse the repository at this point in the history
… PHPUnit 3.5 or newer, but stay backwards compatible to PHPUnit 3.4
  • Loading branch information
chillu committed Mar 11, 2011
1 parent 2184acf commit 002e40b
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions dev/SapphireTest.php
Expand Up @@ -583,6 +583,45 @@ function assertDOSAllMatch($match, $dataObjectSet) {
}
}

/**
* 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);
}

/**
* Helper function for the DOS matchers
*/
Expand Down

0 comments on commit 002e40b

Please sign in to comment.