Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * Test suite for the PHP_CompatInfo_Cli class
4
 *
5
 * PHP version 5
6
 *
7
 * @category PHP
8
 * @package  PHP_CompatInfo
9
 * @author   Laurent Laville <pear@laurent-laville.org>
10
 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD
11
 * @version  CVS: $Id: PHP_CompatInfo_TestSuite_Cli.php,v 1.26 2008/12/18 23:06:45 farell Exp $
12
 * @link     http://pear.php.net/package/PHP_CompatInfo
13
 * @since    File available since Release 1.6.0
14
 */
15
if (!defined("PHPUnit_MAIN_METHOD")) {
16
    define("PHPUnit_MAIN_METHOD", "PHP_CompatInfo_TestSuite_Cli::main");
17
}
18
 
19
require_once "PHPUnit/Framework/TestCase.php";
20
require_once "PHPUnit/Framework/TestSuite.php";
21
 
22
require_once 'PHP/CompatInfo/Cli.php';
23
 
24
/**
25
 * Test suite class to test standard PHP_CompatInfo API.
26
 *
27
 * @category PHP
28
 * @package  PHP_CompatInfo
29
 * @author   Laurent Laville <pear@laurent-laville.org>
30
 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD
31
 * @version  Release: 1.9.0
32
 * @link     http://pear.php.net/package/PHP_CompatInfo
33
 * @since    File available since Release 1.6.0
34
 */
