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 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_Standard.php,v 1.54 2008/12/31 14:32:28 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_Standard::main");
17
}
18
 
19
require_once "PHPUnit/Framework/TestCase.php";
20
require_once "PHPUnit/Framework/TestSuite.php";
21
 
22
require_once 'PHP/CompatInfo.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_Standard extends PHPUnit_Framework_TestCase
36
{
37
    /**
38
     * A PCI object
39
     * @var  object
40
     */
41
    protected $pci;
42
 
43
    /**
44
     * Filename where to write results of debug pci events notification
45
     * @var   string
46
     * @since 1.8.0RC1
47
     */
48
    private $destLogFile;
49
 
50
    /**
51
     * Runs the test methods of this class.
52
     *
53
     * @return void
54
     */
55
    public static function main()
56
    {
57
        include_once "PHPUnit/TextUI/TestRunner.php";
58
 
59
        $suite = new PHPUnit_Framework_TestSuite('PHP_CompatInfo Standard Tests');
60
        PHPUnit_TextUI_TestRunner::run($suite);
61
    }
62
 
63
    /**
64
     * Sets up the fixture.
65
     * This method is called before a test is executed.
66
     *
67
     * @return void
68
     */
69
    protected function setUp()
70
    {
71
        $this->destLogFile = dirname(__FILE__) . DIRECTORY_SEPARATOR .
72
                             __CLASS__ . '.log';
73
 
74
        $this->pci = new PHP_CompatInfo('null');
75
        $this->pci->addListener(array(&$this, 'debugNotify'));
76
    }
77
 
78
    /**
79
     * Tears down the fixture.
80
     * This method is called after a test is executed.
81
     *
82
     * @return void
83
     */
84
    protected function tearDown()
85
    {
86
        unset($this->pci);
87
    }
88
 
89
    /**
90
     * PCI Events notification observer for debug purpose only
91
     *
92
     * @param object &$auditEvent Instance of Event_Notification object
93
     *
94
     * @return void
95
     */
96
    public function debugNotify(&$auditEvent)
97
    {
98
        $notifyName = $auditEvent->getNotificationName();
99
        $notifyInfo = $auditEvent->getNotificationInfo();
100
 
101
        if ($notifyName == PHP_COMPATINFO_EVENT_AUDITSTARTED) {
102
            $dbt = debug_backtrace();
103
            error_log('backtrace: '. $dbt[7]['function'] . PHP_EOL,
104
                      3, $this->destLogFile);
105
            error_log($notifyName.':'. PHP_EOL .
106
                      var_export($notifyInfo, true) . PHP_EOL,
107
                      3, $this->destLogFile);
108
 
109
        } elseif ($notifyName == PHP_COMPATINFO_EVENT_AUDITFINISHED) {
110
            error_log($notifyName.':'. PHP_EOL .
111
                      var_export($notifyInfo, true) . PHP_EOL,
112
                      3, $this->destLogFile);
113
        }
114
    }
115
 
116
    /**
117
     * Retrieve files list to be ignore by parsing process
118
     *
119
     * @param string $dir     Directory to parse
120
     * @param array  $options Parser options
121
     *
122
     * @return array
123
     * @since  version 1.8.0RC1
124
     */
125
    private function getIgnoredFileList($dir, $options)
126
    {
127
        $files = $this->pci->parser->getFileList($dir, $options);
128
 
129
        $ff               = new File_Find();
130
        $ff->dirsep       = DIRECTORY_SEPARATOR;
131
        list(, $allfiles) = $ff->maptree($dir);
132
 
133
        $ignored_files = PHP_CompatInfo_Parser::_arrayDiff($allfiles, $files);
134
        return $ignored_files;
135
    }
136
 
137
    /**
138
     * Test if a dictionary for an Extension is available or not
139
     *
140
     * @param array  $resources   List of Extension dictionaries
141
     *                            that should be present to perform a unit test
142
     * @param array &$testSkipped Reasons of tests skipped
143
     *
144
     * @return bool
145
     * @since  version 1.9.0b2
146
     */
147
    private function isResourceAvailable($resources, &$testSkipped)
148
    {
149
        $dict = array();
150
        foreach ($resources as $ext) {
151
            if (!isset($GLOBALS['_PHP_COMPATINFO_FUNC_'.strtoupper($ext)])) {
152
                $dict[] = $ext;
153
            }
154
        }
155
        if (count($dict) == 1) {
156
            $testSkipped[] = 'The '. $dict[0] .
157
                             ' function dictionary is not available.';
158
        } elseif (count($dict) > 1) {
159
            $testSkipped[] = 'The '. implode(',', $dict) .
160
                             ' function dictionaries are not available.';
161
        }
162
        return (count($testSkipped) == 0);
163
    }
164
 
165
    /**
166
     * Tests tokenizer with a single file and empty contents
167
     *
168
     * @return void
169
     * @group  standard
170
     */
171
    public function testTokenizerWithEmptyFile()
172
    {
173
        if (token_name(311) !== 'T_INLINE_HTML') {
174
            $this->markTestSkipped('Tokens values of Tokenizer have changed');
175
        }
176
 
177
        $ds = DIRECTORY_SEPARATOR;
178
        $fn = dirname(__FILE__) . $ds . 'parseFile' . $ds . 'empty.php';
179
 
180
        $r     = $this->pci->parser->_tokenize($fn, false);
181
        $empty = array(0 =>
182
                   array (
183
 
184
                   1 => "\n",
185
                   2 => 1));
186
        $this->assertSame($empty, $r);
187
 
188
        $r     = $this->pci->parser->_tokenize($fn, false, true);
189
        $empty = array(0 =>
190
                   array (
191
 
192
                   1 => "\n",
193
                   2 => 1,
194
                   3 => 'T_INLINE_HTML'));
195
        $this->assertSame($empty, $r);
196
    }
197
 
198
    /**
199
     * Tests parsing a single file that does not exists
200
     *
201
     * @return void
202
     * @covers PHP_CompatInfo::parseFile
203
     * @group  parseFile
204
     * @group  standard
205
     */
206
    public function testParseInvalidFile()
207
    {
208
        $ds = DIRECTORY_SEPARATOR;
209
        $fn = dirname(__FILE__) . $ds . 'parseFile' . $ds . 'nothere.php';
210
 
211
        $r = $this->pci->parseFile($fn);
212
        $this->assertFalse($r);
213
    }
214
 
215
    /**
216
     * Tests parsing a single file with empty contents
217
     *
218
     * @return void
219
     * @covers PHP_CompatInfo::parseFile
220
     * @group  parseFile
221
     * @group  standard
222
     */
223
    public function testParseEmptyFile()
224
    {
225
        $ds = DIRECTORY_SEPARATOR;
226
        $fn = dirname(__FILE__) . $ds . 'parseFile' . $ds . 'empty.php';
227
 
228
        $r   = $this->pci->parseFile($fn);
229
        $exp = array('ignored_files' => array(),
230
                     'ignored_functions' => array(),
231
                     'ignored_extensions' => array(),
232
                     'ignored_constants' => array(),
233
                     'max_version' => '',
234
                     'version' => '4.0.0',
235
                     'classes' => array(),
236
                     'functions' => array(),
237
                     'extensions' => array(),
238
                     'constants' => array(),
239
                     'tokens' => array(),
240
                     'cond_code' => array(0));
241
        $this->assertSame($exp, $r);
242
    }
243
 
244
    /**
245
     * Tests parsing a single file
246
     *
247
     * @return void
248
     * @covers PHP_CompatInfo::parseFile
249
     * @group  parseFile
250
     * @group  standard
251
     */
252
    public function testParseNotEmptyFile()
253
    {
254
        $resources   = array('bcmath', 'pcre');
255
        $testSkipped = array();
256
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
257
            foreach ($testSkipped as $reason) {
258
                $this->markTestSkipped($reason);
259
            }
260
        }
261
 
262
        $ds = DIRECTORY_SEPARATOR;
263
        $fn = dirname(__FILE__) . $ds . 'parseFile' . $ds . 'math.php';
264
 
265
        $r = $this->pci->parseFile($fn);
266
        $this->assertType('array', $r);
267
 
268
        $exp = array('ignored_files' => array(),
269
                     'ignored_functions' => array(),
270
                     'ignored_extensions' => array(),
271
                     'ignored_constants' => array(),
272
                     'max_version' => '',
273
                     'version' => '4.0.0',
274
                     'classes' => array(),
275
                     'functions' => array('bcsub', 'preg_match'),
276
                     'extensions' => array('bcmath', 'pcre'),
277
                     'constants' => array(),
278
                     'tokens' => array(),
279
                     'cond_code' => array(0));
280
        $this->assertSame($exp, $r);
281
    }
282
 
283
    /**
284
     * Tests parsing a single file with 'ignore_functions' option
285
     *
286
     * @return void
287
     * @covers PHP_CompatInfo::parseFile
288
     * @group  parseFile
289
     * @group  standard
290
     */
291
    public function testParseFileWithIgnoreFunctions()
292
    {
293
        $resources   = array('date');
294
        $testSkipped = array();
295
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
296
            foreach ($testSkipped as $reason) {
297
                $this->markTestSkipped($reason);
298
            }
299
        }
300
 
301
        $ds  = DIRECTORY_SEPARATOR;
302
        $fn  = dirname(__FILE__) . $ds . 'parseFile' . $ds . 'conditional.php';
303
        $opt = array('ignore_functions' => array('simplexml_load_file'));
304
 
305
        $r = $this->pci->parseFile($fn, $opt);
306
        $this->assertType('array', $r);
307
 
308
        $exp = array('ignored_files' => array(),
309
                     'ignored_functions' => array('simplexml_load_file'),
310
                     'ignored_extensions' => array(),
311
                     'ignored_constants' => array(),
312
                     'max_version' => '',
313
                     'version' => '5.1.1',
314
                     'classes' => array(),
315
                     'functions' => array('basename',
316
                                          'date',
317
                                          'debug_backtrace',
318
                                          'define',
319
                                          'defined',
320
                                          'dirname',
321
                                          'function_exists',
322
                                          'phpversion',
323
                                          'simplexml_load_file',
324
                                          'strtoupper',
325
                                          'substr',
326
                                          'version_compare'),
327
                     'extensions' => array('date'),
328
                     'constants' => array('DATE_W3C',
329
                                          'DIRECTORY_SEPARATOR',
330
                                          'FALSE',
331
                                          'PHP_EOL',
332
                                          'PHP_OS',
333
                                          '__FILE__'),
334
                     'tokens' => array(),
335
                     'cond_code' => array(5));
336
        $this->assertSame($exp, $r);
337
    }
338
 
339
    /**
340
     * Tests parsing a single file with 'ignore_constants' option
341
     *
342
     * @return void
343
     * @covers PHP_CompatInfo::parseFile
344
     * @group  parseFile
345
     * @group  standard
346
     */
347
    public function testParseFileWithIgnoreConstants()
348
    {
349
        $resources   = array('date', 'SimpleXML');
350
        $testSkipped = array();
351
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
352
            foreach ($testSkipped as $reason) {
353
                $this->markTestSkipped($reason);
354
            }
355
        }
356
 
357
        $ds  = DIRECTORY_SEPARATOR;
358
        $fn  = dirname(__FILE__) . $ds . 'parseFile' . $ds . 'conditional.php';
359
        $opt = array('ignore_constants' => array('PHP_EOL'));
360
 
361
        $r = $this->pci->parseFile($fn, $opt);
362
        $this->assertType('array', $r);
363
 
364
        $exp = array('ignored_files' => array(),
365
                     'ignored_functions' => array(),
366
                     'ignored_extensions' => array(),
367
                     'ignored_constants' => array('PHP_EOL'),
368
                     'max_version' => '',
369
                     'version' => '5.1.1',
370
                     'classes' => array(),
371
                     'functions' => array('basename',
372
                                          'date',
373
                                          'debug_backtrace',
374
                                          'define',
375
                                          'defined',
376
                                          'dirname',
377
                                          'function_exists',
378
                                          'phpversion',
379
                                          'simplexml_load_file',
380
                                          'strtoupper',
381
                                          'substr',
382
                                          'version_compare'),
383
                     'extensions' => array('date', 'SimpleXML'),
384
                     'constants' => array('DATE_W3C',
385
                                          'DIRECTORY_SEPARATOR',
386
                                          'FALSE',
387
                                          'PHP_EOL',
388
                                          'PHP_OS',
389
                                          '__FILE__'),
390
                     'tokens' => array(),
391
                     'cond_code' => array(5));
392
        $this->assertSame($exp, $r);
393
    }
394
 
395
    /**
396
     * Tests parsing a single file with 'ignore_extensions' option
397
     *
398
     * @return void
399
     * @link   http://www.php.net/zip
400
     * @covers PHP_CompatInfo::parseFile
401
     * @group  parseFile
402
     * @group  standard
403
     */
404
    public function testParseFileWithIgnoreExtensions()
405
    {
406
        $resources   = array('zip');
407
        $testSkipped = array();
408
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
409
            foreach ($testSkipped as $reason) {
410
                $this->markTestSkipped($reason);
411
            }
412
        }
413
 
414
        $ds  = DIRECTORY_SEPARATOR;
415
        $fn  = dirname(__FILE__) . $ds . 'parseFile' . $ds . 'zip.php';
416
        $opt = array('ignore_extensions' => array('zip'));
417
 
418
        $r = $this->pci->parseFile($fn, $opt);
419
        $this->assertType('array', $r);
420
 
