aboutsummaryrefslogtreecommitdiff
path: root/vendors/simpletest/test/compatibility_test.php
blob: ea48f8396ad40d5735d01679c115c4e5c0c78495 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
// $Id: compatibility_test.php 1505 2007-04-30 23:39:59Z lastcraft $
require_once(dirname(__FILE__) . '/../autorun.php');
require_once(dirname(__FILE__) . '/../compatibility.php');

class ComparisonClass {
}

class ComparisonSubclass extends ComparisonClass {
}

if (version_compare(phpversion(), '5') >= 0) {
    eval('interface ComparisonInterface { }');
    eval('class ComparisonClassWithInterface implements ComparisonInterface { }');
}

class TestOfCompatibility extends UnitTestCase {
    
    function testIsA() {
        $this->assertTrue(SimpleTestCompatibility::isA(
                new ComparisonClass(),
                'ComparisonClass'));
        $this->assertFalse(SimpleTestCompatibility::isA(
                new ComparisonClass(),
                'ComparisonSubclass'));
        $this->assertTrue(SimpleTestCompatibility::isA(
                new ComparisonSubclass(),
                'ComparisonClass'));
    }
    
    function testIdentityOfNumericStrings() {
        $numericString1 = "123";
        $numericString2 = "00123";
        $this->assertNotIdentical($numericString1, $numericString2);
    }
    
    function testIdentityOfObjects() {
        $object1 = new ComparisonClass();
        $object2 = new ComparisonClass();
        $this->assertIdentical($object1, $object2);
    }
    
    function testReferences () {
        $thing = "Hello";
        $thing_reference = &$thing;
        $thing_copy = $thing;
        $this->assertTrue(SimpleTestCompatibility::isReference(
                $thing,
                $thing));
        $this->assertTrue(SimpleTestCompatibility::isReference(
                $thing,
                $thing_reference));
        $this->assertFalse(SimpleTestCompatibility::isReference(
                $thing,
                $thing_copy));
    }
    
    function testObjectReferences () {
        $object = &new ComparisonClass();
        $object_reference = &$object;
        $object_copy = new ComparisonClass();
        $object_assignment = $object;
        $this->assertTrue(SimpleTestCompatibility::isReference(
                $object,
                $object));
        $this->assertTrue(SimpleTestCompatibility::isReference(
                $object,
                $object_reference));
        $this->assertFalse(SimpleTestCompatibility::isReference(
                $object,
                $object_copy));
        if (version_compare(phpversion(), '5', '>=')) {
            $this->assertTrue(SimpleTestCompatibility::isReference(
                    $object,
                    $object_assignment));
        } else {
            $this->assertFalse(SimpleTestCompatibility::isReference(
                    $object,
                    $object_assignment));
        }
    }
    
    function testInteraceComparison() {
        if (version_compare(phpversion(), '5', '<')) {
            return;
        }
        
        $object = new ComparisonClassWithInterface();
        $this->assertFalse(SimpleTestCompatibility::isA(
                new ComparisonClass(),
                'ComparisonInterface'));
        $this->assertTrue(SimpleTestCompatibility::isA(
                new ComparisonClassWithInterface(),
                'ComparisonInterface'));
    }
}
?>