35
class PHP_CompatInfo_TestSuite_Cli extends PHPUnit_Framework_TestCase
36
{
37
    /**
38
     * A PCI object
39
     * @var  object
40
     */
41
    protected $pci;
42
 
43
    /**
44
     * Runs the test methods of this class.
45
     *
46
     * @return void
47
     */
48
    public static function main()
49
    {
50
        include_once "PHPUnit/TextUI/TestRunner.php";
51
 
52
        $suite = new PHPUnit_Framework_TestSuite('PHP_CompatInfo CLI Tests');
53
        PHPUnit_TextUI_TestRunner::run($suite);
54
    }
55
 
56
    /**
57
     * Sets up the fixture.
58
     * This method is called before a test is executed.
59
     *
60
     * @return void
61
     */
62
    protected function setUp()
63
    {
64
        $this->pci = new PHP_CompatInfo_Cli();
65
    }
66
 
67
    /**
68
     * Tears down the fixture.
69
     * This method is called after a test is executed.
70
     *
71
     * @return void
72
     */
73
    protected function tearDown()
74
    {
75
        unset($this->pci);
76
    }
77
 
78
    /**
79
     * Test if a dictionary for an Extension is available or not
80
     *
81
     * @param array  $resources   List of Extension dictionaries
82
     *                            that should be present to perform a unit test
83
     * @param array &$testSkipped Reasons of tests skipped
84
     *
85
     * @return bool
86
     * @since  version 1.9.0b2
87
     */
88
    private function isResourceAvailable($resources, &$testSkipped)
89
    {
90
        $dict = array();
91
        foreach ($resources as $ext) {
92
            if (!isset($GLOBALS['_PHP_COMPATINFO_FUNC_'.strtoupper($ext)])) {
93
                $dict[] = $ext;
94
            }
95
        }
96
        if (count($dict) == 1) {
97
            $testSkipped[] = 'The '. $dict[0] .
98
                             ' function dictionary is not available.';
99
        } elseif (count($dict) > 1) {
100
            $testSkipped[] = 'The '. implode(',', $dict) .
101
                             ' function dictionaries are not available.';
102
        }
103
        return (count($testSkipped) == 0);
104
    }
105
 
106
    /**
107
     * Assert results of php exec returns
108
     *
109
     * @param string $args Arguments list that will be pass to the 'pci' command
110
     * @param array  $exp  PCI output results expected
111
     *
112
     * @return void
113
     */
114
    private function assertPhpExec($args, $exp)
115
    {
116
        $command = '/usr/bin/php '
117
                 . '-f /usr/bin' . DIRECTORY_SEPARATOR . 'pci -- ';
118
 
119
        $output = array();
120
        $return = 0;
121
        exec("$command $args", $output, $return);
122
        if ($return == 0) {
123
            $this->assertEquals($exp, $output);
124
        } else {
125
            $this->assertTrue($return);
126
        }
127
    }
128
 
129
    /**
130
     * Regression test for bug #3657
131
     *
132
     * @return void
133
     * @link   http://pear.php.net/bugs/bug.php?id=3657
134
     *         php5 clone constant/token in all sources
135
     * @covers PHP_CompatInfo::parseFile
136
     * @group  parseFile
137
     */
138
    public function testBug3657()
139
    {
140
        $ds  = DIRECTORY_SEPARATOR;
141
        $exp = array('+-----------------------------+---------+------------+--------------------+',
142
                     '| File                        | Version | Extensions | Constants/Tokens   |',
143
                     '+-----------------------------+---------+------------+--------------------+',
144
                     '| ...File'.$ds.'phpweb-entities.php | 4.0.0   |            | FALSE              |',
145
                     '|                             |         |            | __FILE__           |',
146
                     '+-----------------------------+---------+------------+--------------------+');
147
 
148
        $fn = dirname(__FILE__) . $ds . 'parseFile' . $ds . 'phpweb-entities.php';
149
 
150
        $args = '-o 30 -f ' . $fn;
151
        $this->assertPhpExec($args, $exp);
152
    }
153
 
154
    /**
155
     * Regression test for bug #6581
156
     *
157
     * @return void
158
     * @link   http://pear.php.net/bugs/bug.php?id=6581
159
     *         Functions missing in func_array.php
160
     * @covers PHP_CompatInfo::parseFile
161
     * @group  parseFile
162
     */
163
    public function testBug6581()
164
    {
165
        $resources   = array('bcmath', 'pcre');
166
        $testSkipped = array();
167
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
168
            foreach ($testSkipped as $reason) {
169
                $this->markTestSkipped($reason);
170
            }
171
        }
172
 
173
        $ds  = DIRECTORY_SEPARATOR;
174
        $exp = array('+-----------------------------+---------+------------+--------------------+',
175
                     '| File                        | Version | Extensions | Constants/Tokens   |',
176
                     '+-----------------------------+---------+------------+--------------------+',
177
                     '| ...tests'.$ds.'parseFile'.$ds.'math.php | 4.0.0   | bcmath     |                    |',
178
                     '|                             |         | pcre       |                    |',
179
                     '+-----------------------------+---------+------------+--------------------+');
180
 
181
        $fn = dirname(__FILE__) . $ds . 'parseFile' . $ds . 'math.php';
182
 
183
        $args = '-o 30 -f ' . $fn;
184
        $this->assertPhpExec($args, $exp);
185
    }
186
 
187
    /**
188
     * Tests parsing an empty directory
189
     *
190
     * Regression test for bug #8559
191
     *
192
     * @return void
193
     * @link   http://pear.php.net/bugs/bug.php?id=8559
194
     *         PHP_CompatInfo fails to scan if it finds empty file in path
195
     * @see    PHP_CompatInfo_TestSuite_Bugs::testBug8559()
196
     * @covers PHP_CompatInfo::parseDir
197
     * @group  parseDir
198
     */
199
    public function testBug8559()