421
        $exp = array('ignored_files' => array(),
422
                     'ignored_functions' => array('zip_close',
423
                                                  'zip_entry_compressedsize',
424
                                                  'zip_entry_compressionmethod',
425
                                                  'zip_entry_filesize',
426
                                                  'zip_entry_name',
427
                                                  'zip_open',
428
                                                  'zip_read'),
429
                     'ignored_extensions' => array('zip'),
430
                     'ignored_constants' => array(),
431
                     'max_version' => '',
432
                     'version' => '4.0.0',
433
                     'classes' => array(),
434
                     'functions' => array('zip_close',
435
                                          'zip_entry_compressedsize',
436
                                          'zip_entry_compressionmethod',
437
                                          'zip_entry_filesize',
438
                                          'zip_entry_name',
439
                                          'zip_open',
440
                                          'zip_read'),
441
                     'extensions' => array('zip'),
442
                     'constants' => array(),
443
                     'tokens' => array(),
444
                     'cond_code' => array(0));
445
        $this->assertSame($exp, $r);
446
    }
447
 
448
    /**
449
     * Tests parsing a single file with 'ignore_versions' option
450
     * Ignored all PHP functions between 4.3.10 and 4.4.8
451
     *
452
     * @return void
453
     * @covers PHP_CompatInfo::parseFile
454
     * @group  parseFile
455
     * @group  standard
456
     */
457
    public function testParseFileWithIgnoreVersions()
458
    {
459
        $resources   = array('date', 'SimpleXML');
460
        $testSkipped = array();
461
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
462
            foreach ($testSkipped as $reason) {
463
                $this->markTestSkipped($reason);
464
            }
465
        }
466
 
467
        $ds  = DIRECTORY_SEPARATOR;
468
        $fn  = dirname(__FILE__) . $ds . 'parseFile' . $ds . 'conditional.php';
469
        $opt = array('ignore_versions' => array('4.3.10', '4.4.8'));
470
 
471
        $r = $this->pci->parseFile($fn, $opt);
472
        $this->assertType('array', $r);
473
 
474
        $exp = array('ignored_files' => array(),
475
                     'ignored_functions' => array(),
476
                     'ignored_extensions' => array(),
477
                     'ignored_constants' => array(),
478
                     'max_version' => '',
479
                     'version' => '5.1.1',
480
                     'classes' => array(),
481
                     'functions' => array('basename',
482
                                          'date',
483
                                          'debug_backtrace',
484
                                          'define',
485
                                          'defined',
486
                                          'dirname',
487
                                          'function_exists',
488
                                          'phpversion',
489
                                          'simplexml_load_file',
490
                                          'strtoupper',
491
                                          'substr',
492
                                          'version_compare'),
493
                     'extensions' => array('date', 'SimpleXML'),
494
                     'constants' => array('DATE_W3C',
495
                                          'DIRECTORY_SEPARATOR',
496
                                          'FALSE',
497
                                          'PHP_OS',
498
                                          '__FILE__'),
499
                     'tokens' => array(),
500
                     'cond_code' => array(5));
501
        $this->assertSame($exp, $r);
502
    }
503
 
504
    /**
505
     * Tests parsing an invalid input
506
     *
507
     * @return void
508
     * @covers PHP_CompatInfo::parseString
509
     * @group  parseString
510
     * @group  standard
511
     */
512
    public function testParseInvalidString()
513
    {
514
        $in = array();
515
        $r  = $this->pci->parseString($in);
516
        $this->assertFalse($r);
517
    }
518
 
519
    /**
520
     * Tests parsing a string
521
     *
522
     * @return void
523
     * @covers PHP_CompatInfo::parseString
524
     * @group  parseString
525
     * @group  standard
526
     */
527
    public function testParseNotEmptyString()
528
    {
529
        $ds  = DIRECTORY_SEPARATOR;
530
        $fn  = dirname(__FILE__) . $ds . 'sample_req6056.php';
531
        $str = file_get_contents($fn);
532
 
533
        $r = $this->pci->parseString($str);
534
        $this->assertType('array', $r);
535
 
536
        $exp = array('ignored_files' => array(),
537
                     'ignored_functions' => array(),
538
                     'ignored_extensions' => array(),
539
                     'ignored_constants' => array(),
540
                     'max_version' => '5.0.4',
541
                     'version' => '5.1.0',
542
                     'classes' => array(),
543
                     'functions' => array('array_diff_key',
544
                                          'php_check_syntax'),
545
                     'extensions' => array(),
546
                     'constants' => array(),
547
                     'tokens' => array(),
548
                     'cond_code' => array(0));
549
        $this->assertSame($exp, $r);
550
    }
551
 
552
    /**
553
     * Tests parsing string DATE constants
554
     *
555
     * @return void
556
     * @link   http://php.net/manual/en/ref.datetime.php Predefined Date Constants
557
     * @covers PHP_CompatInfo::parseString
558
     * @group  parseString
559
     * @group  standard
560
     */
561
    public function testParseDate511String()
562
    {
563
        $str = '<?php
564
$nl = "\n";
565
echo "$nl Atom    = " . DATE_ATOM;
566
echo "$nl Cookie  = " . DATE_COOKIE;
567
echo "$nl Iso8601 = " . DATE_ISO8601;
568
echo "$nl Rfc822  = " . DATE_RFC822;
569
echo "$nl Rfc850  = " . DATE_RFC850;
570
echo "$nl Rfc1036 = " . DATE_RFC1036;
571
echo "$nl Rfc1123 = " . DATE_RFC1123;
572
echo "$nl Rfc2822 = " . DATE_RFC2822;
573
echo "$nl RSS     = " . DATE_RSS;
574
echo "$nl W3C     = " . DATE_W3C;
575
?>';
576
 
577
        $r = $this->pci->parseString($str);
578
        $this->assertType('array', $r);
579
 
580
        $exp = array('ignored_files' => array(),
581
                     'ignored_functions' => array(),
582
                     'ignored_extensions' => array(),
583
                     'ignored_constants' => array(),
584
                     'max_version' => '',
585
                     'version' => '5.1.1',
586
                     'classes' => array(),
587
                     'functions' => array(),
588
                     'extensions' => array(),
589
                     'constants' => array('DATE_ATOM', 'DATE_COOKIE',
590
                                          'DATE_ISO8601',
591
                                          'DATE_RFC1036', 'DATE_RFC1123',
592
                                          'DATE_RFC2822',
593
                                          'DATE_RFC822', 'DATE_RFC850',
594
                                          'DATE_RSS', 'DATE_W3C'),
595
                     'tokens' => array(),
596
                     'cond_code' => array(0));
597
        $this->assertSame($exp, $r);
598
    }
599
 
600
    /**
601
     * Tests parsing string DATE constants
602
     *
603
     * @return void
604
     * @link   http://php.net/manual/en/ref.datetime.php Predefined Date Constants
605
     * @covers PHP_CompatInfo::parseString
606
     * @group  parseString
607
     * @group  standard
608
     */
609
    public function testParseDate513String()
610
    {
611
        $str = '<?php
612
$nl = "\n";
613
echo "$nl Rfc3339 = " . DATE_RFC3339;
614
echo "$nl RSS     = " . DATE_RSS;
615
?>';
616
 
617
        $r = $this->pci->parseString($str);
618
        $this->assertType('array', $r);
619
 
620
        $exp = array('ignored_files' => array(),
621
                     'ignored_functions' => array(),
622
                     'ignored_extensions' => array(),
623
                     'ignored_constants' => array(),
624
                     'max_version' => '',
625
                     'version' => '5.1.3',
626
                     'classes' => array(),
627
                     'functions' => array(),
628
                     'extensions' => array(),
629
                     'constants' => array('DATE_RFC3339', 'DATE_RSS'),
630
                     'tokens' => array(),
631
                     'cond_code' => array(0));
632
        $this->assertSame($exp, $r);
633
    }
634
 
635
    /**
636
     * Tests parsing string UPLOAD_ERR constants
637
     *
638
     * @return void
639
     * @link   http://www.php.net/features.file-upload.errors
640
     *         File Upload Error specific Constants
641
     * @covers PHP_CompatInfo::parseString
642
     * @group  parseString
643
     * @group  standard
644
     */
645
    public function testParseUploadErrString()
646
    {
647
        $str = '<?php
648
$uploadErrors = array(
649
    UPLOAD_ERR_INI_SIZE   => "The uploaded file exceeds the upload_max_filesize directive in php.ini.",
650
    UPLOAD_ERR_FORM_SIZE  => "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.",
651
    UPLOAD_ERR_PARTIAL    => "The uploaded file was only partially uploaded.",
652
    UPLOAD_ERR_NO_FILE    => "No file was uploaded.",
653
    UPLOAD_ERR_NO_TMP_DIR => "Missing a temporary folder.",
654
    UPLOAD_ERR_CANT_WRITE => "Failed to write file to disk.",
655
    UPLOAD_ERR_EXTENSION  => "File upload stopped by extension.",
656
);
657
 
658
$errorCode = $_FILES["myUpload"]["error"];
659
 
660
if ($errorCode !== UPLOAD_ERR_OK) {
661
    if (isset($uploadErrors[$errorCode])) {
662
        throw new Exception($uploadErrors[$errorCode]);
663
    } else {
664
        throw new Exception("Unknown error uploading file.");
665
    }
666
}
667
?>';
668
        $r   = $this->pci->parseString($str);
669
        $exp = array('ignored_files' => array(),
670
                     'ignored_functions' => array(),
671
                     'ignored_extensions' => array(),
672
                     'ignored_constants' => array(),
673
                     'max_version' => '',
674
                     'version' => '5.2.0',
675
                     'classes' => array('Exception'),
676
                     'functions' => array(),
677
                     'extensions' => array(),
678
                     'constants' => array('UPLOAD_ERR_CANT_WRITE',
679
                                          'UPLOAD_ERR_EXTENSION',
680
                                          'UPLOAD_ERR_FORM_SIZE',
681
                                          'UPLOAD_ERR_INI_SIZE',
682
                                          'UPLOAD_ERR_NO_FILE',
683
                                          'UPLOAD_ERR_NO_TMP_DIR',
684
                                          'UPLOAD_ERR_OK',
685
                                          'UPLOAD_ERR_PARTIAL'),
686
                     'tokens' => array('throw'),
687
                     'cond_code' => array(0));
688
        $this->assertSame($exp, $r);
689
    }
690
 
691
    /**
692
     * Tests parsing a directory that does not exists
693
     *
694
     * @return void
695
     * @covers PHP_CompatInfo::parseFolder
696
     * @group  parseDir
697
     * @group  standard
698
     */
699
    public function testParseInvalidDirectory()
700
    {
701
        $ds  = DIRECTORY_SEPARATOR;
702
        $dir = dirname(__FILE__) . $ds . 'parseDir' . $ds . 'nothere';
703
 
704
        $r = $this->pci->parseFolder($dir);
705
        $this->assertFalse($r);
706
    }
707
 
708
    /**
709
     * Tests parsing a directory without recursive 'recurse_dir' option
710
     *
711
     * @return void
712
     * @covers PHP_CompatInfo::parseDir
713
     * @group  parseDir
714
     * @group  standard
715
     */
716
    public function testParseNoRecursiveDirectory()
717
    {
718
        $resources   = array('gd', 'SQLite', 'xdebug');
719
        $testSkipped = array();
720
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
721
            foreach ($testSkipped as $reason) {
722
                $this->markTestSkipped($reason);
723
            }
724
        }
725
 
726
        $ds  = DIRECTORY_SEPARATOR;
727
        $dir = dirname(__FILE__) . $ds . 'parseDir';
728
        $opt = array('recurse_dir' => false);
729
 
730
        $r   = $this->pci->parseDir($dir, $opt);
731
        $exp = array('ignored_files' => array(),
732
                     'ignored_functions' => array(),
733
                     'ignored_extensions' => array(),
734
                     'ignored_constants' => array(),
735
                     'max_version' => '',
736
                     'version' => '4.3.2',
737
                     'classes' => array(),
738
                     'functions' => array('apache_get_modules',
739
                                          'dl',
740
                                          'extension_loaded',
741
                                          'imageantialias',
742
                                          'imagecreate',
743
                                          'phpinfo',
744
                                          'print_r',
745
                                          'sqlite_libversion',
746
                                          'xdebug_start_trace',
747
                                          'xdebug_stop_trace'),
748
                     'extensions' => array('gd',
749
                                           'SQLite',
750
                                           'xdebug'),
751
                     'constants' => array('PHP_SHLIB_SUFFIX',
752
                                          'TRUE'),
753
                     'tokens' => array(),
754
                     'cond_code' => array(2),
755
                     $dir . $ds . 'extensions.php' =>
756
                         array('ignored_functions' => array(),
757
                               'ignored_extensions' => array(),
758
                               'ignored_constants' => array(),
759
                               'max_version' => '',
760
                               'version' => '4.3.2',
761
                               'classes' => array(),
762
                               'functions' => array('apache_get_modules',
763
                                                    'dl',
764
                                                    'extension_loaded',
765
                                                    'imageantialias',
766
                                                    'imagecreate',
767
                                                    'print_r',
768
                                                    'sqlite_libversion',
769
                                                    'xdebug_start_trace',
770
                                                    'xdebug_stop_trace'),
771
                               'extensions' => array('gd',
772
                                                     'SQLite',
773
                                                     'xdebug'),
774
                               'constants' => array('PHP_SHLIB_SUFFIX',
775
                                                    'TRUE'),
776
                               'tokens' => array(),
777
                               'cond_code' => array(2)),
778
                     $dir . $ds . 'phpinfo.php' =>
779
                         array('ignored_functions' => array(),
780
                               'ignored_extensions' => array(),
781
                               'ignored_constants' => array(),
782
                               'max_version' => '',
783
                               'version' => '4.0.0',
784
                               'classes' => array(),
785
                               'functions' => array('phpinfo'),
786
                               'extensions' => array(),
787
                               'constants' => array(),
788
                               'tokens' => array(),
789
                               'cond_code' => array(0)));
