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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
--TEST--
PEAR_PackageFile_v2_Validator->analyzeSourceCode test
--SKIPIF--
<?php
if (!getenv('PHP_PEAR_RUNTESTS')) {
echo 'skip';
}
if (!function_exists('token_get_all')) {
echo 'skip';
}
?>
--FILE--
<?php
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'setup.php.inc';
$pathtopackagexml = dirname(__FILE__) . DIRECTORY_SEPARATOR .
'Parser'. DIRECTORY_SEPARATOR .
'test_basicparse'. DIRECTORY_SEPARATOR . 'package2.xml';
$pf = $parser->parse(implode('', file($pathtopackagexml)), $pathtopackagexml);
$pf->flattenFilelist();
require_once 'PEAR/PackageFile/v2/Validator.php';
$val = new PEAR_PackageFile_v2_Validator;
$val->validate($pf); // setup purposes only
$phpunit->assertNoErrors('setup');
$phpunit->assertFalse($val->analyzeSourceCode('=+"\\//452'), 'invalid filename');
$testdir = $statedir;
@mkdir($testdir);
$test1 = '
<?php
::error();
?>
';
$fp = fopen($testdir . DIRECTORY_SEPARATOR . 'test1.php', 'w');
fwrite($fp, $test1);
fclose($fp);
$ret = $val->analyzeSourceCode($testdir . DIRECTORY_SEPARATOR . 'test1.php');
$phpunit->assertErrors(array(
array('package' => 'PEAR_PackageFile_v2', 'message' =>
'Parser error: invalid PHP found in file "' . $testdir . DIRECTORY_SEPARATOR . 'test1.php"')),
'invalid php');
$phpunit->assertFalse($ret, 'wrong return value, invalid php in file');
unlink($testdir . DIRECTORY_SEPARATOR . 'test1.php');
$test3 = '
<?php
class test
{
class test2 {
}
}
?>
';
$fp = fopen($testdir . DIRECTORY_SEPARATOR . 'test3.php', 'w');
fwrite($fp, $test3);
fclose($fp);
$ret = $val->analyzeSourceCode($testdir . DIRECTORY_SEPARATOR . 'test3.php');
$phpunit->assertErrors(array(
array('package' => 'PEAR_PackageFile_v2', 'message' =>
'Parser error: invalid PHP found in file "' . $testdir . DIRECTORY_SEPARATOR . 'test3.php"')),
'more invalid php');
$phpunit->assertFalse($ret, 'wrong return value, 2nd invalid PHP test');
unlink($testdir . DIRECTORY_SEPARATOR . 'test3.php');
$test4 = '
<?php
function test()
{
class test2 {
}
}
?>
';
$fp = fopen($testdir . DIRECTORY_SEPARATOR . 'test4.php', 'w');
fwrite($fp, $test4);
fclose($fp);
$ret = $val->analyzeSourceCode($testdir . DIRECTORY_SEPARATOR . 'test4.php');
$phpunit->assertErrors(array(
array('package' => 'PEAR_PackageFile_v2', 'message' =>
'Parser error: invalid PHP found in file "' . $testdir . DIRECTORY_SEPARATOR . 'test4.php"')),
'3rd invalid php');
$phpunit->assertFalse($ret, 'wrong return value, 3rd invalid PHP test');
unlink($testdir . DIRECTORY_SEPARATOR . 'test4.php');
$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 = $val->analyzeSourceCode($testdir . DIRECTORY_SEPARATOR . 'test5.php');
$phpunit->assertNoErrors('1st valid PHP');
$phpunit->showall();
$phpunit->assertEquals(array (
'source_file' => $testdir . DIRECTORY_SEPARATOR . 'test5.php',
'declared_classes' =>
array (
0 => 'test2',
1 => 'blah',
),
'declared_interfaces' =>
array (
),
'declared_methods' =>
array (
'test2' =>
array (
0 => 'test2',
),
'blah' =>
array (
0 => 'blah',
),
),
'declared_functions' =>
array (
0 => 'test',
1 => 'fool',
),
'used_classes' =>
array (
0 => 'Greg',
1 => 'Pierre',
),
'inheritance' =>
array (
'blah' => 'test2',
),
'implements' =>
array (
),
), $ret, 'wrong return value, 1st valid PHP test');
echo 'tests done';
?>
--CLEAN--
<?php
require_once dirname(__FILE__) . '/teardown.php.inc';
?>
--EXPECT--
tests done
|