200
    {
201
        $ds = DIRECTORY_SEPARATOR;
202
        $dn = dirname(__FILE__) . $ds . 'emptyDir';
203
 
204
        $exp = array('Usage: pci [options]',
205
                     '',
206
                     '  -d   --dir (optional)value                      Parse DIR to get its',
207
                     '                                                  compatibility info ()',
208
                     '  -f   --file (optional)value                     Parse FILE to get its',
209
                     '                                                  compatibility info ()',
210
                     '  -s   --string (optional)value                   Parse STRING to get its',
211
                     '                                                  compatibility info ()',
212
                     '  -v   --verbose (optional)value                  Set the verbose level (1)',
213
                     '  -n   --no-recurse                               Do not recursively parse files',
214
                     '                                                  when using --dir',
215
                     '  -if  --ignore-files (optional)value             Data file name which contains',
216
                     '                                                  a list of file to ignore',
217
                     '                                                  (files.txt)',
218
                     '  -id  --ignore-dirs (optional)value              Data file name which contains',
219
                     '                                                  a list of directory to ignore',
220
                     '                                                  (dirs.txt)',
221
                     '  -in  --ignore-functions (optional)value         Data file name which contains',
222
                     '                                                  a list of php function to',
223
                     '                                                  ignore (functions.txt)',
224
                     '  -ic  --ignore-constants (optional)value         Data file name which contains',
225
                     '                                                  a list of php constant to',
226
                     '                                                  ignore (constants.txt)',
227
                     '  -ie  --ignore-extensions (optional)value        Data file name which contains',
228
                     '                                                  a list of php extension to',
229
                     '                                                  ignore (extensions.txt)',
230
                     '  -iv  --ignore-versions values(optional)         PHP versions - functions to',
231
                     '                                                  exclude when parsing source',
232
                     '                                                  code (5.0.0)',
233
                     '  -inm --ignore-functions-match (optional)value   Data file name which contains',
234
                     '                                                  a list of php function pattern',
235
                     '                                                  to ignore',
236
                     '                                                  (functions-match.txt)',
237
                     '  -iem --ignore-extensions-match (optional)value  Data file name which contains',
238
                     '                                                  a list of php extension',
239
                     '                                                  pattern to ignore',
240
                     '                                                  (extensions-match.txt)',
241
                     '  -icm --ignore-constants-match (optional)value   Data file name which contains',
242
                     '                                                  a list of php constant pattern',
243
                     '                                                  to ignore',
244
                     '                                                  (constants-match.txt)',
245
                     '  -fe  --file-ext (optional)value                 A comma separated list of file',
246
                     '                                                  extensions to parse (only',
247
                     '                                                  valid if parsing a directory)',
248
                     '                                                  (php, php4, inc, phtml)',
249
                     '  -r   --report (optional)value                   Print either "xml" or "csv"',
250
                     '                                                  report (text)',
251
                     '  -o   --output-level (optional)value             Print Path/File + Version with',
252
                     '                                                  additional data (31)',
253
                     '  -t   --tab (optional)value                      Columns width (29,12,20)',
254
                     '  -p   --progress (optional)value                 Show a wait message [text] or',
255
                     '                                                  a progress bar [bar] (bar)',
256
                     '  -S   --summarize                                Print only summary when',
257
                     '                                                  parsing directory',
258
                     '  -V   --version                                  Print version information',
259
                     '  -h   --help                                     Show this help',
260
                     '',
261
                     'No valid files into directory "'. $dn .
262
                     '". Please check your spelling and try again.',
263
                     '');
264
 
265
        $args = '-d ' . $dn;
266
        $this->assertPhpExec($args, $exp);
267
    }
268
 
269
    /**
270
     * Regression test for bug #12350
271
     *
272
     * Be sure ( chdir() ) to check
273
     * if file (checkMax.php) is in current directory ( dirname(__FILE__) )
274
     *
275
     * @return void
276
     * @link   http://pear.php.net/bugs/bug.php?id=12350
277
     *         file in current directory is not found
278
     * @covers PHP_CompatInfo::parseFile
279
     * @group  parseFile
280
     * @group  cli
281
     */
282
    public function testBug12350()