790
        $this->assertSame($exp, $r);
791
    }
792
 
793
    /**
794
     * Tests parsing a directory with 'recurse_dir' option active
795
     * and filter files by extension with 'file_ext' option
796
     *
797
     * @return void
798
     * @covers PHP_CompatInfo::parseDir
799
     * @group  parseDir
800
     * @group  standard
801
     */
802
    public function testParseRecursiveDirectory()
803
    {
804
        $resources   = array('gd', 'SQLite', 'xdebug');
805
        $testSkipped = array();
806
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
807
            foreach ($testSkipped as $reason) {
808
                $this->markTestSkipped($reason);
809
            }
810
        }
811
 
812
        $ds  = DIRECTORY_SEPARATOR;
813
        $dir = dirname(__FILE__) . $ds . 'parseDir' . $ds;
814
        $opt = array('recurse_dir' => true,
815
                     'file_ext' => array('php', 'php5'));
816
 
817
        $r   = $this->pci->parseDir($dir, $opt);
818
        $exp = array('ignored_files' => $this->getIgnoredFileList($dir, $opt),
819
                     'ignored_functions' => array(),
820
                     'ignored_extensions' => array(),
821
                     'ignored_constants' => array(),
822
                     'max_version' => '',
823
                     'version' => '5.2.0',
824
                     'classes' => array('Exception'),
825
                     'functions' => array('apache_get_modules',
826
                                          'dl',
827
                                          'extension_loaded',
828
                                          'imageantialias',
829
                                          'imagecreate',
830
                                          'phpinfo',
831
                                          'print_r',
832
                                          'sqlite_libversion',
833
                                          'str_replace',
834
                                          'xdebug_start_trace',
835
                                          'xdebug_stop_trace'),
836
                     'extensions' => array('gd',
837
                                           'SQLite',
838
                                           'xdebug'),
839
                     'constants' => array('PHP_SHLIB_SUFFIX',
840
                                          'TRUE',
841
                                          'UPLOAD_ERR_CANT_WRITE',
842
                                          'UPLOAD_ERR_EXTENSION',
843
                                          'UPLOAD_ERR_FORM_SIZE',
844
                                          'UPLOAD_ERR_INI_SIZE',
845
                                          'UPLOAD_ERR_NO_FILE',
846
                                          'UPLOAD_ERR_NO_TMP_DIR',
847
                                          'UPLOAD_ERR_OK',
848
                                          'UPLOAD_ERR_PARTIAL'),
849
                     'tokens' => array('abstract',
850
                                       'catch',
851
                                       'clone',
852
                                       'final',
853
                                       'implements',
854
                                       'instanceof',
855
                                       'interface',
856
                                       'private',
857
                                       'protected',
858
                                       'public',
859
                                       'throw',
860
                                       'try'),
861
                     'cond_code' => array(2),
862
                     $dir . 'extensions.php' =>
863
                         array('ignored_functions' => array(),
864
                               'ignored_extensions' => array(),
865
                               'ignored_constants' => array(),
866
                               'max_version' => '',
867
                               'version' => '4.3.2',
868
                               'classes' => array(),
869
                               'functions' => array('apache_get_modules',
870
                                                    'dl',
871
                                                    'extension_loaded',
872
                                                    'imageantialias',
873
                                                    'imagecreate',
874
                                                    'print_r',
875
                                                    'sqlite_libversion',
876
                                                    'xdebug_start_trace',
877
                                                    'xdebug_stop_trace'),
878
                               'extensions' => array('gd',
879
                                                     'SQLite',
880
                                                     'xdebug'),
881
                               'constants' => array('PHP_SHLIB_SUFFIX',
882
                                                    'TRUE'),
883
                               'tokens' => array(),
884
                               'cond_code' => array(2)),
885
                     $dir . 'phpinfo.php' =>
886
                         array('ignored_functions' => array(),
887
                               'ignored_extensions' => array(),
888
                               'ignored_constants' => array(),
889
                               'max_version' => '',
890
                               'version' => '4.0.0',
891
                               'classes' => array(),
892
                               'functions' => array('phpinfo'),
893
                               'extensions' => array(),
894
                               'constants' => array(),
895
                               'tokens' => array(),
896
                               'cond_code' => array(0)),
897
                     $dir . 'PHP5' . $ds . 'tokens.php5' =>
898
                         array('ignored_functions' => array(),
899
                               'ignored_extensions' => array(),
900
                               'ignored_constants' => array(),
901
                               'max_version' => '',
902
                               'version' => '5.0.0',
903
                               'classes' => array('Exception'),
904
                               'functions' => array('str_replace'),
905
                               'extensions' => array(),
906
                               'constants' => array(),
907
                               'tokens' => array('abstract',
908
                                                 'catch',
909
                                                 'clone',
910
                                                 'final',
911
                                                 'implements',
912
                                                 'instanceof',
913
                                                 'interface',
914
                                                 'private',
915
                                                 'protected',
916
                                                 'public',
917
                                                 'throw',
918
                                                 'try'),
919
                               'cond_code' => array(0)),
920
                     $dir . 'PHP5' . $ds . 'upload_error.php' =>
921
                         array('ignored_functions' => array(),
922
                               'ignored_extensions' => array(),
923
                               'ignored_constants' => array(),
924
                               'max_version' => '',
925
                               'version' => '5.2.0',
926
                               'classes' => array('Exception'),
927
                               'functions' => array(),
928
                               'extensions' => array(),
929
                               'constants' => array('UPLOAD_ERR_CANT_WRITE',
930
                                                    'UPLOAD_ERR_EXTENSION',
931
                                                    'UPLOAD_ERR_FORM_SIZE',
932
                                                    'UPLOAD_ERR_INI_SIZE',
933
                                                    'UPLOAD_ERR_NO_FILE',
934
                                                    'UPLOAD_ERR_NO_TMP_DIR',
935
                                                    'UPLOAD_ERR_OK',
936
                                                    'UPLOAD_ERR_PARTIAL'),
937
                               'tokens' => array('throw'),
938
                               'cond_code' => array(0)));
939
        $this->assertSame($exp, $r);
940
    }
941
 
942
    /**
943
     * Tests parsing a directory with 'recurse_dir' option active
944
     * with 'ignore_files' options
945
     *
946
     * @return void
947
     * @covers PHP_CompatInfo::parseDir
948
     * @group  parseDir
949
     * @group  standard
950
     */
951
    public function testParseRecursiveDirectoryWithIgnoreFiles()
952
    {
953
        $resources   = array('gd', 'SQLite', 'xdebug');
954
        $testSkipped = array();
955
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
956
            foreach ($testSkipped as $reason) {
957
                $this->markTestSkipped($reason);
958
            }
959
        }
960
 
961
        $ds  = DIRECTORY_SEPARATOR;
962
        $dir = dirname(__FILE__) . $ds . 'parseDir' . $ds;
963
        $opt = array('recurse_dir' => true,
964
                     'ignore_files' => array($dir . 'phpinfo.php'),
965
                     'file_ext' => array('php'));
966
 
967
        $r   = $this->pci->parseDir($dir, $opt);
968
        $exp = array('ignored_files' => $this->getIgnoredFileList($dir, $opt),
969
                     'ignored_functions' => array(),
970
                     'ignored_extensions' => array(),
971
                     'ignored_constants' => array(),
972
                     'max_version' => '',
973
                     'version' => '5.2.0',
974
                     'classes' => array('Exception'),
975
                     'functions' => array('apache_get_modules',
976
                                          'dl',
977
                                          'extension_loaded',
978
                                          'imageantialias',
979
                                          'imagecreate',
980
                                          'print_r',
981
                                          'sqlite_libversion',
982
                                          'xdebug_start_trace',
983
                                          'xdebug_stop_trace'),
984
                     'extensions' => array('gd',
985
                                           'SQLite',
986
                                           'xdebug'),
987
                     'constants' => array('PHP_SHLIB_SUFFIX',
988
                                          'TRUE',
989
                                          'UPLOAD_ERR_CANT_WRITE',
990
                                          'UPLOAD_ERR_EXTENSION',
991
                                          'UPLOAD_ERR_FORM_SIZE',
992
                                          'UPLOAD_ERR_INI_SIZE',
993
                                          'UPLOAD_ERR_NO_FILE',
994
                                          'UPLOAD_ERR_NO_TMP_DIR',
995
                                          'UPLOAD_ERR_OK',
996
                                          'UPLOAD_ERR_PARTIAL'),
997
                     'tokens' => array('throw'),
998
                     'cond_code' => array(2),
999
                     $dir . 'extensions.php' =>
1000
                         array('ignored_functions' => array(),
1001
                               'ignored_extensions' => array(),
1002
                               'ignored_constants' => array(),
1003
                               'max_version' => '',
1004
                               'version' => '4.3.2',
1005
                               'classes' => array(),
1006
                               'functions' => array('apache_get_modules',
1007
                                                    'dl',
1008
                                                    'extension_loaded',
1009
                                                    'imageantialias',
1010
                                                    'imagecreate',
1011
                                                    'print_r',
1012
                                                    'sqlite_libversion',
1013
                                                    'xdebug_start_trace',
1014
                                                    'xdebug_stop_trace'),
1015
                               'extensions' => array('gd',
1016
                                                     'SQLite',
1017
                                                     'xdebug'),
1018
                               'constants' => array('PHP_SHLIB_SUFFIX',
1019
                                                    'TRUE'),
1020
                               'tokens' => array(),
1021
                               'cond_code' => array(2)),
1022
                     $dir . 'PHP5' . $ds . 'upload_error.php' =>
1023
                         array('ignored_functions' => array(),
1024
                               'ignored_extensions' => array(),
1025
                               'ignored_constants' => array(),
1026
                               'max_version' => '',
1027
                               'version' => '5.2.0',
1028
                               'classes' => array('Exception'),
1029
                               'functions' => array(),
1030
                               'extensions' => array(),
1031
                               'constants' => array('UPLOAD_ERR_CANT_WRITE',
1032
                                                    'UPLOAD_ERR_EXTENSION',
1033
                                                    'UPLOAD_ERR_FORM_SIZE',
1034
                                                    'UPLOAD_ERR_INI_SIZE',
1035
                                                    'UPLOAD_ERR_NO_FILE',
1036
                                                    'UPLOAD_ERR_NO_TMP_DIR',
1037
                                                    'UPLOAD_ERR_OK',
1038
                                                    'UPLOAD_ERR_PARTIAL'),
1039
                               'tokens' => array('throw'),
1040
                               'cond_code' => array(0)));
1041
        $this->assertSame($exp, $r);
1042
    }
1043
 
1044
    /**
1045
     * Tests parsing multiple file data sources reference
1046
     *
1047
     * @return void
1048
     * @covers PHP_CompatInfo::parseArray
1049
     * @group  parseArray
1050
     * @group  standard
1051
     */
1052
    public function testParseArrayFile()
1053
    {
1054
        $resources   = array('pcre');
1055
        $testSkipped = array();
1056
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
1057
            foreach ($testSkipped as $reason) {
1058
                $this->markTestSkipped($reason);
1059
            }
1060
        }
1061
 
1062
        $ds  = DIRECTORY_SEPARATOR;
1063
        $dir = dirname(__FILE__) . $ds . 'parseFile';
1064
        $src = array($dir . $ds . 'File_Find-1.3.0__Find.php');
1065
 
1066
        $r   = $this->pci->parseArray($src);
1067
        $exp = array('ignored_files' => array(),
1068
                     'ignored_functions' => array(),
1069
                     'ignored_extensions' => array(),
1070
                     'ignored_constants' => array(),
1071
                     'max_version' => '',
1072
                     'version' => '4.3.0',
1073
                     'classes' => array('File_Find'),
1074
                     'functions' => array('_file_find_match_shell_get_pattern',
1075
                                          'addcslashes',
1076
                                          'array_merge',
1077
                                          'array_pop',
1078
                                          'array_push',
1079
                                          'basename',
1080
                                          'closedir',
1081
                                          'count',
1082
                                          'define',
1083
                                          'defined',
1084
                                          'each',
1085
                                          'explode',
1086
                                          'glob',
1087
                                          'implode',
1088
                                          'is_a',
1089
                                          'is_array',
1090
                                          'is_dir',
1091
                                          'is_readable',
1092
                                          'maptree',
1093
                                          'maptreemultiple',
1094
                                          'opendir',
1095
                                          'preg_match',
1096
                                          'preg_replace',
1097
                                          'preg_split',
1098
                                          'print_r',
1099
                                          'readdir',
1100
                                          'reset',
1101
                                          'search',
1102
                                          'sizeof',
1103
                                          'str_replace',
1104
                                          'strcasecmp',
1105
                                          'strlen',
1106
                                          'strpos',
1107
                                          'substr',
1108
                                          'substr_count'),
1109
                     'extensions' => array('pcre'),
1110
                     'constants' => array('FALSE',
1111
                                          'NULL',
1112
                                          'PREG_SPLIT_DELIM_CAPTURE',
1113
                                          'PREG_SPLIT_NO_EMPTY',
1114
                                          'TRUE'),
1115
                     'tokens' => array(),
1116
                     'cond_code' => array(4));
