~tcuthbert/wordpress/openstack-objectstorage

« back to all changes in this revision

Viewing changes to vendor/phpunit/phpunit/src/Util/Configuration.php

  • Committer: Jacek Nykis
  • Date: 2015-02-11 15:35:31 UTC
  • Revision ID: jacek.nykis@canonical.com-20150211153531-hmy6zi0ov2qfkl0b
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/*
 
3
 * This file is part of PHPUnit.
 
4
 *
 
5
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
 
6
 *
 
7
 * For the full copyright and license information, please view the LICENSE
 
8
 * file that was distributed with this source code.
 
9
 */
 
10
 
 
11
/**
 
12
 * Wrapper for the PHPUnit XML configuration file.
 
13
 *
 
14
 * Example XML configuration file:
 
15
 * <code>
 
16
 * <?xml version="1.0" encoding="utf-8" ?>
 
17
 *
 
18
 * <phpunit backupGlobals="true"
 
19
 *          backupStaticAttributes="false"
 
20
 *          bootstrap="/path/to/bootstrap.php"
 
21
 *          cacheTokens="false"
 
22
 *          colors="false"
 
23
 *          stderr="false"
 
24
 *          convertErrorsToExceptions="true"
 
25
 *          convertNoticesToExceptions="true"
 
26
 *          convertWarningsToExceptions="true"
 
27
 *          forceCoversAnnotation="false"
 
28
 *          mapTestClassNameToCoveredClassName="false"
 
29
 *          printerClass="PHPUnit_TextUI_ResultPrinter"
 
30
 *          processIsolation="false"
 
31
 *          stopOnError="false"
 
32
 *          stopOnFailure="false"
 
33
 *          stopOnIncomplete="false"
 
34
 *          stopOnRisky="false"
 
35
 *          stopOnSkipped="false"
 
36
 *          testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader"
 
37
 *          timeoutForSmallTests="1"
 
38
 *          timeoutForMediumTests="10"
 
39
 *          timeoutForLargeTests="60"
 
40
 *          beStrictAboutTestsThatDoNotTestAnything="false"
 
41
 *          beStrictAboutOutputDuringTests="false"
 
42
 *          beStrictAboutTestSize="false"
 
43
 *          beStrictAboutTodoAnnotatedTests="false"
 
44
 *          checkForUnintentionallyCoveredCode="false"
 
45
 *          verbose="false">
 
46
 *   <testsuites>
 
47
 *     <testsuite name="My Test Suite">
 
48
 *       <directory suffix="Test.php" phpVersion="5.3.0" phpVersionOperator=">=">/path/to/files</directory>
 
49
 *       <file phpVersion="5.3.0" phpVersionOperator=">=">/path/to/MyTest.php</file>
 
50
 *       <exclude>/path/to/files/exclude</exclude>
 
51
 *     </testsuite>
 
52
 *   </testsuites>
 
53
 *
 
54
 *   <groups>
 
55
 *     <include>
 
56
 *       <group>name</group>
 
57
 *     </include>
 
58
 *     <exclude>
 
59
 *       <group>name</group>
 
60
 *     </exclude>
 
61
 *   </groups>
 
62
 *
 
63
 *   <filter>
 
64
 *     <blacklist>
 
65
 *       <directory suffix=".php">/path/to/files</directory>
 
66
 *       <file>/path/to/file</file>
 
67
 *       <exclude>
 
68
 *         <directory suffix=".php">/path/to/files</directory>
 
69
 *         <file>/path/to/file</file>
 
70
 *       </exclude>
 
71
 *     </blacklist>
 
72
 *     <whitelist addUncoveredFilesFromWhitelist="true"
 
73
 *                processUncoveredFilesFromWhitelist="false">
 
74
 *       <directory suffix=".php">/path/to/files</directory>
 
75
 *       <file>/path/to/file</file>
 
76
 *       <exclude>
 
77
 *         <directory suffix=".php">/path/to/files</directory>
 
78
 *         <file>/path/to/file</file>
 
79
 *       </exclude>
 
80
 *     </whitelist>
 
81
 *   </filter>
 
82
 *
 
83
 *   <listeners>
 
84
 *     <listener class="MyListener" file="/optional/path/to/MyListener.php">
 
85
 *       <arguments>
 
86
 *         <array>
 
87
 *           <element key="0">
 
88
 *             <string>Sebastian</string>
 
89
 *           </element>
 
90
 *         </array>
 
91
 *         <integer>22</integer>
 
92
 *         <string>April</string>
 
93
 *         <double>19.78</double>
 
94
 *         <null/>
 
95
 *         <object class="stdClass"/>
 
96
 *         <file>MyRelativeFile.php</file>
 
97
 *         <directory>MyRelativeDir</directory>
 
98
 *       </arguments>
 
99
 *     </listener>
 
100
 *   </listeners>
 
101
 *
 
102
 *   <logging>
 
103
 *     <log type="coverage-html" target="/tmp/report" lowUpperBound="50" highLowerBound="90"/>
 
104
 *     <log type="coverage-clover" target="/tmp/clover.xml"/>
 
105
 *     <log type="json" target="/tmp/logfile.json"/>
 
106
 *     <log type="plain" target="/tmp/logfile.txt"/>
 
107
 *     <log type="tap" target="/tmp/logfile.tap"/>
 
108
 *     <log type="junit" target="/tmp/logfile.xml" logIncompleteSkipped="false"/>
 
109
 *     <log type="testdox-html" target="/tmp/testdox.html"/>
 
110
 *     <log type="testdox-text" target="/tmp/testdox.txt"/>
 
111
 *     <log type="coverage-crap4j" target="/tmp/crap.xml"/>
 
112
 *   </logging>
 
113
 *
 
114
 *   <php>
 
115
 *     <includePath>.</includePath>
 
116
 *     <ini name="foo" value="bar"/>
 
117
 *     <const name="foo" value="bar"/>
 
118
 *     <var name="foo" value="bar"/>
 
119
 *     <env name="foo" value="bar"/>
 
120
 *     <post name="foo" value="bar"/>
 
121
 *     <get name="foo" value="bar"/>
 
122
 *     <cookie name="foo" value="bar"/>
 
123
 *     <server name="foo" value="bar"/>
 
124
 *     <files name="foo" value="bar"/>
 
125
 *     <request name="foo" value="bar"/>
 
126
 *   </php>
 
127
 *
 
128
 *   <selenium>
 
129
 *     <browser name="Firefox on Linux"
 
130
 *              browser="*firefox /usr/lib/firefox/firefox-bin"
 
131
 *              host="my.linux.box"
 
132
 *              port="4444"
 
133
 *              timeout="30000"/>
 
134
 *   </selenium>
 
135
 * </phpunit>
 
136
 * </code>
 
137
 *
 
138
 * @package    PHPUnit
 
139
 * @subpackage Util
 
140
 * @author     Sebastian Bergmann <sebastian@phpunit.de>
 
141
 * @copyright  Sebastian Bergmann <sebastian@phpunit.de>
 
142
 * @license    http://www.opensource.org/licenses/BSD-3-Clause  The BSD 3-Clause License
 
143
 * @link       http://www.phpunit.de/
 
144
 * @since      Class available since Release 3.2.0
 
145
 */
 