283
    {
284
        $exp = array('+-----------------------------+---------+------------+--------------------+',
285
                     '| File                        | Version | Extensions | Constants/Tokens   |',
286
                     '+-----------------------------+---------+------------+--------------------+',
287
                     '| checkMax.php                | 4.0.7   |            | ...CTORY_SEPARATOR |',
288
                     '|                             |         |            | TRUE               |',
289
                     '|                             |         |            | __FILE__           |',
290
                     '+-----------------------------+---------+------------+--------------------+');
291
 
292
        chdir(dirname(__FILE__));
293
        $args = '-o 30 -f checkMax.php';
294
        $this->assertPhpExec($args, $exp);
295
    }
296
 
297
    /**
298
     * Parsing string with -s | --string parameter
299
     *
300
     * @return void
301
     * @covers PHP_CompatInfo::parseString
302
     * @group  parseString
303
     * @group  cli
304
     */
305
    public function testParseString()
306
    {
307
        $exp = array('+-----------------------------+---------+---+------------+--------------------+',
308
                     '| Source code                 | Version | C | Extensions | Constants/Tokens   |',
309
                     '+-----------------------------+---------+---+------------+--------------------+',
310
                     '| <?php ... ?>                | 5.1.1   | 0 |            | DATE_RSS           |',
311
                     '+-----------------------------+---------+---+------------+--------------------+');
312
 
313
        $str = "\"echo DATE_RSS;\"";
314
 
315
        $args = '-s ' . $str;
316
        $this->assertPhpExec($args, $exp);
317
    }
318
 
319
    /**
320
     * Regression test for request#13147
321
     *
322
     * @return void
323
     * @link   http://pear.php.net/bugs/bug.php?id=13147
324
     *         CLI: add filter file extension option on parsing directory
325
     * @covers PHP_CompatInfo::parseDir
326
     * @group  parseDir
327
     * @group  cli
328
     */
329
    public function testRequest13147()
330
    {
331
        $resources   = array('gd', 'SQLite', 'xdebug');
332
        $testSkipped = array();
333
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
334
            foreach ($testSkipped as $reason) {
335
                $this->markTestSkipped($reason);
336
            }
337
        }
338
 
339
        $ds  = DIRECTORY_SEPARATOR;