1117
        $this->assertSame($exp, $r);
1118
    }
1119
 
1120
    /**
1121
     * Tests parsing multiple file data sources reference
1122
     * with option 'ignore_files'
1123
     *
1124
     * @return void
1125
     * @covers PHP_CompatInfo::parseArray
1126
     * @group  parseArray
1127
     * @group  standard
1128
     */
1129
    public function testParseArrayFileWithIgnoreFiles()
1130
    {
1131
        $resources   = array('pcre');
1132
        $testSkipped = array();
1133
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
1134
            foreach ($testSkipped as $reason) {
1135
                $this->markTestSkipped($reason);
1136
            }
1137
        }
1138
 
1139
        $ds   = DIRECTORY_SEPARATOR;
1140
        $inc  = get_included_files();
1141
        $dir  = dirname(__FILE__) . $ds . 'parseFile';
1142
        $src  = array($dir . $ds . 'File_Find-1.3.0__Find.php');
1143
        $excl = array();
1144
 
1145
        foreach ($inc as $file) {
1146
            if (basename($file) == 'PEAR.php') {
1147
                $excl[] = $file;
1148
                $src[]  = $file;
1149
            }
1150
        }
1151
        $opt = array('ignore_files' => $excl);
1152
 
1153
        $r   = $this->pci->parseArray($src, $opt);
1154
        $exp = array('ignored_files' => $excl,
1155
                     'ignored_functions' => array(),
1156
                     'ignored_extensions' => array(),
1157
                     'ignored_constants' => array(),
1158
                     'max_version' => '',
1159
                     'version' => '4.3.0',
1160
                     'classes' => array('File_Find'),
1161
                     'functions' => array('_file_find_match_shell_get_pattern',
1162
                                          'addcslashes',
1163
                                          'array_merge',
1164
                                          'array_pop',
1165
                                          'array_push',
1166
                                          'basename',
1167
                                          'closedir',
1168
                                          'count',
1169
                                          'define',
1170
                                          'defined',
1171
                                          'each',
1172
                                          'explode',
1173
                                          'glob',
1174
                                          'implode',
1175
                                          'is_a',
1176
                                          'is_array',
1177
                                          'is_dir',
1178
                                          'is_readable',
1179
                                          'maptree',
1180
                                          'maptreemultiple',
1181
                                          'opendir',
1182
                                          'preg_match',
1183
                                          'preg_replace',
1184
                                          'preg_split',
1185
                                          'print_r',
1186
                                          'readdir',
1187
                                          'reset',
1188
                                          'search',
1189
                                          'sizeof',
1190
                                          'str_replace',
1191
                                          'strcasecmp',
1192
                                          'strlen',
1193
                                          'strpos',
1194
                                          'substr',
1195
                                          'substr_count'),
1196
                     'extensions' => array('pcre'),
1197
                     'constants' => array('FALSE',
1198
                                          'NULL',
1199
                                          'PREG_SPLIT_DELIM_CAPTURE',
1200
                                          'PREG_SPLIT_NO_EMPTY',
1201
                                          'TRUE'),
1202
                     'tokens' => array(),
1203
                     'cond_code' => array(4));
1204
        $this->assertSame($exp, $r);
1205
    }
1206
 
1207
    /**
1208
     * Tests parsing multiple strings (chunk of code)
1209
     *
1210
     * @return void
1211
     * @covers PHP_CompatInfo::parseArray
1212
     * @group  parseArray
1213
     * @group  standard
1214
     */
1215
    public function testParseArrayString()
1216
    {
1217
        $code1 = "<?php
1218
php_check_syntax('somefile.php');
1219
?>";
1220
        $code2 = "<?php
1221
\$array1 = array('blue'  => 1, 'red'  => 2, 'green'  => 3, 'purple' => 4);
1222
\$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan'   => 8);
1223
 
1224
\$diff = array_diff_key(\$array1, \$array2);
1225
?>";
1226
        $data  = array($code1, $code2);
1227
        $opt   = array('is_string' => true);
1228
 
1229
        $r   = $this->pci->parseArray($data, $opt);
1230
        $exp = array('ignored_files' => array(),
1231
                     'ignored_functions' => array(),
1232
                     'ignored_extensions' => array(),
1233
                     'ignored_constants' => array(),
1234
                     'max_version' => '5.0.4',
1235
                     'version' => '5.1.0',
1236
                     'classes' => array(),
1237
                     'functions' => array('array_diff_key', 'php_check_syntax'),
1238
                     'extensions' => array(),
1239
                     'constants' => array(),
1240
                     'tokens' => array(),
1241
                     'cond_code' => array(0),
1242
                     'string_1' => array(
1243
                          'ignored_functions' => array(),
1244
                          'ignored_extensions' => array(),
1245
                          'ignored_constants' => array(),
1246
                          'max_version' => '5.0.4',
1247
                          'version' => '5.0.0',
1248
                          'classes' => array(),
1249
                          'functions' => array('php_check_syntax'),
1250
                          'extensions' => array(),
1251
                          'constants' => array(),
1252
                          'tokens' => array(),
1253
                          'cond_code' => array(0)),
1254
                     'string_2' => array(
1255
                          'ignored_functions' => array(),
1256
                          'ignored_extensions' => array(),
1257
                          'ignored_constants' => array(),
1258
                          'max_version' => '',
1259
                          'version' => '5.1.0',
1260
                          'classes' => array(),
1261
                          'functions' => array('array_diff_key'),
1262
                          'extensions' => array(),
1263
                          'constants' => array(),
1264
                          'tokens' => array(),
1265
                          'cond_code' => array(0))
1266
                     );
1267
        $this->assertSame($exp, $r);
1268
    }
1269
 
1270
    /**
1271
     * Tests parsing nothing (all files are excluded from scope)
1272
     *
1273
     * @return void
1274
     * @covers PHP_CompatInfo::parseArray
1275
     * @group  parseArray
1276
     * @group  standard
1277
     */
1278
    public function testParseArrayWithNoFiles()
1279
    {
1280
        $files = get_included_files();
1281
        $opt   = array('ignore_files' => $files);
1282
 
1283
        $r = $this->pci->parseArray($files, $opt);
1284
        $this->assertFalse($r);
1285
    }
1286
 
1287
    /**
1288
     * Tests loading functions list for a PHP version
1289
     *
1290
     * @return void
1291
     * @covers PHP_CompatInfo::loadVersion
1292
     * @group  loadVersion
1293
     * @group  standard
1294
     */
1295
    public function testLoadVersion()
1296
    {
1297
        $resources   = array('date', 'filter', 'gd', 'gmp', 'mbstring', 'ming',
1298
                             'mysql', 'openssl', 'pgsql',
1299
                             'posix', 'snmp', 'spl');
1300
        $testSkipped = array();
1301
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
1302
            foreach ($testSkipped as $reason) {
1303
                $this->markTestSkipped($reason);
1304
            }
1305
        }
1306
 
1307
        $r   = $this->pci->loadVersion('5.2.0');
1308
        $exp = array('array_fill_keys',
1309
                     'error_get_last',
1310
                     'filter_has_var',
1311
                     'filter_id',
1312
                     'filter_input',
1313
                     'filter_input_array',
1314
                     'filter_list',
1315
                     'filter_var',
1316
                     'filter_var_array',
1317
                     'gmp_nextprime',
1318
                     'imagegrabscreen',
1319
                     'imagegrabwindow',
1320
                     'iterator_apply',
1321
                     'mb_list_encodings_alias_names',
1322
                     'mb_list_mime_names',
1323
                     'mb_stripos',
1324
                     'mb_stristr',
1325
                     'mb_strrchr',
1326
                     'mb_strrichr',
1327
                     'mb_strripos',
1328
                     'mb_strstr',
1329
                     'memory_get_peak_usage',
1330
                     'ming_setswfcompression',
1331
                     'mysql_set_charset',
1332
                     'openssl_csr_get_public_key',
1333
                     'openssl_csr_get_subject',
1334
                     'openssl_pkcs12_export',
1335
                     'openssl_pkcs12_export_to_file',
1336
                     'openssl_pkcs12_read',
1337
                     'openssl_pkey_get_details',
1338
                     'pg_field_table',
1339
                     'php_ini_loaded_file',
1340
                     'posix_initgroups',
1341
                     'preg_last_error',
1342
                     'snmp_set_oid_output_format',
1343
                     'spl_object_hash',
1344
                     'stream_is_local',
1345
                     'stream_socket_shutdown',
1346
                     'sys_get_temp_dir',
1347
                     'timezone_transitions_get');
1348
        $this->assertSame($exp, $r);
1349
    }
1350
 
1351
    /**
1352
     * Tests loading functions list for a PHP version range
1353
     *
1354
     * @return void
1355
     * @covers PHP_CompatInfo::loadVersion
1356
     * @group  loadVersion
1357
     * @group  standard
1358
     */
1359
    public function testLoadVersionRange()
1360
    {
1361
        $resources   = array('date', 'filter', 'gd', 'gmp', 'mbstring', 'ming',
1362
                             'openssl', 'pgsql',
1363
                             'posix', 'snmp', 'spl');
1364
        $testSkipped = array();
1365
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
1366
            foreach ($testSkipped as $reason) {
1367
                $this->markTestSkipped($reason);
1368
            }
1369
        }
1370
 
1371
        $r   = $this->pci->loadVersion('5.2.0', '5.2.2');
1372
        $exp = array('array_fill_keys',
1373
                     'error_get_last',
1374
                     'filter_has_var',
1375
                     'filter_id',
1376
                     'filter_input',
1377
                     'filter_input_array',
1378
                     'filter_list',
1379
                     'filter_var',
1380
                     'filter_var_array',
1381
                     'gmp_nextprime',
1382
                     'imagegrabscreen',
1383
                     'imagegrabwindow',
1384
                     'iterator_apply',
1385
                     'mb_list_encodings_alias_names',
1386
                     'mb_list_mime_names',
1387
                     'mb_stripos',
1388
                     'mb_stristr',
1389
                     'mb_strrchr',
1390
                     'mb_strrichr',
1391
                     'mb_strripos',
1392
                     'mb_strstr',
1393
                     'memory_get_peak_usage',
1394
                     'ming_setswfcompression',
1395
                     'openssl_csr_get_public_key',
1396
                     'openssl_csr_get_subject',
1397
                     'openssl_pkcs12_export',
1398
                     'openssl_pkcs12_export_to_file',
1399
                     'openssl_pkcs12_read',
1400
                     'openssl_pkey_get_details',
1401
                     'pg_field_table',
1402
                     'posix_initgroups',
1403
                     'preg_last_error',
1404
                     'snmp_set_oid_output_format',
1405
                     'spl_object_hash',
1406
                     'stream_socket_shutdown',
1407
                     'sys_get_temp_dir',
1408
                     'timezone_transitions_get');
1409
        $this->assertSame($exp, $r);
1410
    }
1411
 
1412
    /**
1413
     * Tests loading function list for a range of PHP version,
1414
     * group by version number
1415
     *
1416
     * What's new with versions 4.3.2 to 4.4.0 : 13 + 30 + 5 functions
1417
     *
1418
     * @return void
1419
     * @covers PHP_CompatInfo::loadVersion
1420
     * @group  loadVersion
1421
     * @group  standard
1422
     */
1423
    public function testLoadVersionRangeGroupByVersion()
1424
    {
1425
        $resources   = array('bz2', 'gd', 'imap', 'oci8', 'snmp', 'zlib');
1426
        $testSkipped = array();
1427
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
1428
            foreach ($testSkipped as $reason) {
1429
                $this->markTestSkipped($reason);
1430
            }
1431
        }
1432
 
1433
        $r   = $this->pci->loadVersion('4.3.2', '4.4.0', false, true);
1434
        $exp = array('4.3.2' => array('apache_get_modules',
1435
                                      'apache_get_version',
1436
                                      'domxml_attr_set_value',
1437
                                      'domxml_doc_free_doc',
1438
                                      'imageantialias',
1439
                                      'imagecolorallocatealpha',
1440
                                      'imageistruecolor',
1441
                                      'imagesavealpha',
1442
                                      'memory_get_usage',
1443
                                      'ocipasswordchange',
1444
                                      'session_regenerate_id',
1445
                                      'stream_wrapper_register',
1446
                                      'zlib_get_coding_type'),
1447
                     '4.3.3' => array('bzclose',
1448
                                      'bzcompress',
1449
                                      'bzdecompress',
1450
                                      'bzerrno',
1451
                                      'bzerror',
1452
                                      'bzerrstr',
1453
                                      'bzflush',
1454
                                      'bzopen',
1455
                                      'bzread',
1456
                                      'bzwrite',
1457
                                      'imap_timeout',
1458
                                      'nsapi_request_headers',
1459
                                      'nsapi_response_headers',
1460
                                      'nsapi_virtual',
1461
                                      'snmp_get_valueretrieval',
1462
                                      'snmp_set_valueretrieval',
1463
                                      'solid_fetch_prev',
1464
                                      'swfmovie_add',
1465
                                      'swfmovie_init',
1466
                                      'swfmovie_labelframe',
1467
                                      'swfmovie_nextframe',
1468
                                      'swfmovie_output',
1469
                                      'swfmovie_save',
1470
                                      'swfmovie_savetofile',
1471
                                      'swfmovie_setbackground',
1472
                                      'swfmovie_setdimension',
1473
                                      'swfmovie_setframes',
1474
                                      'swfmovie_setrate',
1475
                                      'swfmovie_streammp3',
1476
                                      'swfsprite_labelframe'),
1477
                     '4.4.0' => array('session_commit',
1478
                                      'snmp2_get',
1479
                                      'snmp2_real_walk',
1480
                                      'snmp2_set',
1481
                                      'snmp2_walk'));
