compatibility_test.php 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. // $Id: compatibility_test.php 1748 2008-04-14 01:50:41Z lastcraft $
  3. require_once(dirname(__FILE__) . '/../autorun.php');
  4. require_once(dirname(__FILE__) . '/../compatibility.php');
  5. class ComparisonClass { }
  6. class ComparisonSubclass extends ComparisonClass { }
  7. interface ComparisonInterface { }
  8. class ComparisonClassWithInterface implements ComparisonInterface { }
  9. class TestOfCompatibility extends UnitTestCase {
  10. function testIsA() {
  11. $this->assertTrue(SimpleTestCompatibility::isA(
  12. new ComparisonClass(),
  13. 'ComparisonClass'));
  14. $this->assertFalse(SimpleTestCompatibility::isA(
  15. new ComparisonClass(),
  16. 'ComparisonSubclass'));
  17. $this->assertTrue(SimpleTestCompatibility::isA(
  18. new ComparisonSubclass(),
  19. 'ComparisonClass'));
  20. }
  21. function testIdentityOfNumericStrings() {
  22. $numericString1 = "123";
  23. $numericString2 = "00123";
  24. $this->assertNotIdentical($numericString1, $numericString2);
  25. }
  26. function testIdentityOfObjects() {
  27. $object1 = new ComparisonClass();
  28. $object2 = new ComparisonClass();
  29. $this->assertIdentical($object1, $object2);
  30. }
  31. function testReferences () {
  32. $thing = "Hello";
  33. $thing_reference = &$thing;
  34. $thing_copy = $thing;
  35. $this->assertTrue(SimpleTestCompatibility::isReference(
  36. $thing,
  37. $thing));
  38. $this->assertTrue(SimpleTestCompatibility::isReference(
  39. $thing,
  40. $thing_reference));
  41. $this->assertFalse(SimpleTestCompatibility::isReference(
  42. $thing,
  43. $thing_copy));
  44. }
  45. function testObjectReferences () {
  46. $object = new ComparisonClass();
  47. $object_reference = $object;
  48. $object_copy = new ComparisonClass();
  49. $object_assignment = $object;
  50. $this->assertTrue(SimpleTestCompatibility::isReference(
  51. $object,
  52. $object));
  53. $this->assertTrue(SimpleTestCompatibility::isReference(
  54. $object,
  55. $object_reference));
  56. $this->assertFalse(SimpleTestCompatibility::isReference(
  57. $object,
  58. $object_copy));
  59. if (version_compare(phpversion(), '5', '>=')) {
  60. $this->assertTrue(SimpleTestCompatibility::isReference(
  61. $object,
  62. $object_assignment));
  63. } else {
  64. $this->assertFalse(SimpleTestCompatibility::isReference(
  65. $object,
  66. $object_assignment));
  67. }
  68. }
  69. function testInteraceComparison() {
  70. $object = new ComparisonClassWithInterface();
  71. $this->assertFalse(SimpleTestCompatibility::isA(
  72. new ComparisonClass(),
  73. 'ComparisonInterface'));
  74. $this->assertTrue(SimpleTestCompatibility::isA(
  75. new ComparisonClassWithInterface(),
  76. 'ComparisonInterface'));
  77. }
  78. }
  79. ?>