340
        $exp = array('+-----------------------------+---------+------------+--------------------+',
341
                     '| Files                       | Version | Extensions | Constants/Tokens   |',
342
                     '+-----------------------------+---------+------------+--------------------+',
343
                     '| ...patInfo'.$ds.'tests'.$ds.'parseDir'.$ds.'* | 5.2.0   | gd         | PHP_SHLIB_SUFFIX   |',
344
                     '|                             |         | SQLite     | TRUE               |',
345
                     '|                             |         | xdebug     | ..._ERR_CANT_WRITE |',
346
                     '|                             |         |            | ...D_ERR_EXTENSION |',
347
                     '|                             |         |            | ...D_ERR_FORM_SIZE |',
348
                     '|                             |         |            | ...AD_ERR_INI_SIZE |',
349
                     '|                             |         |            | UPLOAD_ERR_NO_FILE |',
350
                     '|                             |         |            | ..._ERR_NO_TMP_DIR |',
351
                     '|                             |         |            | UPLOAD_ERR_OK      |',
352
                     '|                             |         |            | UPLOAD_ERR_PARTIAL |',
353
                     '|                             |         |            | abstract           |',
354
                     '|                             |         |            | catch              |',
355
                     '|                             |         |            | clone              |',
356
                     '|                             |         |            | final              |',
357
                     '|                             |         |            | implements         |',
358
                     '|                             |         |            | instanceof         |',
359
                     '|                             |         |            | interface          |',
360
                     '|                             |         |            | private            |',
361
                     '|                             |         |            | protected          |',
362
                     '|                             |         |            | public             |',
363
                     '|                             |         |            | throw              |',
364
                     '|                             |         |            | try                |',
365
                     '+-----------------------------+---------+------------+--------------------+',
366
                     '| ...'.$ds.'parseDir'.$ds.'extensions.php | 4.3.2   | gd         | PHP_SHLIB_SUFFIX   |',
367
                     '|                             |         | SQLite     | TRUE               |',
368
                     '|                             |         | xdebug     |                    |',
369
                     '+-----------------------------+---------+------------+--------------------+',
370
                     '| ...sts'.$ds.'parseDir'.$ds.'phpinfo.php | 4.0.0   |            |                    |',
371
                     '+-----------------------------+---------+------------+--------------------+',
372
                     '| ...arseDir'.$ds.'PHP5'.$ds.'tokens.php5 | 5.0.0   |            | abstract           |',
373
                     '|                             |         |            | catch              |',
374
                     '|                             |         |            | clone              |',
375
                     '|                             |         |            | final              |',
376
                     '|                             |         |            | implements         |',
377
                     '|                             |         |            | instanceof         |',
378
                     '|                             |         |            | interface          |',
379
                     '|                             |         |            | private            |',
380
                     '|                             |         |            | protected          |',
381
                     '|                             |         |            | public             |',
382
                     '|                             |         |            | throw              |',
383
                     '|                             |         |            | try                |',
384
                     '+-----------------------------+---------+------------+--------------------+',
385
                     '| ...ir'.$ds.'PHP5'.$ds.'upload_error.php | 5.2.0   |            | ..._ERR_CANT_WRITE |',
386
                     '|                             |         |            | ...D_ERR_EXTENSION |',
387
                     '|                             |         |            | ...D_ERR_FORM_SIZE |',
388
                     '|                             |         |            | ...AD_ERR_INI_SIZE |',
389
                     '|                             |         |            | UPLOAD_ERR_NO_FILE |',
390
                     '|                             |         |            | ..._ERR_NO_TMP_DIR |',
391
                     '|                             |         |            | UPLOAD_ERR_OK      |',
392
                     '|                             |         |            | UPLOAD_ERR_PARTIAL |',
393
                     '|                             |         |            | throw              |',
394
                     '+-----------------------------+---------+------------+--------------------+');
395
 
396
        $dn = dirname(__FILE__) . $ds . 'parseDir';
397
        $fe = 'php,php5';
398
 
399
        $args = '-o 30 -fe '. $fe . ' -d '. $dn;
400
        $this->assertPhpExec($args, $exp);
401
    }
402
 
403
    /**
404
     * Regression test for request#13147
405
     * with a better reading of Extensions and Constants/Tokens columns
406
     *
407
     * @return void
408
     * @see    testRequest13147()
409
     * @link   http://pear.php.net/bugs/bug.php?id=13147
410
     *         CLI: add filter file extension option on parsing directory
411
     * @covers PHP_CompatInfo::parseDir
412
     * @group  parseDir
413
     * @group  cli
414
     */
415
    public function testReq13147ImproveRender()
416
    {
417
        $resources   = array('gd', 'SQLite', 'xdebug');
418
        $testSkipped = array();
419
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
420
            foreach ($testSkipped as $reason) {
421
                $this->markTestSkipped($reason);
422
            }
423
        }
424
 
425
        $ds  = DIRECTORY_SEPARATOR;