1482
        $this->assertSame($exp, $r);
1483
    }
1484
 
1485
    /**
1486
     * Tests loading function+constant list for a single PHP version
1487
     *
1488
     * What's new with version 4.3.10 : 0 functions and 2 new constants
1489
     *
1490
     * @return void
1491
     * @covers PHP_CompatInfo::loadVersion
1492
     * @group  loadVersion
1493
     * @group  standard
1494
     */
1495
    public function testLoadVersionRangeWithConstant()
1496
    {
1497
        $r   = $this->pci->loadVersion('4.3.10', '4.3.10', true);
1498
        $exp = array('functions' => array(),
1499
                     'constants' => array('PHP_EOL',
1500
                                          'UPLOAD_ERR_NO_TMP_DIR'));
1501
        $this->assertSame($exp, $r);
1502
    }
1503
 
1504
    /**
1505
     * Tests loading function list for a range of PHP version,
1506
     * group by version number
1507
     *
1508
     * What's new with versions 4.3.2 to 4.4.0 : 13 + 30 + 5 functions
1509
     *
1510
     * @return void
1511
     * @covers PHP_CompatInfo::loadVersion
1512
     * @group  loadVersion
1513
     * @group  standard
1514
     */
1515
    public function testLoadVersionRangeWithConstantGroupByVersion()
1516
    {
1517
        $resources   = array('bz2', 'gd', 'imap', 'oci8', 'snmp', 'zlib');
1518
        $testSkipped = array();
1519
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
1520
            foreach ($testSkipped as $reason) {
1521
                $this->markTestSkipped($reason);
1522
            }
1523
        }
1524
 
1525
        $r   = $this->pci->loadVersion('4.3.2', '4.4.0', true, true);
1526
        $exp = array('functions' => array(
1527
                     '4.3.2' => array('apache_get_modules',
1528
                                      'apache_get_version',
1529
                                      'domxml_attr_set_value',
1530
                                      'domxml_doc_free_doc',
1531
                                      'imageantialias',
1532
                                      'imagecolorallocatealpha',
1533
                                      'imageistruecolor',
1534
                                      'imagesavealpha',
1535
                                      'memory_get_usage',
1536
                                      'ocipasswordchange',
1537
                                      'session_regenerate_id',
1538
                                      'stream_wrapper_register',
1539
                                      'zlib_get_coding_type'),
1540
                     '4.3.3' => array('bzclose',
1541
                                      'bzcompress',
1542
                                      'bzdecompress',
1543
                                      'bzerrno',
1544
                                      'bzerror',
1545
                                      'bzerrstr',
1546
                                      'bzflush',
1547
                                      'bzopen',
1548
                                      'bzread',
1549
                                      'bzwrite',
1550
                                      'imap_timeout',
1551
                                      'nsapi_request_headers',
1552
                                      'nsapi_response_headers',
1553
                                      'nsapi_virtual',
1554
                                      'snmp_get_valueretrieval',
1555
                                      'snmp_set_valueretrieval',
1556
                                      'solid_fetch_prev',
1557
                                      'swfmovie_add',
1558
                                      'swfmovie_init',
1559
                                      'swfmovie_labelframe',
1560
                                      'swfmovie_nextframe',
1561
                                      'swfmovie_output',
1562
                                      'swfmovie_save',
1563
                                      'swfmovie_savetofile',
1564
                                      'swfmovie_setbackground',
1565
                                      'swfmovie_setdimension',
1566
                                      'swfmovie_setframes',
1567
                                      'swfmovie_setrate',
1568
                                      'swfmovie_streammp3',
1569
                                      'swfsprite_labelframe'),
1570
                     '4.4.0' => array('session_commit',
1571
                                      'snmp2_get',
1572
                                      'snmp2_real_walk',
1573
                                      'snmp2_set',
1574
                                      'snmp2_walk')),
1575
                     'constants' => array(
1576
                     '4.3.10' => array('PHP_EOL',
1577
                                       'UPLOAD_ERR_NO_TMP_DIR')
1578
                                       ));
1579
        $this->assertSame($exp, $r);
1580
    }
1581
 
1582
    /**
1583
     * Tests loading function+constant list for a PHP version range
1584
     *
1585
     * What's new with since version 5.2.1 : 24 new functions and 0 constant
1586
     *
1587
     * @return void
1588
     * @covers PHP_CompatInfo::loadVersion
1589
     * @group  loadVersion
1590
     * @group  standard
1591
     */
1592
    public function testLoadVersionWithConstant()
1593
    {
1594
        $resources   = array('gd', 'ming', 'openssl');
1595
        $testSkipped = array();
1596
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
1597
            foreach ($testSkipped as $reason) {
1598
                $this->markTestSkipped($reason);
1599
            }
1600
        }
1601
 
1602
        $r   = $this->pci->loadVersion('5.2.1', false, true);
1603
        $exp = array('functions' => array('imagegrabscreen',
1604
                                          'imagegrabwindow',
1605
                                          'ming_setswfcompression',
1606
                                          'mysql_set_charset',
1607
                                          'openssl_pkcs12_export',
1608
                                          'openssl_pkcs12_export_to_file',
1609
                                          'openssl_pkcs12_read',
1610
                                          'php_ini_loaded_file',
1611
                                          'stream_is_local',
1612
                                          'stream_socket_shutdown',
1613
                                          'sys_get_temp_dir'),
1614
                     'constants' => array('PCRE_VERSION',
1615
                                          'PREG_BAD_UTF8_OFFSET_ERROR'));
1616
        $this->assertSame($exp, $r);
1617
    }
1618
 
1619
    /**
1620
     * Tests the PHP Method chaining feature introduced with PHP5
1621
     * Sample #1
1622
     *
1623
     * @link http://cowburn.info/php/php5-method-chaining/
1624
     * @return void
1625
     * @covers PHP_CompatInfo::parseFile
1626
     * @group  parseFile
1627
     * @group  standard
1628
     */
1629
    public function testPHP5MethodChainingSamp1()
1630
    {
1631
        $ds  = DIRECTORY_SEPARATOR;
1632
        $fn  = dirname(__FILE__) . $ds . 'parseFile' . $ds
1633
             . 'php5_method_chaining.php';
1634
        $r   = $this->pci->parseFile($fn);
1635
        $exp = array('ignored_files' => array(),
1636
                     'ignored_functions' => array(),
1637
                     'ignored_extensions' => array(),
1638
                     'ignored_constants' => array(),
1639
                     'max_version' => '',
1640
                     'version' => '5.0.0',
1641
                     'classes' => array('Person'),
1642
                     'functions' => array('printf'),
1643
                     'extensions' => array(),
1644
                     'constants' => array(),
1645
                     'tokens' => array(),
1646
                     'cond_code' => array(0));
1647
        $this->assertSame($exp, $r);
1648
    }
1649
 
1650
    /**
1651
     * Tests the PHP Method chaining feature introduced with PHP5.
1652
     * Sample #2
1653
     *
1654
     * @return void
1655
     * @covers PHP_CompatInfo::parseFile
1656
     * @group  parseFile
1657
     * @group  standard
1658
     */
1659
    public function testPHP5MethodChainingSamp2()
1660
    {
1661
        $ds  = DIRECTORY_SEPARATOR;
1662
        $fn  = dirname(__FILE__) . $ds . 'parseFile' . $ds
1663
             . 'php5_method_chaining_samp2.php';
1664
        $r   = $this->pci->parseFile($fn);
1665
        $exp = array('ignored_files' => array(),
1666
                     'ignored_functions' => array(),
1667
                     'ignored_extensions' => array(),
1668
                     'ignored_constants' => array(),
1669
                     'max_version' => '',
1670
                     'version' => '5.0.0',
1671
                     'classes' => array(),
1672
                     'functions' => array(),
1673
                     'extensions' => array(),
1674
                     'constants' => array(),
1675
                     'tokens' => array(),
1676
                     'cond_code' => array(0));
1677
        $this->assertSame($exp, $r);
1678
    }
1679
 
1680
    /**
1681
     * Tests parsing a single file with 'ignore_functions_match' option
1682
     * Sample #1
1683
     *
1684
     * Exclude all functions that are referenced by php function_exists(),
1685
     * and match regular expressions :
1686
     * - word file_put_contents (case insensitive)
1687
     * - beginning with debug (case sensitive)
1688
     *
1689
     * @return void
1690
     * @since  version 1.7.0
1691
     * @covers PHP_CompatInfo::parseFile
1692
     * @group  parseFile
1693
     * @group  standard
1694
     */
1695
    public function testParseFileWithIgnoreFunctionsMatchSamp1()
1696
    {
1697
        $ds  = DIRECTORY_SEPARATOR;
1698
        $fn  = dirname(__FILE__) . $ds . 'parseFile' . $ds
1699
             . 'ignore_functions_match.php';
1700
        $opt = array('ignore_functions_match' =>
1701
                   array('function_exists', array('/^File_put_contents$/i',
1702
                                                  '/^debug/')));
1703
 
1704
        $r = $this->pci->parseFile($fn, $opt);
1705
        $this->assertType('array', $r);
1706
 
1707
        $exp = array('ignored_files' => array(),
1708
                     'ignored_functions' => array('debug_backtrace', 'file_put_contents'),
1709
                     'ignored_extensions' => array(),
1710
                     'ignored_constants' => array(),
1711
                     'max_version' => '',
1712
                     'version' => '5.0.0',
1713
                     'classes' => array(),
1714
                     'functions' => array('debug_backtrace',
1715
                                          'debug_print_backtrace',
1716
                                          'fclose',
1717
                                          'file_put_contents',
1718
                                          'fopen',
1719
                                          'fwrite'),
1720
                     'extensions' => array(),
1721
                     'constants' => array('FALSE'),
1722
                     'tokens' => array(),
1723
                     'cond_code' => array(0));
1724
        $this->assertSame($exp, $r);
1725
    }
1726
 
1727
    /**
1728
     * Tests parsing a single file with 'ignore_functions_match' option
1729
     * Sample #2
1730
     *
1731
     * Exclude (from scope) all functions that are 'debug' prefixed (case sensitive).
1732
     *
1733
     * If you want a case-insensitive search add an "i" after the pattern delimiter,
1734
     * like that:  '/^debug/i'
1735
     *
1736
     * @return void
1737
     * @since  version 1.7.0
1738
     * @covers PHP_CompatInfo::parseFile
1739
     * @group  parseFile
1740
     * @group  standard
1741
     */
1742
    public function testParseFileWithIgnoreFunctionsMatchSamp2()
1743
    {
1744
        $ds  = DIRECTORY_SEPARATOR;
1745
        $fn  = dirname(__FILE__) . $ds . 'parseFile' . $ds . 'ignore_functions_match.php';
1746
        $opt = array('ignore_functions_match' => array('preg_match', array('/^debug/')));
1747
 
1748
        $r = $this->pci->parseFile($fn, $opt);
1749
        $this->assertType('array', $r);
1750
 
1751
        $exp = array('ignored_files' => array(),
1752
                     'ignored_functions' => array('debug_backtrace', 'debug_print_backtrace'),
1753
                     'ignored_extensions' => array(),
1754
                     'ignored_constants' => array(),
1755
                     'max_version' => '',
1756
                     'version' => '5.0.0',
1757
                     'classes' => array(),
1758
                     'functions' => array('debug_backtrace',
1759
                                          'debug_print_backtrace',
1760
                                          'fclose',
1761
                                          'file_put_contents',
1762
                                          'fopen',
1763
                                          'function_exists',
1764
                                          'fwrite'),
1765
                     'extensions' => array(),
1766
                     'constants' => array('FALSE'),
1767
                     'tokens' => array(),
1768
                     'cond_code' => array(1));
1769
        $this->assertSame($exp, $r);
1770
    }
1771
 
1772
    /**
1773
     * Tests parsing a single file with 'ignore_functions_match' option
1774
     * Sample #3
1775
     *
1776
     * When I don't know the script to parse (most case), I would really
1777
     * exclude from scope all functions that are conditionned by function_exists().
1778
     *
1779
     * @return void
1780
     * @since  version 1.7.0
1781
     * @covers PHP_CompatInfo::parseFile
1782
     * @group  parseFile
1783
     * @group  standard
1784
     */
1785
    public function testParseFileWithIgnoreFunctionsMatchSamp3()
1786
    {
1787
        $ds  = DIRECTORY_SEPARATOR;
1788
        $fn  = dirname(__FILE__) . $ds . 'parseFile' . $ds . 'ignore_functions_match.php';
1789
        $opt = array('ignore_functions_match' => array('function_exists', array('/.*/')));
1790
 
1791
        $r = $this->pci->parseFile($fn, $opt);
1792
        $this->assertType('array', $r);
1793
 
1794
        $exp = array('ignored_files' => array(),
1795
                     'ignored_functions' => array('debug_backtrace', 'file_put_contents'),
1796
                     'ignored_extensions' => array(),
1797
                     'ignored_constants' => array(),
1798
                     'max_version' => '',
1799
                     'version' => '5.0.0',
1800
                     'classes' => array(),
1801
                     'functions' => array('debug_backtrace',
1802
                                          'debug_print_backtrace',
1803
                                          'fclose',
1804
                                          'file_put_contents',
1805
                                          'fopen',
1806
                                          'fwrite'),
1807
                     'extensions' => array(),
1808
                     'constants' => array('FALSE'),
1809
                     'tokens' => array(),
1810
                     'cond_code' => array(0));
1811
        $this->assertSame($exp, $r);
1812
    }
