aboutsummaryrefslogtreecommitdiffstats
path: root/yamlishwriter-php-v0.0.1/t/lib/TestLite.php
blob: 231001bd56ea043d50ec02078aafec30395d6657 (plain) (blame)
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
<?php

    $NEXT_TEST = 1;

    function plan($tests) {
        print "1..$tests\n";
    }

    function ok($ok, $message = null) {
        global $NEXT_TEST;
        $out = "ok " . ($NEXT_TEST++);
        if (!$ok) {
            $out = 'not ' . $out;
        }
        if ($message) {
            $out .= " $message";
        }
        print "$out\n";
    }

    function pass($message) {
        ok(true, $message);
    }
    
    function fail($message) {
        ok(false, $message);
    }
    
    function diag($message) {
        $stdout = fopen('php://stderr', 'w'); 
        fwrite( $stdout, "# $message\n" );
        fclose( $stdout );             
    }

    function is_deeply_array( $got, $expected, $message ) {
        if ( gettype($got) != 'array' ) {
            fail($message);
            diag('$got is not an array');
            return;
        }
        
        if ( gettype($expected) != 'array' ) {
            fail($message);
            diag('$expected is not an array');
            return;
        }

        $ok         = true;
        $diag       = array();
        $got_c      = count( $got );
        $expected_c = count( $expected );

        if ($got_c != $expected_c) {
            $ok = false;
            $diag[] = 'Array sizes differ:';
            $diag[] = '      $got: ' . $got_c;
            $diag[] = ' $expected: ' . $expected_c;
        }

        $count = max( $got_c, $expected_c );
  
        for ($i = 0; $i < $count; $i++) {
            if ( $got[$i] != $expected[$i] ) {
                if ($ok) {
                    $ok = false;
                    $diag[] = 'Arrays differ:';
                }
                $diag[] = "       \$got[$i]: $got[$i]";
                $diag[] = "  \$expected[$i]: $expected[$i]";
            }
        }
        
        ok($ok, $message);
        foreach ($diag as $d) {
            diag($d);
        }
    }

?>