426
        $exp = array('+-----------------------------+---------+-------------+-----------------------+',
427
                     '| Files                       | Version | Extensions  | Constants/Tokens      |',
428
                     '+-----------------------------+---------+-------------+-----------------------+',
429
                     '| ...patInfo'.$ds.'tests'.$ds.'parseDir'.$ds.'* | 5.2.0   | gd          | PHP_SHLIB_SUFFIX      |',
430
                     '|                             |         | SQLite      | TRUE                  |',
431
                     '|                             |         | xdebug      | UPLOAD_ERR_CANT_WRITE |',
432
                     '|                             |         |             | UPLOAD_ERR_EXTENSION  |',
433
                     '|                             |         |             | UPLOAD_ERR_FORM_SIZE  |',
434
                     '|                             |         |             | UPLOAD_ERR_INI_SIZE   |',
435
                     '|                             |         |             | UPLOAD_ERR_NO_FILE    |',
436
                     '|                             |         |             | UPLOAD_ERR_NO_TMP_DIR |',
437
                     '|                             |         |             | UPLOAD_ERR_OK         |',
438
                     '|                             |         |             | UPLOAD_ERR_PARTIAL    |',
439
                     '|                             |         |             | abstract              |',
440
                     '|                             |         |             | catch                 |',
441
                     '|                             |         |             | clone                 |',
442
                     '|                             |         |             | final                 |',
443
                     '|                             |         |             | implements            |',
444
                     '|                             |         |             | instanceof            |',
445
                     '|                             |         |             | interface             |',
446
                     '|                             |         |             | private               |',
447
                     '|                             |         |             | protected             |',
448
                     '|                             |         |             | public                |',
449
                     '|                             |         |             | throw                 |',
450
                     '|                             |         |             | try                   |',
451
                     '+-----------------------------+---------+-------------+-----------------------+',
452
                     '| ...'.$ds.'parseDir'.$ds.'extensions.php | 4.3.2   | gd          | PHP_SHLIB_SUFFIX      |',
453
                     '|                             |         | SQLite      | TRUE                  |',
454
                     '|                             |         | xdebug      |                       |',
455
                     '+-----------------------------+---------+-------------+-----------------------+',
456
                     '| ...sts'.$ds.'parseDir'.$ds.'phpinfo.php | 4.0.0   |             |                       |',
457
                     '+-----------------------------+---------+-------------+-----------------------+',
458
                     '| ...arseDir'.$ds.'PHP5'.$ds.'tokens.php5 | 5.0.0   |             | abstract              |',
459
                     '|                             |         |             | catch                 |',
460
                     '|                             |         |             | clone                 |',
461
                     '|                             |         |             | final                 |',
462
                     '|                             |         |             | implements            |',
463
                     '|                             |         |             | instanceof            |',
464
                     '|                             |         |             | interface             |',
465
                     '|                             |         |             | private               |',
466
                     '|                             |         |             | protected             |',
467
                     '|                             |         |             | public                |',
468
                     '|                             |         |             | throw                 |',
469
                     '|                             |         |             | try                   |',
470
                     '+-----------------------------+---------+-------------+-----------------------+',
471
                     '| ...ir'.$ds.'PHP5'.$ds.'upload_error.php | 5.2.0   |             | UPLOAD_ERR_CANT_WRITE |',
472
                     '|                             |         |             | UPLOAD_ERR_EXTENSION  |',
473
                     '|                             |         |             | UPLOAD_ERR_FORM_SIZE  |',
474
                     '|                             |         |             | UPLOAD_ERR_INI_SIZE   |',
475
                     '|                             |         |             | UPLOAD_ERR_NO_FILE    |',
476
                     '|                             |         |             | UPLOAD_ERR_NO_TMP_DIR |',
477
                     '|                             |         |             | UPLOAD_ERR_OK         |',
478
                     '|                             |         |             | UPLOAD_ERR_PARTIAL    |',
479
                     '|                             |         |             | throw                 |',
480
                     '+-----------------------------+---------+-------------+-----------------------+');
481
 
482
        $dn = dirname(__FILE__) . $ds . 'parseDir';
483
        $fe = 'php,php5';
484
 
485
        $args = '-o 30 -t 29,13,23 -fe '. $fe . ' -d '. $dn;
486
        $this->assertPhpExec($args, $exp);
487
    }
488
}
489
 
490
// Call PHP_CompatInfo_TestSuite_Cli::main() if file is executed directly.
491
if (PHPUnit_MAIN_METHOD == "PHP_CompatInfo_TestSuite_Cli::main") {
492
    PHP_CompatInfo_TestSuite_Cli::main();
493
}
494
?>