1813
 
1814
    /**
1815
     * Tests parsing a single file with 'ignore_extensions_match' option
1816
     * Sample #1
1817
     *
1818
     * Exclude all extensions (and their functions) that are referenced by
1819
     * php extension_loaded(), and match regular expressions
1820
     *
1821
     * @return void
1822
     * @since  version 1.7.0
1823
     * @covers PHP_CompatInfo::parseFile
1824
     * @group  parseFile
1825
     * @group  standard
1826
     */
1827
    public function testParseFileWithIgnoreExtensionsMatchSamp1()
1828
    {
1829
        $resources   = array('gd', 'SQLite', 'xdebug');
1830
        $testSkipped = array();
1831
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
1832
            foreach ($testSkipped as $reason) {
1833
                $this->markTestSkipped($reason);
1834
            }
1835
        }
1836
 
1837
        $ds  = DIRECTORY_SEPARATOR;
1838
        $fn  = dirname(__FILE__) . $ds . 'parseDir' . $ds . 'extensions.php';
1839
        $opt = array('ignore_extensions_match' =>
1840
                   array('extension_loaded', array('/^SQLite$/')));
1841
 
1842
        $r = $this->pci->parseFile($fn, $opt);
1843
        $this->assertType('array', $r);
1844
 
1845
        $exp = array('ignored_files' => array(),
1846
                     'ignored_functions' => array('sqlite_libversion'),
1847
                     'ignored_extensions' => array('SQLite'),
1848
                     'ignored_constants' => array(),
1849
                     'max_version' => '',
1850
                     'version' => '4.3.2',
1851
                     'classes' => array(),
1852
                     'functions' => array('apache_get_modules',
1853
                                          'dl',
1854
                                          'imageantialias',
1855
                                          'imagecreate',
1856
                                          'print_r',
1857
                                          'sqlite_libversion',
1858
                                          'xdebug_start_trace',
1859
                                          'xdebug_stop_trace'),
1860
                     'extensions' => array('gd',
1861
                                           'SQLite',
1862
                                           'xdebug'),
1863
                     'constants' => array('PHP_SHLIB_SUFFIX',
1864
                                          'TRUE'),
1865
                     'tokens' => array(),
1866
                     'cond_code' => array(0));
1867
        $this->assertSame($exp, $r);
1868
    }
1869
 
1870
    /**
1871
     * Tests parsing a single file with 'ignore_extensions_match' option
1872
     * Sample #2
1873
     *
1874
     * Exclude all extensions (and their functions) that are referenced freely by
1875
     * preg_match clause, and match regular expression:
1876
     * - beginning with 'xdebug' (case sensitive)
1877
     *
1878
     * @return void
1879
     * @since  version 1.7.0
1880
     * @covers PHP_CompatInfo::parseFile
1881
     * @group  parseFile
1882
     * @group  standard
1883
     */
1884
    public function testParseFileWithIgnoreExtensionsMatchSamp2()
1885
    {
1886
        $resources   = array('gd', 'SQLite', 'xdebug');
1887
        $testSkipped = array();
1888
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
1889
            foreach ($testSkipped as $reason) {
1890
                $this->markTestSkipped($reason);
1891
            }
1892
        }
1893
 
1894
        $ds  = DIRECTORY_SEPARATOR;
1895
        $fn  = dirname(__FILE__) . $ds . 'parseDir' . $ds . 'extensions.php';
1896
        $opt = array('ignore_extensions_match' =>
1897
                   array('preg_match', array('/^xdebug/')));
1898
 
1899
        $r = $this->pci->parseFile($fn, $opt);
1900
        $this->assertType('array', $r);
1901
 
1902
        $exp = array('ignored_files' => array(),
1903
                     'ignored_functions' => array('xdebug_start_trace',
1904
                                                  'xdebug_stop_trace'),
1905
                     'ignored_extensions' => array('xdebug'),
1906
                     'ignored_constants' => array(),
1907
                     'max_version' => '',
1908
                     'version' => '4.3.2',
1909
                     'classes' => array(),
1910
                     'functions' => array('apache_get_modules',
1911
                                          'dl',
1912
                                          'extension_loaded',
1913
                                          'imageantialias',
1914
                                          'imagecreate',
1915
                                          'print_r',
1916
                                          'sqlite_libversion',
1917
                                          'xdebug_start_trace',
1918
                                          'xdebug_stop_trace'),
1919
                     'extensions' => array('gd',
1920
                                           'SQLite',
1921
                                           'xdebug'),
1922
                     'constants' => array('PHP_SHLIB_SUFFIX',
1923
                                          'TRUE'),
1924
                     'tokens' => array(),
1925
                     'cond_code' => array(2));
1926
        $this->assertSame($exp, $r);
1927
    }
1928
 
1929
    /**
1930
     * Tests parsing a single file with 'ignore_constants_match' option
1931
     * Sample #1
1932
     *
1933
     * Exclude all constants that are referenced by php defined(),
1934
     * and match regular expressions
1935
     *
1936
     * @return void
1937
     * @since  version 1.7.0
1938
     * @covers PHP_CompatInfo::parseFile
1939
     * @group  parseFile
1940
     * @group  standard
1941
     */
1942
    public function testParseFileWithIgnoreConstantsMatchSamp1()
1943
    {
1944
        $resources   = array('date', 'SimpleXML');
1945
        $testSkipped = array();
1946
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
1947
            foreach ($testSkipped as $reason) {
1948
                $this->markTestSkipped($reason);
1949
            }
1950
        }
1951
 
1952
        $ds  = DIRECTORY_SEPARATOR;
1953
        $fn  = dirname(__FILE__) . $ds . 'parseFile' . $ds . 'conditional.php';
1954
        $opt = array('ignore_constants_match' =>
1955
                   array('defined', array('/^directory/i')));
1956
 
1957
        $r = $this->pci->parseFile($fn, $opt);
1958
        $this->assertType('array', $r);
1959
 
1960
        $exp = array('ignored_files' => array(),
1961
                     'ignored_functions' => array(),
1962
                     'ignored_extensions' => array(),
1963
                     'ignored_constants' => array('DIRECTORY_SEPARATOR'),
1964
                     'max_version' => '',
1965
                     'version' => '5.1.1',
1966
                     'classes' => array(),
1967
                     'functions' => array('basename',
1968
                                          'date',
1969
                                          'debug_backtrace',
1970
                                          'define',
1971
                                          'dirname',
1972
                                          'function_exists',
1973
                                          'phpversion',
1974
                                          'simplexml_load_file',
1975
                                          'strtoupper',
1976
                                          'substr',
1977
                                          'version_compare'),
1978
                     'extensions' => array( 'date', 'SimpleXML'),
1979
                     'constants' => array('DATE_W3C',
1980
                                          'DIRECTORY_SEPARATOR',
1981
                                          'FALSE',
1982
                                          'PHP_EOL',
1983
                                          'PHP_OS',
1984
                                          '__FILE__'),
1985
                     'tokens' => array(),
1986
                     'cond_code' => array(1));
1987
        $this->assertSame($exp, $r);
1988
    }
1989
 
1990
    /**
1991
     * Tests parsing a single file with 'ignore_constants_match' option
1992
     * Sample #2
1993
     *
1994
     * Exclude all constants that freely match regular expressions
1995
     *
1996
     * @return void
1997
     * @since  version 1.7.0
1998
     * @covers PHP_CompatInfo::parseFile
1999
     * @group  parseFile
2000
     * @group  standard
2001
     */
2002
    public function testParseFileWithIgnoreConstantsMatchSamp2()
2003
    {
2004
        $resources   = array('date', 'SimpleXML');
2005
        $testSkipped = array();
2006
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
2007
            foreach ($testSkipped as $reason) {
2008
                $this->markTestSkipped($reason);
2009
            }
2010
        }
2011
 
2012
        $ds  = DIRECTORY_SEPARATOR;
2013
        $fn  = dirname(__FILE__) . $ds . 'parseFile' . $ds . 'conditional.php';
2014
        $opt = array('ignore_constants_match' =>
2015
                   array('preg_match', array('/^dir/i', '/^DATE_W3C$/')));
2016
 
2017
        $r = $this->pci->parseFile($fn, $opt);
2018
        $this->assertType('array', $r);
2019
 
2020
        $exp = array('ignored_files' => array(),
2021
                     'ignored_functions' => array(),
2022
                     'ignored_extensions' => array(),
2023
                     'ignored_constants' => array('DATE_W3C',
2024
                                                  'DIRECTORY_SEPARATOR'),
2025
                     'max_version' => '',
2026
                     'version' => '5.0.0',
2027
                     'classes' => array(),
2028
                     'functions' => array('basename',
2029
                                          'date',
2030
                                          'debug_backtrace',
2031
                                          'define',
2032
                                          'defined',
2033
                                          'dirname',
2034
                                          'function_exists',
2035
                                          'phpversion',
2036
                                          'simplexml_load_file',
2037
                                          'strtoupper',
2038
                                          'substr',
2039
                                          'version_compare'),
2040
                     'extensions' => array('date', 'SimpleXML'),
2041
                     'constants' => array('DATE_W3C',
2042
                                          'DIRECTORY_SEPARATOR',
2043
                                          'FALSE',
2044
                                          'PHP_EOL',
2045
                                          'PHP_OS',
2046
                                          '__FILE__'),
2047
                     'tokens' => array(),
2048
                     'cond_code' => array(5));
2049
        $this->assertSame($exp, $r);
2050
    }
2051
 
2052
    /**
2053
     * Tests parsing multiple strings (chunk of code)
2054
     * and return minimum PHP version required
2055
     *
2056
     * @return void
2057
     * @covers PHP_CompatInfo::getVersion
2058
     * @group  getVersion
2059
     * @group  standard
2060
     */
2061
    public function testGetVersion()
2062
    {
2063
        $code1 = "<?php
2064
php_check_syntax('somefile.php');
2065
?>";
2066
        $code2 = "<?php
2067
\$array1 = array('blue'  => 1, 'red'  => 2, 'green'  => 3, 'purple' => 4);
2068
\$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan'   => 8);
2069
 
2070
\$diff = array_diff_key(\$array1, \$array2);
2071
?>";
2072
        $data  = array($code1, $code2);
2073
        $opt   = array('is_string' => true);
2074
 
2075
        $this->pci->parseArray($data, $opt);
2076
        $r   = $this->pci->getVersion();
2077
        $exp = '5.1.0';
2078
        $this->assertEquals($exp, $r);
2079
    }
2080
 
2081
    /**
2082
     * Tests parsing multiple strings (chunk of code)
2083
     * and return maximum PHP version
2084
     *
2085
     * @return void
2086
     * @covers PHP_CompatInfo::getVersion
2087
     * @group  getVersion
2088
     * @group  standard
2089
     */
2090
    public function testGetVersionWithMax()
2091
    {
2092
        $code1 = "<?php
2093
php_check_syntax('somefile.php');
2094
?>";
2095
        $code2 = "<?php
2096
\$array1 = array('blue'  => 1, 'red'  => 2, 'green'  => 3, 'purple' => 4);
2097
\$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan'   => 8);
2098
 
2099
\$diff = array_diff_key(\$array1, \$array2);
2100
?>";
2101
        $data  = array($code1, $code2);
2102
        $opt   = array('is_string' => true);
2103
 
2104
        $this->pci->parseArray($data, $opt);
2105
        $r   = $this->pci->getVersion(false, true);
2106
        $exp = '5.0.4';
2107
        $this->assertEquals($exp, $r);
2108
    }
2109
 
2110
    /**
2111
     * Tests parsing a file and get classes declared (end-user defined)
2112
     *
2113
     * @return void
2114
     * @covers PHP_CompatInfo::getClasses
2115
     * @group  getClasses
2116
     * @group  standard
2117
     */
2118
    public function testGetClasses()
2119
    {
2120
        $ds  = DIRECTORY_SEPARATOR;
2121
        $fn  = dirname(__FILE__) . $ds . 'parseFile' . $ds
2122
             . 'php5_method_chaining.php';
2123
        $this->pci->parseFile($fn);
2124
 
2125
        $r   = $this->pci->getClasses();
2126
        $exp = array('Person');
2127
        $this->assertSame($exp, $r);
2128
    }
2129
 
2130
    /**
2131
     * Tests parsing a directory and get classes declared (internal)
2132
     *
2133
     * @return void
2134
     * @covers PHP_CompatInfo::getClasses
2135
     * @group  getClasses
2136
     * @group  standard
2137
     */
2138
    public function testGetClassesInternal()
2139
    {
2140
        $ds  = DIRECTORY_SEPARATOR;
2141
        $dir = dirname(__FILE__) . $ds . 'parseDir' . $ds;
2142
        $opt = array('recurse_dir' => true,
2143
                     'file_ext' => array('php', 'php5'));
2144
        $this->pci->parseDir($dir, $opt);
2145
 
2146
        $f   = $dir . 'PHP5' . $ds . 'tokens.php5';
2147
        $r   = $this->pci->getClasses($f);
2148
        $exp = array('Exception');
2149
        $this->assertSame($exp, $r);
2150
    }
2151
 
2152
    /**
2153
     * Tests parsing a file and get functions declared
2154
     * (internal and end-user defined)
2155
     *
2156
     * @return void
2157
     * @covers PHP_CompatInfo::getFunctions
2158
     * @group  getFunctions
2159
     * @group  standard
2160
     */