146
class PHPUnit_Util_Configuration
 
147
{
 
148
    private static $instances = array();
 
149
 
 
150
    protected $document;
 
151
    protected $xpath;
 
152
    protected $filename;
 
153
 
 
154
    /**
 
155
     * Loads a PHPUnit configuration file.
 
156
     *
 
157
     * @param string $filename
 
158
     */
 
159
    protected function __construct($filename)
 
160
    {
 
161
        $this->filename = $filename;
 
162
        $this->document = PHPUnit_Util_XML::loadFile($filename, false, true, true);
 
163
        $this->xpath    = new DOMXPath($this->document);
 
164
    }
 
165
 
 
166
    /**
 
167
     * @since  Method available since Release 3.4.0
 
168
     */
 
169
    final private function __clone()
 
170
    {
 
171
    }
 
172
 
 
173
    /**
 
174
     * Returns a PHPUnit configuration object.
 
175
     *
 
176
     * @param  string                     $filename
 
177
     * @return PHPUnit_Util_Configuration
 
178
     * @since  Method available since Release 3.4.0
 
179
     */
 
180
    public static function getInstance($filename)
 
181
    {
 
182
        $realpath = realpath($filename);
 
183
 
 
184
        if ($realpath === false) {
 
185
            throw new PHPUnit_Framework_Exception(
 
186
                sprintf(
 
187
                    'Could not read "%s".',
 
188
                    $filename
 
189
                )
 
190
            );
 
191
        }
 
192
 
 
193
        if (!isset(self::$instances[$realpath])) {
 
194
            self::$instances[$realpath] = new PHPUnit_Util_Configuration($realpath);
 
195
        }
 
196
 
 
197
        return self::$instances[$realpath];
 
198
    }
 
199
 
 
200
    /**
 
201
     * Returns the realpath to the configuration file.
 
202
     *
 
203
     * @return string
 
204
     * @since  Method available since Release 3.6.0
 
205
     */
 
206
    public function getFilename()
 
207
    {
 
208
        return $this->filename;
 
209
    }
 
210
 
 
211
    /**
 
212
     * Returns the configuration for SUT filtering.
 
213
     *
 
214
     * @return array
 
215
     * @since  Method available since Release 3.2.1
 
216
     */
 
217
    public function getFilterConfiguration()
 
218
    {
 
219
        $addUncoveredFilesFromWhitelist     = true;
 
220
        $processUncoveredFilesFromWhitelist = false;
 
221
 
 
222
        $tmp = $this->xpath->query('filter/whitelist');
 
223
 
 
224
        if ($tmp->length == 1) {
 
225
            if ($tmp->item(0)->hasAttribute('addUncoveredFilesFromWhitelist')) {
 
226
                $addUncoveredFilesFromWhitelist = $this->getBoolean(
 
227
                    (string) $tmp->item(0)->getAttribute(
 
228
                        'addUncoveredFilesFromWhitelist'
 
229
                    ),
 
230
                    true
 
231
                );
 
232
            }
 
233
 
 
234
            if ($tmp->item(0)->hasAttribute('processUncoveredFilesFromWhitelist')) {
 
235
                $processUncoveredFilesFromWhitelist = $this->getBoolean(
 
236
                    (string) $tmp->item(0)->getAttribute(
 
237
                        'processUncoveredFilesFromWhitelist'
 
238
                    ),
 
239
                    false
 
240
                );
 
241
            }
 
242
        }
 
243
 
 
244
        return array(
 
245
          'blacklist' => array(
 
246
            'include' => array(
 
247
              'directory' => $this->readFilterDirectories(
 
248
                  'filter/blacklist/directory'
 
249
              ),
 
250
              'file' => $this->readFilterFiles(
 
251
                  'filter/blacklist/file'
 
252
              )
 
253
            ),
 
254
            'exclude' => array(
 
255
              'directory' => $this->readFilterDirectories(
 
256
                  'filter/blacklist/exclude/directory'
 
257
              ),
 
258
              'file' => $this->readFilterFiles(
 
259
                  'filter/blacklist/exclude/file'
 
260
              )
 
261
            )
 
262
          ),
 
263
          'whitelist' => array(
 
264
            'addUncoveredFilesFromWhitelist' => $addUncoveredFilesFromWhitelist,
 
265
            'processUncoveredFilesFromWhitelist' => $processUncoveredFilesFromWhitelist,
 
266
            'include' => array(
 
267
              'directory' => $this->readFilterDirectories(
 
268
                  'filter/whitelist/directory'
 
269
              ),
 
270
              'file' => $this->readFilterFiles(
 
271
                  'filter/whitelist/file'
 
272
              )
 
273
            ),
 
274
            'exclude' => array(
 
275
              'directory' => $this->readFilterDirectories(
 
276
                  'filter/whitelist/exclude/directory'
 
277
              ),
 
278
              'file' => $this->readFilterFiles(
 
279
                  'filter/whitelist/exclude/file'
 
280
              )
 
281
            )
 
282
          )
 
283
        );
 
284
    }
 
285
 
 
286
    /**
 
287
     * Returns the configuration for groups.
 
288
     *
 
289
     * @return array
 
290
     * @since  Method available since Release 3.2.1
 
291
     */
 
292
    public function getGroupConfiguration()
 
293
    {
 
294
        $groups = array(
 
295
          'include' => array(),
 
296
          'exclude' => array()
 
297
        );
 
298
 
 
299
        foreach ($this->xpath->query('groups/include/group') as $group) {
 
300
            $groups['include'][] = (string) $group->nodeValue;
 
301
        }
 
302
 
 
303
        foreach ($this->xpath->query('groups/exclude/group') as $group) {
 
304
            $groups['exclude'][] = (string) $group->nodeValue;
 
305
        }
 
306
 
 
307
        return $groups;
 
308
    }
 
309
 
 
310
    /**
 
311
     * Returns the configuration for listeners.
 
312
     *
 
313
     * @return array
 
314
     * @since  Method available since Release 3.4.0
 
315
     */
 
316
    public function getListenerConfiguration()
 
317
    {
 
318
        $result = array();
 
319
 
 
320
        foreach ($this->xpath->query('listeners/listener') as $listener) {
 
321
            $class     = (string) $listener->getAttribute('class');
 
322
            $file      = '';
 
323
            $arguments = array();
 
324
 
 
325
            if ($listener->getAttribute('file')) {
 
326
                $file = $this->toAbsolutePath(
 
327
                    (string) $listener->getAttribute('file'), true
 
328
                );
 
329
            }
 
330
 
 
331
            foreach ($listener->childNodes as $node) {
 
332
                if ($node instanceof DOMElement && $node->tagName == 'arguments') {
 
333
                    foreach ($node->childNodes as $argument) {
 
334
                        if ($argument instanceof DOMElement) {
 
335
                            if ($argument->tagName == 'file' ||
 
336
                            $argument->tagName == 'directory') {
 
337
                                $arguments[] = $this->toAbsolutePath((string) $argument->nodeValue);
 
338
                            } else {
 
339
                                $arguments[] = PHPUnit_Util_XML::xmlToVariable($argument);
 
340
                            }
 
341
                        }
 
342
                    }
 
343
                }
 
344
            }
 
345
 
 
346
            $result[] = array(
 
347
              'class'     => $class,
 
348
              'file'      => $file,
 
349
              'arguments' => $arguments
 
350
            );
 
351
        }
 
352
 
 
353
        return $result;
 
354
    }
 
355
 
 
356
    /**
 
357
     * Returns the logging configuration.
 
358
     *
 
359
     * @return array
 
360
     */
 
361
    public function getLoggingConfiguration()
 
362
    {
 
363
        $result = array();
 
364
 
 
365
        foreach ($this->xpath->query('logging/log') as $log) {
 
366
            $type = (string) $log->getAttribute('type');
 
367
            $target = (string) $log->getAttribute('target');
 
368
 
 
369
            if (!$target) {
 
370
                continue;
 
371
            }
 
372
 
 
373
            $target = $this->toAbsolutePath($target);
 
374
 
 
375
            if ($type == 'coverage-html') {
 
376
                if ($log->hasAttribute('lowUpperBound')) {
 
377
                    $result['lowUpperBound'] = (string) $log->getAttribute('lowUpperBound');
 
378
                }
 
379
 
 
380
                if ($log->hasAttribute('highLowerBound')) {
 
381
                    $result['highLowerBound'] = (string) $log->getAttribute('highLowerBound');
 
382
                }
 
383
            } elseif ($type == 'junit') {
 
384
                if ($log->hasAttribute('logIncompleteSkipped')) {
 
385
                    $result['logIncompleteSkipped'] = $this->getBoolean(
 
386
                        (string) $log->getAttribute('logIncompleteSkipped'),
 
387
                        false
 
388
                    );
 
389
                }
 
390
            } elseif ($type == 'coverage-text') {
 
391
                if ($log->hasAttribute('showUncoveredFiles')) {
 
392
                    $result['coverageTextShowUncoveredFiles'] = $this->getBoolean(
 
393
                        (string) $log->getAttribute('showUncoveredFiles'),
 
394
                        false
 
395
                    );
 
396
                }
 
397
                if ($log->hasAttribute('showOnlySummary')) {
 
398
                    $result['coverageTextShowOnlySummary'] = $this->getBoolean(
 
399
                        (string) $log->getAttribute('showOnlySummary'),
 
400
                        false
 
401
                    );
 
402
                }
 
403
            }
 
404
 
 
405
            $result[$type] = $target;
 
406
        }
 
407
 
 
408
        return $result;
 
409
    }
 
410
 
 
411
    /**
 
412
     * Returns the PHP configuration.
 
413
     *
 
414
     * @return array
 
415
     * @since  Method available since Release 3.2.1
 
416
     */
 
417
    public function getPHPConfiguration()
 
418
    {
 
419
        $result = array(
 
420
          'include_path' => array(),
 
421
          'ini'          => array(),
 
422
          'const'        => array(),
 
423
          'var'          => array(),
 
424
          'env'          => array(),
 
425
          'post'         => array(),
 
426
          'get'          => array(),
 
427
          'cookie'       => array(),
 
428
          'server'       => array(),
 
429
          'files'        => array(),
 
430
          'request'      => array()
 
431
        );
 
432
 
 
433
        foreach ($this->xpath->query('php/includePath') as $includePath) {
 
434
            $path = (string) $includePath->nodeValue;
 
435
            if ($path) {
 
436
                $result['include_path'][] = $this->toAbsolutePath($path);
 
437
            }
 
438
        }
 
439
 
 
440
        foreach ($this->xpath->query('php/ini') as $ini) {
 
441
            $name  = (string) $ini->getAttribute('name');
 
442
            $value = (string) $ini->getAttribute('value');
 
443
 
 
444
            $result['ini'][$name] = $value;
 
445
        }
 
446
 
 
447
        foreach ($this->xpath->query('php/const') as $const) {
 
448
            $name  = (string) $const->getAttribute('name');
 
449
            $value = (string) $const->getAttribute('value');
 
450
 
 
451
            $result['const'][$name] = $this->getBoolean($value, $value);
 
452
        }
 
453
 
 
454
        foreach (array('var', 'env', 'post', 'get', 'cookie', 'server', 'files', 'request') as $array) {
 
455
            foreach ($this->xpath->query('php/' . $array) as $var) {
 
456
                $name  = (string) $var->getAttribute('name');
 
457
                $value = (string) $var->getAttribute('value');
 
458
 
 
459
                $result[$array][$name] = $this->getBoolean($value, $value);
 
460
            }
 
461
        }
 
462
 
 
463
        return $result;
 
464
    }
 
465
 
 
466
    /**
 
467
     * Handles the PHP configuration.
 
468
     *
 
469
     * @since  Method available since Release 3.2.20
 
470
     */
 
471
    public function handlePHPConfiguration()
 
472
    {
 
473
        $configuration = $this->getPHPConfiguration();
 
474
 
 
475
        if (! empty($configuration['include_path'])) {
 
476
            ini_set(
 
477
                'include_path',
 
478
                implode(PATH_SEPARATOR, $configuration['include_path']) .
 
479
                PATH_SEPARATOR .
 
480
                ini_get('include_path')
 
481
            );
 
482
        }
 
483
 
 
484
        foreach ($configuration['ini'] as $name => $value) {
 
485
            if (defined($value)) {
 
486
                $value = constant($value);
 
487
            }
 
488
 
 
489
            ini_set($name, $value);
 
490
        }
 
491
 
 
492
        foreach ($configuration['const'] as $name => $value) {
 
493
            if (!defined($name)) {
 
494
                define($name, $value);
 
495
            }
 
496
        }
 
497
 
 
498
        foreach (array('var', 'post', 'get', 'cookie', 'server', 'files', 'request') as $array) {
 
499
            // See https://github.com/sebastianbergmann/phpunit/issues/277
 
500
            switch ($array) {
 
501
                case 'var':
 
502
                    $target = &$GLOBALS;
 
503
                    break;
 
504
 
 
505
                case 'server':
 
506
                    $target = &$_SERVER;
 
507
                    break;
 
508
 
 
509
                default:
 
510
                    $target = &$GLOBALS['_' . strtoupper($array)];
 
511
                    break;
 
512
            }
 
513
 
 
514
            foreach ($configuration[$array] as $name => $value) {
 
515
                $target[$name] = $value;
 
516
            }
 
517
        }
 
518
 
 
519
        foreach ($configuration['env'] as $name => $value) {
 
520
            if (false === getenv($name)) {
 
521
                putenv("{$name}={$value}");
 
522
            }
 
523
            if (!isset($_ENV[$name])) {
 
524
                $_ENV[$name] = $value;
 
525
            }
 
526
        }
 
527
    }
 
528
 
 
529
    /**
 
530
     * Returns the PHPUnit configuration.
 
531
     *
 
532
     * @return array
 
533
     * @since  Method available since Release 3.2.14
 
534
     */
 
535
    public function getPHPUnitConfiguration()
 
536
    {
 
537
        $result = array();
 
538
        $root   = $this->document->documentElement;
 
539
 
 
540
        if ($root->hasAttribute('cacheTokens')) {
 
541
            $result['cacheTokens'] = $this->getBoolean(
 
542
                (string) $root->getAttribute('cacheTokens'), false
 
543
            );
 
544
        }
 
545
 
 
546
        if ($root->hasAttribute('colors')) {
 
547
            $result['colors'] = $this->getBoolean(
 
548
                (string) $root->getAttribute('colors'), false
 
549
            );
 
550
        }
 
551
 
 
552
        /**
 
553
         * Issue #657
 
554
         */
 
555
        if ($root->hasAttribute('stderr')) {
 
556
            $result['stderr'] = $this->getBoolean(
 
557
                (string)$root->getAttribute('stderr'), false
 
558
            );
 
559
        }
 
560
 
 
561
        if ($root->hasAttribute('backupGlobals')) {
 
562
            $result['backupGlobals'] = $this->getBoolean(
 
563
                (string) $root->getAttribute('backupGlobals'), true
 
564
            );
 
565
        }
 
566
 
 
567
        if ($root->hasAttribute('backupStaticAttributes')) {
 
568
            $result['backupStaticAttributes'] = $this->getBoolean(
 
569
                (string) $root->getAttribute('backupStaticAttributes'), false
 
570
            );
 
571
        }
 
572
 
 
573
        if ($root->getAttribute('bootstrap')) {
 
574
            $result['bootstrap'] = $this->toAbsolutePath(
 
575
                (string) $root->getAttribute('bootstrap')
 
576
            );
 
577
        }
 
578
 
 
579
        if ($root->hasAttribute('convertErrorsToExceptions')) {
 
580
            $result['convertErrorsToExceptions'] = $this->getBoolean(
 
581
                (string) $root->getAttribute('convertErrorsToExceptions'), true
 
582
            );
 
583
        }
 
584
 
 
585
        if ($root->hasAttribute('convertNoticesToExceptions')) {
 
586
            $result['convertNoticesToExceptions'] = $this->getBoolean(
 
587
                (string) $root->getAttribute('convertNoticesToExceptions'), true
 
588
            );
 
589
        }
 
590
 
 
591
        if ($root->hasAttribute('convertWarningsToExceptions')) {
 
592
            $result['convertWarningsToExceptions'] = $this->getBoolean(
 
593
                (string) $root->getAttribute('convertWarningsToExceptions'), true
 
594
            );
 
595
        }
 
596
 
 
597
        if ($root->hasAttribute('forceCoversAnnotation')) {
 
598
            $result['forceCoversAnnotation'] = $this->getBoolean(
 
599
                (string) $root->getAttribute('forceCoversAnnotation'), false
 
600
            );
 
601
        }
 
602
 
 
603
        if ($root->hasAttribute('mapTestClassNameToCoveredClassName')) {
 
604
            $result['mapTestClassNameToCoveredClassName'] = $this->getBoolean(
 
605
                (string) $root->getAttribute('mapTestClassNameToCoveredClassName'),
 
606
                false
 
607
            );
 
608
        }
 
609
 
 
610
        if ($root->hasAttribute('processIsolation')) {
 
611
            $result['processIsolation'] = $this->getBoolean(
 
612
                (string) $root->getAttribute('processIsolation'), false
 
613
            );
 
614
        }
 
615
 
 
616
        if ($root->hasAttribute('stopOnError')) {
 
617
            $result['stopOnError'] = $this->getBoolean(
 
618
                (string) $root->getAttribute('stopOnError'), false
 
619
            );
 
620
        }
 
621
 
 
622
        if ($root->hasAttribute('stopOnFailure')) {
 
623
            $result['stopOnFailure'] = $this->getBoolean(
 
624
                (string) $root->getAttribute('stopOnFailure'), false
 
625
            );
 
626
        }
 
627
 
 
628
        if ($root->hasAttribute('stopOnIncomplete')) {
 
629
            $result['stopOnIncomplete'] = $this->getBoolean(
 
630
                (string) $root->getAttribute('stopOnIncomplete'), false
 
631
            );
 
632
        }
 
633
 
 
634
        if ($root->hasAttribute('stopOnRisky')) {
 
635
            $result['stopOnRisky'] = $this->getBoolean(
 
636
                (string) $root->getAttribute('stopOnRisky'), false
 
637
            );
 
638
        }
 
639
 
 
640
        if ($root->hasAttribute('stopOnSkipped')) {
 
641
            $result['stopOnSkipped'] = $this->getBoolean(
 
642
                (string) $root->getAttribute('stopOnSkipped'), false
 
643
            );
 
644
        }
 
645
 
 
646
        if ($root->hasAttribute('testSuiteLoaderClass')) {
 
647
            $result['testSuiteLoaderClass'] = (string) $root->getAttribute(
 
648
                'testSuiteLoaderClass'
 
649
            );
 
650
        }
 
651
 
 
652
        if ($root->getAttribute('testSuiteLoaderFile')) {
 
653
            $result['testSuiteLoaderFile'] = $this->toAbsolutePath(
 
654
                (string) $root->getAttribute('testSuiteLoaderFile')
 
655
            );
 
656
        }
 
657
 
 
658
        if ($root->hasAttribute('printerClass')) {
 
659
            $result['printerClass'] = (string) $root->getAttribute(
 
660
                'printerClass'
 
661
            );
 
662
        }
 
663
 
 
664
        if ($root->getAttribute('printerFile')) {
 
665
            $result['printerFile'] = $this->toAbsolutePath(
 
666
                (string) $root->getAttribute('printerFile')
 
667
            );
 
668
        }
 
669
 
 
670
        if ($root->hasAttribute('timeoutForSmallTests')) {
 
671
            $result['timeoutForSmallTests'] = $this->getInteger(
 
672
                (string) $root->getAttribute('timeoutForSmallTests'), 1
 
673
            );
 
674
        }
 
675
 
 
676
        if ($root->hasAttribute('timeoutForMediumTests')) {
 
677
            $result['timeoutForMediumTests'] = $this->getInteger(
 
678
                (string) $root->getAttribute('timeoutForMediumTests'), 10
 
679
            );
 
680
        }
 
681
 
 
682
        if ($root->hasAttribute('timeoutForLargeTests')) {
 
683
            $result['timeoutForLargeTests'] = $this->getInteger(
 
684
                (string) $root->getAttribute('timeoutForLargeTests'), 60
 
685
            );
 
686
        }
 
687
 
 
688
        if ($root->hasAttribute('beStrictAboutTestsThatDoNotTestAnything')) {
 
689
            $result['reportUselessTests'] = $this->getBoolean(
 
690
                (string) $root->getAttribute('beStrictAboutTestsThatDoNotTestAnything'), false
 
691
            );
 
692
        }
 
693
 
 
694
        if ($root->hasAttribute('checkForUnintentionallyCoveredCode')) {
 
695
            $result['strictCoverage'] = $this->getBoolean(
 
696
                (string) $root->getAttribute('checkForUnintentionallyCoveredCode'), false
 
697
            );
 
698
        }
 
699
 
 
700
        if ($root->hasAttribute('beStrictAboutOutputDuringTests')) {
 
701
            $result['disallowTestOutput'] = $this->getBoolean(
 
702
                (string) $root->getAttribute('beStrictAboutOutputDuringTests'), false
 
703
            );
 
704
        }
 
705
 
 
706
        if ($root->hasAttribute('beStrictAboutTestSize')) {
 
707
            $result['enforceTimeLimit'] = $this->getBoolean(
 
708
                (string) $root->getAttribute('beStrictAboutTestSize'), false
 
709
            );
 
710
        }
 
711
 
 
712
        if ($root->hasAttribute('beStrictAboutTodoAnnotatedTests')) {
 
713
            $result['disallowTodoAnnotatedTests'] = $this->getBoolean(
 
714
                (string) $root->getAttribute('beStrictAboutTodoAnnotatedTests'), false
 
715
            );
 
716
        }
 
717
 
 
718
        if ($root->hasAttribute('strict')) {
 
719
            $flag = $this->getBoolean(
 
720
                (string) $root->getAttribute('strict'), false
 
721
            );
 
722
 
 
723
            $result['reportUselessTests']         = $flag;
 
724
            $result['strictCoverage']             = $flag;
 
725
            $result['disallowTestOutput']         = $flag;
 
726
            $result['enforceTimeLimit']           = $flag;
 
727
            $result['disallowTodoAnnotatedTests'] = $flag;
 
728
        }
 
729
 
 
730
        if ($root->hasAttribute('verbose')) {
 
731
            $result['verbose'] = $this->getBoolean(
 
732
                (string) $root->getAttribute('verbose'), false
 
733
            );
 
734
        }
 
735
 
 
736
        return $result;
 
737
    }
 
738
 
 
739
    /**
 
740
     * Returns the SeleniumTestCase browser configuration.
 
741
     *
 
742
     * @return array
 
743
     * @since  Method available since Release 3.2.9
 
744
     */
 
745
    public function getSeleniumBrowserConfiguration()
 
746
    {
 
747
        $result = array();
 
748
 
 
749
        foreach ($this->xpath->query('selenium/browser') as $config) {
 
750
            $name    = (string) $config->getAttribute('name');
 
751
            $browser = (string) $config->getAttribute('browser');
 
752
 
 
753
            if ($config->hasAttribute('host')) {
 
754
                $host = (string) $config->getAttribute('host');
 
755
            } else {
 
756
                $host = 'localhost';
 
757
            }
 
758
 
 
759
            if ($config->hasAttribute('port')) {
 
760
                $port = $this->getInteger(
 
761
                    (string) $config->getAttribute('port'), 4444
 
762
                );
 
763
            } else {
 
764
                $port = 4444;
 
765
            }
 
766
 
 
767
            if ($config->hasAttribute('timeout')) {
 
768
                $timeout = $this->getInteger(
 
769
                    (string) $config->getAttribute('timeout'), 30000
 
770
                );
 
771
            } else {
 
772
                $timeout = 30000;
 
773
            }
 
774
 
 
775
            $result[] = array(
 
776
              'name'    => $name,
 
777
              'browser' => $browser,
 
778
              'host'    => $host,
 
779
              'port'    => $port,
 
780
              'timeout' => $timeout
 
781
            );
 
782
        }
 
783
 
 
784
        return $result;
 
785
    }
 
786
 
 
787
    /**
 
788
     * Returns the test suite configuration.
 
789
     *
 
790
     * @return PHPUnit_Framework_TestSuite
 
791
     * @since  Method available since Release 3.2.1
 
792
     */
 
793
    public function getTestSuiteConfiguration($testSuiteFilter = null)
 
794
    {
 
795
        $testSuiteNodes = $this->xpath->query('testsuites/testsuite');
 
796
 
 
797
        if ($testSuiteNodes->length == 0) {
 
798
            $testSuiteNodes = $this->xpath->query('testsuite');
 
799
        }
 
800
 
 
801
        if ($testSuiteNodes->length == 1) {
 
802
            return $this->getTestSuite($testSuiteNodes->item(0), $testSuiteFilter);
 
803
        }
 
804
 
 
805
        if ($testSuiteNodes->length > 1) {
 
806
            $suite = new PHPUnit_Framework_TestSuite;
 
807
 
 
808
            foreach ($testSuiteNodes as $testSuiteNode) {
 
809
                $suite->addTestSuite(
 
810
                    $this->getTestSuite($testSuiteNode, $testSuiteFilter)
 
811
                );
 
812
            }
 
813
 
 
814
            return $suite;
 
815
        }
 
816
    }
 
817
 
 
818
    /**
 
819
     * @param  DOMElement                  $testSuiteNode
 
820
     * @return PHPUnit_Framework_TestSuite
 
821
     * @since  Method available since Release 3.4.0
 
822
     */
 
823
    protected function getTestSuite(DOMElement $testSuiteNode, $testSuiteFilter = null)
 
824
    {
 
825
        if ($testSuiteNode->hasAttribute('name')) {
 
826
            $suite = new PHPUnit_Framework_TestSuite(
 
827
                (string) $testSuiteNode->getAttribute('name')
 
828
            );
 
829
        } else {
 
830
            $suite = new PHPUnit_Framework_TestSuite;
 
831
        }
 
832
 
 
833
        $exclude = array();
 
834
 
 
835
        foreach ($testSuiteNode->getElementsByTagName('exclude') as $excludeNode) {
 
836
            $excludeFile = (string) $excludeNode->nodeValue;
 
837
            if ($excludeFile) {
 
838
                $exclude[] = $this->toAbsolutePath($excludeFile);
 
839
            }
 
840
        }
 
841
 
 
842
        $fileIteratorFacade = new File_Iterator_Facade;
 
843
 
 
844
        foreach ($testSuiteNode->getElementsByTagName('directory') as $directoryNode) {
 
845
            if ($testSuiteFilter && $directoryNode->parentNode->getAttribute('name') != $testSuiteFilter) {
 
846
                continue;
 
847
            }
 
848
 
 
849
            $directory = (string) $directoryNode->nodeValue;
 
850
 
 
851
            if (empty($directory)) {
 
852
                continue;
 
853
            }
 
854
 
 
855
            if ($directoryNode->hasAttribute('phpVersion')) {
 
856
                $phpVersion = (string) $directoryNode->getAttribute('phpVersion');
 
857
            } else {
 
858
                $phpVersion = PHP_VERSION;
 
859
            }
 
860
 
 
861
            if ($directoryNode->hasAttribute('phpVersionOperator')) {
 
862
                $phpVersionOperator = (string) $directoryNode->getAttribute('phpVersionOperator');
 
863
            } else {
 
864
                $phpVersionOperator = '>=';
 
865
            }
 
866
 
 
867
            if (!version_compare(PHP_VERSION, $phpVersion, $phpVersionOperator)) {
 
868
                continue;
 
869
            }
 
870
 
 
871
            if ($directoryNode->hasAttribute('prefix')) {
 
872
                $prefix = (string) $directoryNode->getAttribute('prefix');
 
873
            } else {
 
874
                $prefix = '';
 
875
            }
 
876
 
 
877
            if ($directoryNode->hasAttribute('suffix')) {
 
878
                $suffix = (string) $directoryNode->getAttribute('suffix');
 
879
            } else {
 
880
                $suffix = 'Test.php';
 
881
            }
 
882
 
 
883
            $files = $fileIteratorFacade->getFilesAsArray(
 
884
                $this->toAbsolutePath($directory),
 
885
                $suffix,
 
886
                $prefix,
 
887
                $exclude
 
888
            );
 
889
            $suite->addTestFiles($files);
 
890
        }
 
891
 
 
892
        foreach ($testSuiteNode->getElementsByTagName('file') as $fileNode) {
 
893
            if ($testSuiteFilter && $fileNode->parentNode->getAttribute('name') != $testSuiteFilter) {
 
894
                continue;
 
895
            }
 
896
 
 
897
            $file = (string) $fileNode->nodeValue;
 
898
 
 
899
            if (empty($file)) {
 
900
                continue;
 
901
            }
 
902
 
 
903
            // Get the absolute path to the file
 
904
            $file = $fileIteratorFacade->getFilesAsArray(
 
905
                $this->toAbsolutePath($file)
 
906
            );
 
907
 
 
908
            if (!isset($file[0])) {
 
909
                continue;
 
910
            }
 
911
 
 
912
            $file = $file[0];
 
913
 
 
914
            if ($fileNode->hasAttribute('phpVersion')) {
 
915
                $phpVersion = (string) $fileNode->getAttribute('phpVersion');
 
916
            } else {
 
917
                $phpVersion = PHP_VERSION;
 
918
            }
 
919
 
 
920
            if ($fileNode->hasAttribute('phpVersionOperator')) {
 
921
                $phpVersionOperator = (string) $fileNode->getAttribute('phpVersionOperator');
 
922
            } else {
 
923
                $phpVersionOperator = '>=';
 
924
            }
 
925
 
 
926
            if (!version_compare(PHP_VERSION, $phpVersion, $phpVersionOperator)) {
 
927
                continue;
 
928
            }
 
929
 
 
930
            $suite->addTestFile($file);
 
931
        }
 
932
 
 
933
        return $suite;
 
934
    }
 
935
 
 
936
    /**
 
937
     * @param  string  $value
 
938
     * @param  boolean $default
 
939
     * @return boolean
 
940
     * @since  Method available since Release 3.2.3
 
941
     */
 
942
    protected function getBoolean($value, $default)
 
943
    {
 
944
        if (strtolower($value) == 'false') {
 
945
            return false;
 
946
        } elseif (strtolower($value) == 'true') {
 
947
            return true;
 
948
        }
 
949
 
 
950
        return $default;
 
951
    }
 
952
 
 
953
    /**
 
954
     * @param  string  $value
 
955
     * @param  boolean $default
 
956
     * @return boolean
 
957
     * @since  Method available since Release 3.6.0
 
958
     */
 
959
    protected function getInteger($value, $default)
 
960
    {
 
961
        if (is_numeric($value)) {
 
962
            return (int) $value;
 
963
        }
 
964
 
 
965
        return $default;
 
966
    }
 
967
 
 
968
    /**
 
969
     * @param  string $query
 
970
     * @return array
 
971
     * @since  Method available since Release 3.2.3
 
972
     */
 
973
    protected function readFilterDirectories($query)
 
974
    {
 
975
        $directories = array();
 
976
 
 
977
        foreach ($this->xpath->query($query) as $directory) {
 
978
            $directoryPath = (string) $directory->nodeValue;
 
979
 
 
980
            if (!$directoryPath) {
 
981
                continue;
 
982
            }
 
983
 
 
984
            if ($directory->hasAttribute('prefix')) {
 
985
                $prefix = (string) $directory->getAttribute('prefix');
 
986
            } else {
 
987
                $prefix = '';
 
988
            }
 
989
 
 
990
            if ($directory->hasAttribute('suffix')) {
 
991
                $suffix = (string) $directory->getAttribute('suffix');
 
992
            } else {
 
993
                $suffix = '.php';
 
994
            }
 
995
 
 
996
            if ($directory->hasAttribute('group')) {
 
997
                $group = (string) $directory->getAttribute('group');
 
998
            } else {
 
999
                $group = 'DEFAULT';
 
1000
            }
 
1001
 
 
1002
            $directories[] = array(
 
1003
              'path'   => $this->toAbsolutePath($directoryPath),
 
1004
              'prefix' => $prefix,
 
1005
              'suffix' => $suffix,
 
1006
              'group'  => $group
 
1007
            );
 
1008
        }
 
1009
 
 
1010
        return $directories;
 
1011
    }
 
1012
 
 
1013
    /**
 
1014
     * @param  string $query
 
1015
     * @return array
 
1016
     * @since  Method available since Release 3.2.3
 
1017
     */
 
1018
    protected function readFilterFiles($query)
 
1019
    {
 
1020
        $files = array();
 
1021
 
 
1022
        foreach ($this->xpath->query($query) as $file) {
 
1023
            $filePath = (string) $file->nodeValue;
 
1024
            if ($filePath) {
 
1025
                $files[] = $this->toAbsolutePath($filePath);
 
1026
            }
 
1027
        }
 
1028
 
 
1029
        return $files;
 
1030
    }
 
1031
 
 
1032
    /**
 
1033
     * @param  string  $path
 
1034
     * @param  boolean $useIncludePath
 
1035
     * @return string
 
1036
     * @since  Method available since Release 3.5.0
 
1037
     */
 
1038
    protected function toAbsolutePath($path, $useIncludePath = false)
 
1039
    {
 
1040
        if ($path[0] === '/') {
 
1041
            return $path;
 
1042
        }
 
1043
 
 
1044
        // Matches the following on Windows:
 
1045
        //  - \\NetworkComputer\Path
 
1046
        //  - \\.\D:
 
1047
        //  - \\.\c:
 
1048
        //  - C:\Windows
 
1049
        //  - C:\windows
 
1050
        //  - C:/windows
 
1051
        //  - c:/windows
 
1052
        if (defined('PHP_WINDOWS_VERSION_BUILD') &&
 
1053
            ($path[0] === '\\' ||
 
1054
            (strlen($path) >= 3 && preg_match('#^[A-Z]\:[/\\\]#i', substr($path, 0, 3))))) {
 
1055
            return $path;
 
1056
        }
 
1057
 
 
1058
        // Stream
 
1059
        if (strpos($path, '://') !== false) {
 
1060
            return $path;
 
1061
        }
 
1062
 
 
1063
        $file = dirname($this->filename) . DIRECTORY_SEPARATOR . $path;
 
1064
 
 
1065
        if ($useIncludePath && !file_exists($file)) {
 
1066
            $includePathFile = stream_resolve_include_path($path);
 
1067
 
 
1068
            if ($includePathFile) {
 
1069
                $file = $includePathFile;
 
1070
            }
 
1071
        }
 
1072
 
 
1073
        return $file;
 
1074
    }
 
1075
}