summaryrefslogtreecommitdiff
path: root/pear/tests/pear_common_buildProvidesArray.phpt
blob: 574ed4465c85426ca04283da2121062a501d12b7 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
--TEST--
PEAR_Common::buildProvidesArray test
--SKIPIF--
<?php
if (!getenv('PHP_PEAR_RUNTESTS')) {
    echo 'skip';
}
if (!function_exists('token_get_all')) {
    echo 'skip';
}
?>
--FILE--
<?php

require_once "PEAR/Common.php";

$testdir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'pear_common_buildProvidesArraytest';
mkdir($testdir);

$test5 = '
<?php
function test()
{
}

if (trytofool) {
    function fool()
    {
    }
}
class test2 {
    function test2() {
        parent::unused();
        Greg::classes();
        $a = new Pierre;
    }
}

class blah extends test2 {
    /**
     * @nodep Stig
     */
    function blah() 
    {
        Stig::rules();
    }
}
?>
';
$fp = fopen($testdir . DIRECTORY_SEPARATOR . 'test5.php', 'w');
fwrite($fp, $test5);
fclose($fp);

$ret = PEAR_Common::analyzeSourceCode($testdir . DIRECTORY_SEPARATOR . 'test5.php');
echo "pre-test: returns false with valid PHP? ";
echo $ret ? "no\n" : "yes\n";
$ret['source_file'] = str_replace(array(dirname(__FILE__),DIRECTORY_SEPARATOR), array('', '/'), $ret['source_file']);
var_dump($ret);
unlink($testdir . DIRECTORY_SEPARATOR . 'test5.php');
$common = new PEAR_Common;
$common->buildProvidesArray($ret);
var_dump($common->pkginfo);
rmdir($testdir);
?>
--EXPECT--
pre-test: returns false with valid PHP? no
array(6) {
  ["source_file"]=>
  string(45) "/pear_common_buildProvidesArraytest/test5.php"
  ["declared_classes"]=>
  array(2) {
    [0]=>
    string(5) "test2"
    [1]=>
    string(4) "blah"
  }
  ["declared_methods"]=>
  array(2) {
    ["test2"]=>
    array(1) {
      [0]=>
      string(5) "test2"
    }
    ["blah"]=>
    array(1) {
      [0]=>
      string(4) "blah"
    }
  }
  ["declared_functions"]=>
  array(2) {
    [0]=>
    string(4) "test"
    [1]=>
    string(4) "fool"
  }
  ["used_classes"]=>
  array(2) {
    [0]=>
    string(4) "Greg"
    [1]=>
    string(6) "Pierre"
  }
  ["inheritance"]=>
  array(1) {
    ["blah"]=>
    string(5) "test2"
  }
}
array(1) {
  ["provides"]=>
  array(4) {
    ["class;test2"]=>
    array(3) {
      ["file"]=>
      string(9) "test5.php"
      ["type"]=>
      string(5) "class"
      ["name"]=>
      string(5) "test2"
    }
    ["class;blah"]=>
    array(4) {
      ["file"]=>
      string(9) "test5.php"
      ["type"]=>
      string(5) "class"
      ["name"]=>
      string(4) "blah"
      ["extends"]=>
      string(5) "test2"
    }
    ["function;test"]=>
    array(3) {
      ["file"]=>
      string(9) "test5.php"
      ["type"]=>
      string(8) "function"
      ["name"]=>
      string(4) "test"
    }
    ["function;fool"]=>
    array(3) {
      ["file"]=>
      string(9) "test5.php"
      ["type"]=>
      string(8) "function"
      ["name"]=>
      string(4) "fool"
    }
  }
}