2161
    public function testGetFunctions()
2162
    {
2163
        $ds  = DIRECTORY_SEPARATOR;
2164
        $dir = dirname(__FILE__) . $ds . 'parseFile';
2165
        $src = $dir . $ds . 'File_Find-1.3.0__Find.php';
2166
        $this->pci->parseFile($src);
2167
 
2168
        $r   = $this->pci->getFunctions();
2169
        $exp = array('_file_find_match_shell_get_pattern',
2170
                     'addcslashes',
2171
                     'array_merge',
2172
                     'array_pop',
2173
                     'array_push',
2174
                     'basename',
2175
                     'closedir',
2176
                     'count',
2177
                     'define',
2178
                     'defined',
2179
                     'each',
2180
                     'explode',
2181
                     'glob',
2182
                     'implode',
2183
                     'is_a',
2184
                     'is_array',
2185
                     'is_dir',
2186
                     'is_readable',
2187
                     'maptree',
2188
                     'maptreemultiple',
2189
                     'opendir',
2190
                     'preg_match',
2191
                     'preg_replace',
2192
                     'preg_split',
2193
                     'print_r',
2194
                     'readdir',
2195
                     'reset',
2196
                     'search',
2197
                     'sizeof',
2198
                     'str_replace',
2199
                     'strcasecmp',
2200
                     'strlen',
2201
                     'strpos',
2202
                     'substr',
2203
                     'substr_count');
2204
        $this->assertSame($exp, $r);
2205
    }
2206
 
2207
    /**
2208
     * Tests parsing a directory and get functions declared
2209
     * (internal and end-user defined) for a specific file
2210
     *
2211
     * @return void
2212
     * @covers PHP_CompatInfo::getFunctions
2213
     * @group  getFunctions
2214
     * @group  standard
2215
     */
2216
    public function testGetFunctionsByFile()
2217
    {
2218
        $ds  = DIRECTORY_SEPARATOR;
2219
        $dir = dirname(__FILE__) . $ds . 'parseDir' . $ds;
2220
        $opt = array('recurse_dir' => true,
2221
                     'file_ext' => array('php', 'php5'));
2222
        $this->pci->parseDir($dir, $opt);
2223
 
2224
        $f   = $dir . 'extensions.php';
2225
        $r   = $this->pci->getFunctions($f);
2226
        $exp = array('apache_get_modules',
2227
                     'dl',
2228
                     'extension_loaded',
2229
                     'imageantialias',
2230
                     'imagecreate',
2231
                     'print_r',
2232
                     'sqlite_libversion',
2233
                     'xdebug_start_trace',
2234
                     'xdebug_stop_trace');
2235
        $this->assertSame($exp, $r);
2236
    }
2237
 
2238
    /**
2239
     * Tests parsing a file and get constants declared
2240
     * (internal and end-user defined)
2241
     *
2242
     * @return void
2243
     * @covers PHP_CompatInfo::getConstants
2244
     * @group  getConstants
2245
     * @group  standard
2246
     */
2247
    public function testGetConstants()
2248
    {
2249
        $ds  = DIRECTORY_SEPARATOR;
2250
        $src = dirname(__FILE__) . $ds . 'parseFile' . $ds . 'conditional.php';
2251
        $this->pci->parseFile($src);
2252
 
2253
        $r   = $this->pci->getConstants();
2254
        $exp = array('DATE_W3C',
2255
                     'DIRECTORY_SEPARATOR',
2256
                     'FALSE',
2257
                     'PHP_EOL',
2258
                     'PHP_OS',
2259
                     '__FILE__');
2260
        $this->assertSame($exp, $r);
2261
    }
2262
 
2263
    /**
2264
     * Tests parsing a directory and get constants declared
2265
     * (internal and end-user defined) for a specific file
2266
     *
2267
     * @return void
2268
     * @covers PHP_CompatInfo::getConstants
2269
     * @group  getConstants
2270
     * @group  standard
2271
     */
2272
    public function testGetConstantsByFile()
2273
    {
2274
        $ds  = DIRECTORY_SEPARATOR;
2275
        $dir = dirname(__FILE__) . $ds . 'parseDir' . $ds;
2276
        $opt = array('recurse_dir' => true,
2277
                     'file_ext' => array('php', 'php5'));
2278
        $this->pci->parseDir($dir, $opt);
2279
 
2280
        $f   = $dir . 'PHP5' . $ds . 'upload_error.php';
2281
        $r   = $this->pci->getConstants($f);
2282
        $exp = array('UPLOAD_ERR_CANT_WRITE',
2283
                     'UPLOAD_ERR_EXTENSION',
2284
                     'UPLOAD_ERR_FORM_SIZE',
2285
                     'UPLOAD_ERR_INI_SIZE',
2286
                     'UPLOAD_ERR_NO_FILE',
2287
                     'UPLOAD_ERR_NO_TMP_DIR',
2288
                     'UPLOAD_ERR_OK',
2289
                     'UPLOAD_ERR_PARTIAL');
2290
        $this->assertSame($exp, $r);
2291
    }
2292
 
2293
    /**
2294
     * Tests parsing a file and get tokens declared
2295
     *
2296
     * @return void
2297
     * @covers PHP_CompatInfo::getTokens
2298
     * @group  getTokens
2299
     * @group  standard
2300
     */
2301
    public function testGetTokens()
2302
    {
2303
        $ds  = DIRECTORY_SEPARATOR;
2304
        $src = dirname(__FILE__) . $ds . 'parseFile' . $ds . 'conditional.php';
2305
        $this->pci->parseFile($src);
2306
 
2307
        $r   = $this->pci->getTokens();
2308
        $exp = array();
2309
        $this->assertSame($exp, $r);
2310
    }
2311
 
2312
    /**
2313
     * Tests parsing a directory and get tokens declared
2314
     * for a specific file
2315
     *
2316
     * @return void
2317
     * @covers PHP_CompatInfo::getTokens
2318
     * @group  getTokens
2319
     * @group  standard
2320
     */
2321
    public function testGetTokensByFile()
2322
    {
2323
        $ds  = DIRECTORY_SEPARATOR;
2324
        $dir = dirname(__FILE__) . $ds . 'parseDir' . $ds;
2325
        $opt = array('recurse_dir' => true,
2326
                     'file_ext' => array('php', 'php5'));
2327
        $this->pci->parseDir($dir, $opt);
2328
 
2329
        $f   = $dir . 'PHP5' . $ds . 'tokens.php5';
2330
        $r   = $this->pci->getTokens($f);
2331
        $exp = array('abstract',
2332
                     'catch',
2333
                     'clone',
2334
                     'final',
2335
                     'implements',
2336
                     'instanceof',
2337
                     'interface',
2338
                     'private',
2339
                     'protected',
2340
                     'public',
2341
                     'throw',
2342
                     'try');
2343
        $this->assertSame($exp, $r);
2344
    }
2345
 
2346
    /**
2347
     * Tests parsing a directory and retrieve the Code Condition level
2348
     *
2349
     * @return void
2350
     * @covers PHP_CompatInfo::getConditions
2351
     * @group  getConditions
2352
     * @group  standard
2353
     */
2354
    public function testGetConditionsWithoutContext()
2355
    {
2356
        $ds  = DIRECTORY_SEPARATOR;
2357
        $dir = dirname(__FILE__) . $ds . 'parseDir' . $ds;
2358
        $opt = array('debug' => true,
2359
                     'recurse_dir' => true,
2360
                     'file_ext' => array('php', 'php5'));
2361
 
2362
        $this->pci->parseDir($dir, $opt);
2363
        $r   = $this->pci->getConditions(false, true);
2364
        $exp = 2; // extension condition code level
2365
        $this->assertEquals($exp, $r);
2366
    }
2367
 
2368
    /**
2369
     * Tests parsing a directory and retrieve the Code Condition
2370
     * contextual data
2371
     *
2372
     * @return void
2373
     * @covers PHP_CompatInfo::getConditions
2374
     * @group  getConditions
2375
     * @group  standard
2376
     */
2377
    public function testGetConditionsWithContext()
2378
    {
2379
        $ds  = DIRECTORY_SEPARATOR;
2380
        $dir = dirname(__FILE__) . $ds . 'parseDir' . $ds;
2381
        $opt = array('debug' => true,
2382
                     'recurse_dir' => true,
2383
                     'file_ext' => array('php', 'php5'));
2384
 
2385
        $this->pci->parseDir($dir, $opt);
2386
        $r   = $this->pci->getConditions();
2387
        $exp = array(2, array(array(), array('SQLite'), array()));
2388
        $this->assertSame($exp, $r);
2389
    }
2390
 
2391
    /**
2392
     * Tests parsing a directory and retrieve the Code Condition
2393
     * of a specific file
2394
     *
2395
     * @return void
2396
     * @covers PHP_CompatInfo::getConditions
2397
     * @group  getConditions
2398
     * @group  standard
2399
     */
2400
    public function testGetConditionsByFile()
2401
    {
2402
        $ds  = DIRECTORY_SEPARATOR;
2403
        $dir = dirname(__FILE__) . $ds . 'parseDir' . $ds;
2404
        $opt = array('debug' => false,
2405
                     'recurse_dir' => true,
2406
                     'file_ext' => array('php', 'php5'));
2407
 
2408
        $this->pci->parseDir($dir, $opt);
2409
        $f   = $dir . 'phpinfo.php';
2410
        $r   = $this->pci->getConditions($f);
2411
        $exp = array(0); // no condition code
2412
        $this->assertSame($exp, $r);
2413
    }
2414
 
2415
    /**
2416
     * Tests parsing a file and get extensions used
2417
     *
2418
     * @return void
2419
     * @covers PHP_CompatInfo::getExtensions
2420
     * @group  getExtensions
2421
     * @group  standard
2422
     */
2423
    public function testGetExtensions()
2424
    {
2425
        $resources   = array('date', 'SimpleXML');
2426
        $testSkipped = array();
2427
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
2428
            foreach ($testSkipped as $reason) {
2429
                $this->markTestSkipped($reason);
2430
            }
2431
        }
2432
 
2433
        $ds = DIRECTORY_SEPARATOR;
2434
        $fn = dirname(__FILE__) . $ds . 'parseFile' . $ds . 'conditional.php';
2435
        $this->pci->parseFile($fn);
2436
 
2437
        $r   = $this->pci->getExtensions();
2438
        $exp = array('date', 'SimpleXML');
2439
        $this->assertSame($exp, $r);
2440
    }
2441
 
2442
    /**
2443
     * Tests parsing a directory and get extensions used
2444
     * for a specific file
2445
     *
2446
     * @return void
2447
     * @covers PHP_CompatInfo::getExtensions
2448
     * @group  getExtensions
2449
     * @group  standard
2450
     */
2451
    public function testGetExtensionsByFile()
2452
    {
2453
        $resources   = array('gd', 'SQLite', 'xdebug');
2454
        $testSkipped = array();
2455
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
2456
            foreach ($testSkipped as $reason) {
2457
                $this->markTestSkipped($reason);
2458
            }
2459
        }
2460
 
2461
        $ds  = DIRECTORY_SEPARATOR;
2462
        $dir = dirname(__FILE__) . $ds . 'parseDir' . $ds;
2463
        $opt = array('recurse_dir' => true,
2464
                     'file_ext' => array('php', 'php5'));
2465
        $this->pci->parseDir($dir, $opt);
2466
 
2467
        $f   = $dir . 'extensions.php';
2468
        $r   = $this->pci->getExtensions($f);
2469
        $exp = array('gd',
2470
                     'SQLite',
2471
                     'xdebug');
2472
        $this->assertSame($exp, $r);
2473
    }
2474
 
2475
    /**
2476
     * Tests parsing a single file and get list of ignored functions
2477
     *
2478
     * @return void
2479
     * @covers PHP_CompatInfo::getIgnoredFunctions
2480
     * @group  getIgnoredFunctions
2481
     * @group  standard
2482
     */
2483
    public function testGetIgnoredFunctions()
2484
    {
2485
        $ds  = DIRECTORY_SEPARATOR;
2486
        $fn  = dirname(__FILE__) . $ds . 'parseFile' . $ds . 'ignore_functions_match.php';
2487
        $opt = array('ignore_functions_match' => array('preg_match', array('/^debug/')));
2488
        $this->pci->parseFile($fn, $opt);
2489
 
2490
        $r   = $this->pci->getIgnoredFunctions();
2491
        $exp = array('debug_backtrace', 'debug_print_backtrace');
2492
        $this->assertSame($exp, $r);
2493
    }
2494
 
2495
    /**
2496
     * Tests parsing a directory and get list of ignored functions
2497
     * for a specific file
2498
     *
2499
     * @return void
2500
     * @covers PHP_CompatInfo::getIgnoredFunctions
2501
     * @group  getIgnoredFunctions
2502
     * @group  standard
2503
     */
2504
    public function testGetIgnoredFunctionsByFile()
2505
    {
2506
        $resources   = array('gd', 'SQLite', 'xdebug');
2507
        $testSkipped = array();
2508
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
2509
            foreach ($testSkipped as $reason) {
2510
                $this->markTestSkipped($reason);
2511
            }
2512
        }
2513
 
2514
        $ds  = DIRECTORY_SEPARATOR;
2515
        $dir = dirname(__FILE__) . $ds . 'parseDir' . $ds;
2516
        $opt = array('ignore_functions_match' => array('preg_match', array('/debug/')));
2517
        $this->pci->parseDir($dir, $opt);
2518
 
2519
        $f   = $dir . 'extensions.php';
