Skip to content
This repository
Browse code

MINOR Added deprecated SapphireTest->assertType() in order to support…

… PHPUnit 3.5 or newer, but stay backwards compatible to PHPUnit 3.4
  • Loading branch information...
commit 201506e2991d81e4b76280bf5faf50ae2efceba5 1 parent 900b0a7
Ingo Schommer authored February 21, 2011

Showing 1 changed file with 39 additions and 0 deletions. Show diff stats Hide diff stats

  1. 39  dev/SapphireTest.php
39  dev/SapphireTest.php
@@ -575,6 +575,45 @@ function assertDOSAllMatch($match, $dataObjectSet) {
575 575
 	} 
576 576
 	
577 577
 	/**
  578
+	 * Backported from PHPUnit 3.4 in order to maintain backwards
  579
+	 * compatibility: assertType() is deprecated in PHPUnit 3.5 (with PHP 5.2.7+),
  580
+	 * but as SilverStripe 2.3 and 2.4 support PHP 5.1 we can't require it.
  581
+	 */
  582
+	public static function assertType($expected, $actual, $message = '') {
  583
+      // PHPUnit_Util_DeprecatedFeature_Logger::log(
  584
+      //   'assertType() will be removed in PHPUnit 3.6 and should no longer ' .
  585
+      //   'be used. assertInternalType() should be used for asserting ' .
  586
+      //   'internal types such as "integer" or "string" whereas ' .
  587
+      //   'assertInstanceOf() should be used for asserting that an object is ' .
  588
+      //   'an instance of a specified class or interface.'
  589
+      // );
  590
+
  591
+      if (is_string($expected)) {
  592
+          if (PHPUnit_Util_Type::isType($expected)) {
  593
+              $constraint = new PHPUnit_Framework_Constraint_IsType(
  594
+                $expected
  595
+              );
  596
+          }
  597
+
  598
+          else if (class_exists($expected) || interface_exists($expected)) {
  599
+              $constraint = new PHPUnit_Framework_Constraint_IsInstanceOf(
  600
+                $expected
  601
+              );
  602
+          }
  603
+
  604
+          else {
  605
+              throw PHPUnit_Util_InvalidArgumentHelper::factory(
  606
+                1, 'class or interface name'
  607
+              );
  608
+          }
  609
+      } else {
  610
+          throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
  611
+      }
  612
+
  613
+      self::assertThat($actual, $constraint, $message);
  614
+  }
  615
+	
  616
+	/**
578 617
 	 * Helper function for the DOS matchers
579 618
 	 */
580 619
 	private function dataObjectArrayMatch($item, $match) {

0 notes on commit 201506e

Please sign in to comment.
Something went wrong with that request. Please try again.