2520
        $r   = $this->pci->getIgnoredFunctions($f);
2521
        $exp = array('xdebug_start_trace', 'xdebug_stop_trace');
2522
        $this->assertSame($exp, $r);
2523
    }
2524
 
2525
    /**
2526
     * Tests parsing a single file and get list of ignored extensions
2527
     *
2528
     * @return void
2529
     * @covers PHP_CompatInfo::getIgnoredExtensions
2530
     * @group  getIgnoredExtensions
2531
     * @group  standard
2532
     */
2533
    public function testGetIgnoredExtensions()
2534
    {
2535
        $resources   = array('gd', 'SQLite', 'xdebug');
2536
        $testSkipped = array();
2537
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
2538
            foreach ($testSkipped as $reason) {
2539
                $this->markTestSkipped($reason);
2540
            }
2541
        }
2542
 
2543
        $ds  = DIRECTORY_SEPARATOR;
2544
        $fn  = dirname(__FILE__) . $ds . 'parseDir' . $ds . 'extensions.php';
2545
        $opt = array('ignore_extensions_match' => array('preg_match', array('/SQL/')));
2546
        $this->pci->parseFile($fn, $opt);
2547
 
2548
        $r   = $this->pci->getIgnoredExtensions();
2549
        $exp = array('SQLite');
2550
        $this->assertSame($exp, $r);
2551
    }
2552
 
2553
    /**
2554
     * Tests parsing a directory and get list of ignored extensions
2555
     * for a specific file
2556
     *
2557
     * @return void
2558
     * @covers PHP_CompatInfo::getIgnoredExtensions
2559
     * @group  getIgnoredExtensions
2560
     * @group  standard
2561
     */
2562
    public function testGetIgnoredExtensionsByFile()
2563
    {
2564
        $resources   = array('gd', 'SQLite', 'xdebug');
2565
        $testSkipped = array();
2566
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
2567
            foreach ($testSkipped as $reason) {
2568
                $this->markTestSkipped($reason);
2569
            }
2570
        }
2571
 
2572
        $ds  = DIRECTORY_SEPARATOR;
2573
        $dir = dirname(__FILE__) . $ds . 'parseDir' . $ds;
2574
        $opt = array('ignore_extensions' => array('gd'));
2575
        $this->pci->parseDir($dir, $opt);
2576
 
2577
        $f   = $dir . 'extensions.php';
2578
        $r   = $this->pci->getIgnoredExtensions($f);
2579
        $exp = array('gd');
2580
        $this->assertSame($exp, $r);
2581
    }
2582
 
2583
    /**
2584
     * Tests parsing a single file and get list of ignored constants
2585
     *
2586
     * @return void
2587
     * @covers PHP_CompatInfo::getIgnoredConstants
2588
     * @group  getIgnoredConstants
2589
     * @group  standard
2590
     */
2591
    public function testGetIgnoredConstants()
2592
    {
2593
        $resources   = array('date', 'SimpleXML');
2594
        $testSkipped = array();
2595
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
2596
            foreach ($testSkipped as $reason) {
2597
                $this->markTestSkipped($reason);
2598
            }
2599
        }
2600
 
2601
        $ds  = DIRECTORY_SEPARATOR;
2602
        $fn  = dirname(__FILE__) . $ds . 'parseFile' . $ds . 'conditional.php';
2603
        $opt = array('ignore_constants' => array('PHP_EOL', '__LINE__'));
2604
        $this->pci->parseFile($fn, $opt);
2605
 
2606
        $r   = $this->pci->getIgnoredConstants();
2607
        $exp = array('PHP_EOL');
2608
        $this->assertSame($exp, $r);
2609
    }
2610
 
2611
    /**
2612
     * Tests parsing a directory and get list of ignored constants
2613
     * for a specific file
2614
     *
2615
     * @return void
2616
     * @covers PHP_CompatInfo::getIgnoredConstants
2617
     * @group  getIgnoredConstants
2618
     * @group  standard
2619
     */
2620
    public function testGetIgnoredConstantsByFile()
2621
    {
2622
        $resources   = array('bcmath', 'date', 'pcre', 'SimpleXML');
2623
        $testSkipped = array();
2624
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
2625
            foreach ($testSkipped as $reason) {
2626
                $this->markTestSkipped($reason);
2627
            }
2628
        }
2629
 
2630
        $ds  = DIRECTORY_SEPARATOR;
2631
        $dir = dirname(__FILE__) . $ds . 'parseFile' . $ds;
2632
        $opt = array('ignore_constants' => array('PHP_EOL', '__LINE__'));
2633
        $this->pci->parseDir($dir, $opt);
2634
 
2635
        $f   = $dir . 'conditional.php';
2636
        $r   = $this->pci->getIgnoredConstants($f);
2637
        $exp = array('PHP_EOL');
2638
        $this->assertSame($exp, $r);
2639
    }
2640
 
2641
    /**
2642
     * Tests parsing multiple data sources and get only the summary result
2643
     * without the function list returns only by debug mode
2644
     *
2645
     * @return void
2646
     * @covers PHP_CompatInfo::getSummary
2647
     * @group  getSummary
2648
     * @group  standard
2649
     */
2650
    public function testGetSummaryWithoutFunctionsForArrayFile()
2651
    {
2652
        $resources   = array('date', 'pcre', 'SimpleXML');
2653
        $testSkipped = array();
2654
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
2655
            foreach ($testSkipped as $reason) {
2656
                $this->markTestSkipped($reason);
2657
            }
2658
        }
2659
 
2660
        $ds  = DIRECTORY_SEPARATOR;
2661
        $dir = dirname(__FILE__) . $ds . 'parseFile';
2662
        $fn1 = $dir . $ds . 'File_Find-1.3.0__Find.php';
2663
        $fn2 = $dir . $ds . 'conditional.php';
2664
        $opt = array('debug' => false);
2665
        $this->pci->parseData(array($fn1, $fn2), $opt);
2666
 
2667
        $r   = $this->pci->getSummary();
2668
        $exp = array('ignored_files' => array(),
2669
                     'ignored_functions' => array(),
2670
                     'ignored_extensions' => array(),
2671
                     'ignored_constants' => array(),
2672
                     'max_version' => '',
2673
                     'version' => '5.1.1',
2674
                     'classes' => array('File_Find'),
2675
                     'extensions' => array('date', 'pcre', 'SimpleXML'),
2676
                     'constants' => array('DATE_W3C',
2677
                                          'DIRECTORY_SEPARATOR',
2678
                                          'FALSE',
2679
                                          'NULL',
2680
                                          'PHP_EOL',
2681
                                          'PHP_OS',
2682
                                          'PREG_SPLIT_DELIM_CAPTURE',
2683
                                          'PREG_SPLIT_NO_EMPTY',
2684
                                          'TRUE',
2685
                                          '__FILE__'),
2686
                     'tokens' => array(),
2687
                     'cond_code' => array(5));
2688
        $this->assertSame($exp, $r);
2689
    }
2690
 
2691
    /**
2692
     * Tests parsing multiple data sources and get only the summary result
2693
     * including the function list returns by debug mode
2694
     *
2695
     * @return void
2696
     * @covers PHP_CompatInfo::getSummary
2697
     * @group  getSummary
2698
     * @group  standard
2699
     */
2700
    public function testGetSummaryWithFunctionsForArrayFile()
2701
    {
2702
        $resources   = array('date', 'pcre', 'SimpleXML');
2703
        $testSkipped = array();
2704
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
2705
            foreach ($testSkipped as $reason) {
2706
                $this->markTestSkipped($reason);
2707
            }
2708
        }
2709
 
2710
        $ds  = DIRECTORY_SEPARATOR;
2711
        $dir = dirname(__FILE__) . $ds . 'parseFile';
2712
        $fn1 = $dir . $ds . 'File_Find-1.3.0__Find.php';
2713
        $fn2 = $dir . $ds . 'conditional.php';
2714
        $opt = array('debug' => true);
2715
        $this->pci->parseData(array($fn1, $fn2), $opt);
2716
 
2717
        $r   = $this->pci->getSummary();
2718
        $exp = array('ignored_files' => array(),
2719
                     'ignored_functions' => array(),
2720
                     'ignored_extensions' => array(),
2721
                     'ignored_constants' => array(),
2722
                     'max_version' => '',
2723
                     'version' => '5.1.1',
2724
                     'classes' => array('File_Find'),
2725
                     'functions' => array('_file_find_match_shell_get_pattern',
2726
                                          'addcslashes',
2727
                                          'array_merge',
2728
                                          'array_pop',
2729
                                          'array_push',
2730
                                          'basename',
2731
                                          'closedir',
2732
                                          'count',
2733
                                          'date',
2734
                                          'debug_backtrace',
2735
                                          'define',
2736
                                          'defined',
2737
                                          'dirname',
2738
                                          'each',
2739
                                          'explode',
2740
                                          'function_exists',
2741
                                          'glob',
2742
                                          'implode',
2743
                                          'is_a',
2744
                                          'is_array',
2745
                                          'is_dir',
2746
                                          'is_readable',
2747
                                          'maptree',
2748
                                          'maptreemultiple',
2749
                                          'opendir',
2750
                                          'phpversion',
2751
                                          'preg_match',
2752
                                          'preg_replace',
2753
                                          'preg_split',
2754
                                          'print_r',
2755
                                          'readdir',
2756
                                          'reset',
2757
                                          'search',
2758
                                          'simplexml_load_file',
2759
                                          'sizeof',
2760
                                          'str_replace',
2761
                                          'strcasecmp',
2762
                                          'strlen',
2763
                                          'strpos',
2764
                                          'strtoupper',
2765
                                          'substr',
2766
                                          'substr_count',
2767
                                          'version_compare'),
2768
                     'extensions' => array('date', 'pcre', 'SimpleXML'),
2769
                     'constants' => array('DATE_W3C',
2770
                                          'DIRECTORY_SEPARATOR',
2771
                                          'FALSE',
2772
                                          'NULL',
2773
                                          'PHP_EOL',
2774
                                          'PHP_OS',
2775
                                          'PREG_SPLIT_DELIM_CAPTURE',
2776
                                          'PREG_SPLIT_NO_EMPTY',
2777
                                          'TRUE',
2778
                                          '__FILE__'),
2779
                     'tokens' => array(),
2780
                     'cond_code' => array(5,
2781
                                          array(
2782
                                            array('debug_backtrace',
2783
                                                  'simplexml_load_file'),
2784
                                            array(),
2785
                                            array('DIRECTORY_SEPARATOR',
2786
                                                  'FILE_FIND_DEBUG'),
2787
                                          ))
2788
                     );
2789
        $this->assertSame($exp, $r);
2790
    }
2791
 
2792
    /**
2793
     * Tests parsing directory and get only the summary result
2794
     * without the function list returns only by debug mode
2795
     *
2796
     * @return void
2797
     * @covers PHP_CompatInfo::getSummary
2798
     * @group  getSummary
2799
     * @group  standard
2800
     */
2801
    public function testGetSummaryForDirectory()
2802
    {
2803
        $resources   = array('gd', 'SQLite', 'xdebug');
2804
        $testSkipped = array();
2805
        if (!$this->isResourceAvailable($resources, $testSkipped)) {
2806
            foreach ($testSkipped as $reason) {
2807
                $this->markTestSkipped($reason);
2808
            }
2809
        }
2810
 
2811
        $ds  = DIRECTORY_SEPARATOR;
2812
        $dir = dirname(__FILE__) . $ds . 'parseDir' . $ds;
2813
        $opt = array('recurse_dir' => true,
2814
                     'file_ext' => array('php', 'php5'));
2815
        $this->pci->parseData($dir, $opt);
2816
 
2817
        $r   = $this->pci->getSummary();
2818
        $exp = array('ignored_files' => $this->getIgnoredFileList($dir, $opt),
2819
                     'ignored_functions' => array(),
2820
                     'ignored_extensions' => array(),
2821
                     'ignored_constants' => array(),
2822
                     'max_version' => '',
2823
                     'version' => '5.2.0',
2824
                     'classes' => array('Exception'),
2825
                     'extensions' => array('gd',
2826
                                           'SQLite',
2827
                                           'xdebug'),
2828
                     'constants' => array('PHP_SHLIB_SUFFIX',
2829
                                          'TRUE',
2830
                                          'UPLOAD_ERR_CANT_WRITE',
2831
                                          'UPLOAD_ERR_EXTENSION',
2832
                                          'UPLOAD_ERR_FORM_SIZE',
2833
                                          'UPLOAD_ERR_INI_SIZE',
2834
                                          'UPLOAD_ERR_NO_FILE',
2835
                                          'UPLOAD_ERR_NO_TMP_DIR',
2836
                                          'UPLOAD_ERR_OK',
2837
                                          'UPLOAD_ERR_PARTIAL'),
2838
                     'tokens' => array('abstract',
2839
                                       'catch',
2840
                                       'clone',
2841
                                       'final',
2842
                                       'implements',
2843
                                       'instanceof',
2844
                                       'interface',
2845
                                       'private',
2846
                                       'protected',
2847
                                       'public',
2848
                                       'throw',
2849
                                       'try'),
2850
                     'cond_code' => array(2));
2851
        $this->assertSame($exp, $r);
2852
    }
2853
}
2854
 
2855
// Call PHP_CompatInfo_TestSuite_Standard::main() if file is executed directly.
2856
if (PHPUnit_MAIN_METHOD == "PHP_CompatInfo_TestSuite_Standard::main") {
2857
    PHP_CompatInfo_TestSuite_Standard::main();
2858
}
2859
?>