Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * PHPUnit
4
 *
5
 * Copyright (c) 2002-2010, Sebastian Bergmann <sb@sebastian-bergmann.de>.
6
 * All rights reserved.
7
 *
8
 * Redistribution and use in source and binary forms, with or without
9
 * modification, are permitted provided that the following conditions
10
 * are met:
11
 *
12
 *   * Redistributions of source code must retain the above copyright
13
 *     notice, this list of conditions and the following disclaimer.
14
 *
15
 *   * Redistributions in binary form must reproduce the above copyright
16
 *     notice, this list of conditions and the following disclaimer in
17
 *     the documentation and/or other materials provided with the
18
 *     distribution.
19
 *
20
 *   * Neither the name of Sebastian Bergmann nor the names of his
21
 *     contributors may be used to endorse or promote products derived
22
 *     from this software without specific prior written permission.
23
 *
24
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35
 * POSSIBILITY OF SUCH DAMAGE.
36
 *
37
 * @category   Testing
38
 * @package    PHPUnit
39
 * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
40
 * @copyright  2002-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
41
 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
42
 * @link       http://www.phpunit.de/
43
 * @since      File available since Release 3.2.0
44
 */
45
 
46
require_once 'PHPUnit/Util/Filter.php';
47
require_once 'PHPUnit/Runner/IncludePathTestCollector.php';
48
require_once 'PHPUnit/Util/XML.php';
49
 
50
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
51
 
52
/**
53
 * Wrapper for the PHPUnit XML configuration file.
54
 *
55
 * Example XML configuration file:
56
 * <code>
57
 * <?xml version="1.0" encoding="utf-8" ?>
58
 *
59
 * <phpunit backupGlobals="true"
60
 *          backupStaticAttributes="false"
61
 *          bootstrap="/path/to/bootstrap.php"
62
 *          colors="false"
63
 *          convertErrorsToExceptions="true"
64
 *          convertNoticesToExceptions="true"
65
 *          convertWarningsToExceptions="true"
66
 *          processIsolation="false"
67
 *          stopOnFailure="false"
68
 *          syntaxCheck="false"
69
 *          testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader">
70
 *   <testsuites>
71
 *     <testsuite name="My Test Suite">
72
 *       <directory suffix="Test.php">/path/to/files</directory>
73
 *       <file>/path/to/MyTest.php</file>
74
 *     </testsuite>
75
 *   </testsuites>
76
 *
77
 *   <groups>
78
 *     <include>
79
 *       <group>name</group>
80
 *     </include>
81
 *     <exclude>
82
 *       <group>name</group>
83
 *     </exclude>
84
 *   </groups>
85
 *
86
 *   <filter>
87
 *     <blacklist>
88
 *       <directory suffix=".php">/path/to/files</directory>
89
 *       <file>/path/to/file</file>
90
 *       <exclude>
91
 *         <directory suffix=".php">/path/to/files</directory>
92
 *         <file>/path/to/file</file>
93
 *       </exclude>
94
 *     </blacklist>
95
 *     <whitelist addUncoveredFilesFromWhitelist="true">
96
 *       <directory suffix=".php">/path/to/files</directory>
97
 *       <file>/path/to/file</file>
98
 *       <exclude>
99
 *         <directory suffix=".php">/path/to/files</directory>
100
 *         <file>/path/to/file</file>
101
 *       </exclude>
102
 *     </whitelist>
103
 *   </filter>
104
 *
105
 *   <listeners>
106
 *     <listener class="MyListener" file="/optional/path/to/MyListener.php">
107
 *       <arguments>
108
 *         <array>
109
 *           <element key="0">
110
 *             <string>Sebastian</string>
111
 *           </element>
112
 *         </array>
113
 *         <integer>22</integer>
114
 *         <string>April</string>
115
 *         <double>19.78</double>
116
 *         <null/>
117
 *         <object class="stdClass"/>
118
 *       </arguments>
119
 *     </listener>
120
 *   </listeners>
121
 *
122
 *   <logging>
123
 *     <log type="coverage-html" target="/tmp/report" title="My Project"
124
            charset="UTF-8" yui="true" highlight="false"
125
 *          lowUpperBound="35" highLowerBound="70"/>
126
 *     <log type="coverage-clover" target="/tmp/clover.xml"/>
127
 *     <log type="coverage-source" target="/tmp/coverage"/>
128
 *     <log type="graphviz" target="/tmp/logfile.dot"/>
129
 *     <log type="json" target="/tmp/logfile.json"/>
130
 *     <log type="metrics-xml" target="/tmp/metrics.xml"/>
131
 *     <log type="plain" target="/tmp/logfile.txt"/>
132
 *     <log type="pmd-xml" target="/tmp/pmd.xml" cpdMinLines="5" cpdMinMatches="70"/>
133
 *     <log type="tap" target="/tmp/logfile.tap"/>
134
 *     <log type="junit" target="/tmp/logfile.xml" logIncompleteSkipped="false"/>
135
 *     <log type="story-html" target="/tmp/story.html"/>
136
 *     <log type="story-text" target="/tmp/story.txt"/>
137
 *     <log type="testdox-html" target="/tmp/testdox.html"/>
138
 *     <log type="testdox-text" target="/tmp/testdox.txt"/>
139
 *
140
 *     <pmd>
141
 *       <rule class="PHPUnit_Util_Log_PMD_Rule_Project_CRAP"
142
 *             threshold="5,30" priority="1"/>
143
 *       <rule class="PHPUnit_Util_Log_PMD_Rule_Class_DepthOfInheritanceTree"
144
 *             threshold="6" priority="1"/>
145
 *       <rule class="PHPUnit_Util_Log_PMD_Rule_Class_EfferentCoupling"
146
 *             threshold="20" priority="1"/>
147
 *       <rule class="PHPUnit_Util_Log_PMD_Rule_Class_ExcessiveClassLength"
148
 *             threshold="1000" priority="1"/>
149
 *       <rule class="PHPUnit_Util_Log_PMD_Rule_Class_ExcessivePublicCount"
150
 *             threshold="45" priority="1"/>
151
 *       <rule class="PHPUnit_Util_Log_PMD_Rule_Class_TooManyFields"
152
 *             threshold="15" priority="1"/>
153
 *       <rule class="PHPUnit_Util_Log_PMD_Rule_Function_CodeCoverage"
154
 *             threshold="35,70" priority="1"/>
155
 *       <rule class="PHPUnit_Util_Log_PMD_Rule_Function_CRAP"
156
 *             threshold="30" priority="1"/>
157
 *       <rule class="PHPUnit_Util_Log_PMD_Rule_Function_CyclomaticComplexity"
158
 *             threshold="20" priority="1"/>
159
 *       <rule class="PHPUnit_Util_Log_PMD_Rule_Function_ExcessiveMethodLength"
160
 *             threshold="100" priority="1"/>
161
 *       <rule class="PHPUnit_Util_Log_PMD_Rule_Function_ExcessiveParameterList"
162
 *             threshold="10" priority="1"/>
163
 *       <rule class="PHPUnit_Util_Log_PMD_Rule_Function_NPathComplexity"
164
 *             threshold="200" priority="1"/>
165
 *     </pmd>
166
 *   </logging>
167
 *
168
 *   <php>
169
 *     <ini name="foo" value="bar"/>
170
 *     <const name="foo" value="bar"/>
171
 *     <var name="foo" value="bar"/>
172
 *   </php>
173
 *
174
 *   <selenium>
175
 *     <browser name="Firefox on Linux"
176
 *              browser="*firefox /usr/lib/firefox/firefox-bin"
177
 *              host="my.linux.box"
178
 *              port="4444"
179
 *              timeout="30000"/>
180
 *   </selenium>
181
 * </phpunit>
182
 * </code>
183
 *
184
 * @category   Testing
185
 * @package    PHPUnit
186
 * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
187
 * @copyright  2002-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
188
 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
189
 * @version    Release: 3.4.15
190
 * @link       http://www.phpunit.de/
191
 * @since      Class available since Release 3.2.0
192
 */
193
class PHPUnit_Util_Configuration
194
{
195
    private static $instances = array();
196
 
197
    protected $document;
198
    protected $xpath;
199
 
200
    /**
201
     * Loads a PHPUnit configuration file.
202
     *
203
     * @param  string $filename
204
     */
205
    protected function __construct($filename)
206
    {
207
        $this->document = PHPUnit_Util_XML::loadFile($filename);
208
        $this->xpath    = new DOMXPath($this->document);
209
    }
210
 
211
    /**
212
     * @since  Method available since Release 3.4.0
213
     */
214
    private final function __clone()
215
    {
216
    }
217
 
218
    /**
219
     * Returns a PHPUnit configuration object.
220
     *
221
     * @param  string $filename
222
     * @return PHPUnit_Util_Configuration
223
     * @since  Method available since Release 3.4.0
224
     */
225
    public static function getInstance($filename) {
226
        $realpath = realpath($filename);
227
 
228
        if ($realpath === FALSE) {
229
            throw new PHPUnit_Framework_Exception(
230
              sprintf(
231
                'Could not read "%s".',
232
                $filename
233
              )
234
            );
235
        }
236
 
237
        if (!isset(self::$instances[$realpath])) {
238
            self::$instances[$realpath] = new PHPUnit_Util_Configuration($realpath);
239
        }
240
 
241
        return self::$instances[$realpath];
242
    }
243
 
244
    /**
245
     * Returns the configuration for SUT filtering.
246
     *
247
     * @return array
248
     * @since  Method available since Release 3.2.1
249
     */
250
    public function getFilterConfiguration()
251
    {
252
        $addUncoveredFilesFromWhitelist = TRUE;
253
 
254
        $tmp = $this->xpath->query('filter/whitelist');
255
 
256
        if ($tmp->length == 1 &&
257
            $tmp->item(0)->hasAttribute('addUncoveredFilesFromWhitelist')) {
258
            $addUncoveredFilesFromWhitelist = $this->getBoolean(
259
              (string)$tmp->item(0)->getAttribute('addUncoveredFilesFromWhitelist'),
260
              TRUE
261
            );
262
        }
263
 
264
        return array(
265
          'blacklist' => array(
266
            'include' => array(
267
              'directory' => $this->readFilterDirectories(
268
                'filter/blacklist/directory'
269
              ),
270
              'file' => $this->readFilterFiles(
271
                'filter/blacklist/file'
272
              )
273
            ),
274
            'exclude' => array(
275
              'directory' => $this->readFilterDirectories(
276
                'filter/blacklist/exclude/directory'
277
               ),
278
              'file' => $this->readFilterFiles(
279
                'filter/blacklist/exclude/file'
280
              )
281
            )
282
          ),
283
          'whitelist' => array(
284
            'addUncoveredFilesFromWhitelist' => $addUncoveredFilesFromWhitelist,
285
            'include' => array(
286
              'directory' => $this->readFilterDirectories(
287
                'filter/whitelist/directory'
288
              ),
289
              'file' => $this->readFilterFiles(
290
                'filter/whitelist/file'
291
              )
292
            ),
293
            'exclude' => array(
294
              'directory' => $this->readFilterDirectories(
295
                'filter/whitelist/exclude/directory'
296
              ),
297
              'file' => $this->readFilterFiles(
298
                'filter/whitelist/exclude/file'
299
              )
300
            )
301
          )
302
        );
303
    }
304
 
305
    /**
306
     * Returns the configuration for groups.
307
     *
308
     * @return array
309
     * @since  Method available since Release 3.2.1
310
     */
311
    public function getGroupConfiguration()
312
    {
313
        $groups = array(
314
          'include' => array(),
315
          'exclude' => array()
316
        );
317
 
318
        foreach ($this->xpath->query('groups/include/group') as $group) {
319
            $groups['include'][] = (string)$group->nodeValue;
320
        }
321
 
322
        foreach ($this->xpath->query('groups/exclude/group') as $group) {
323
            $groups['exclude'][] = (string)$group->nodeValue;
324
        }
325
 
326
        return $groups;
327
    }
328
 
329
    /**
330
     * Returns the configuration for listeners.
331
     *
332
     * @return array
333
     * @since  Method available since Release 3.4.0
334
     */
335
    public function getListenerConfiguration()
336
    {
337
        $result = array();
338
 
339
        foreach ($this->xpath->query('listeners/listener') as $listener) {
340
            $class     = (string)$listener->getAttribute('class');
341
            $file      = '';
342
            $arguments = array();
343
 
344
            if ($listener->hasAttribute('file')) {
345
                $file = (string)$listener->getAttribute('file');
346
            }
347
 
348
            if ($listener->childNodes->item(1) instanceof DOMElement &&
349
                $listener->childNodes->item(1)->tagName == 'arguments') {
350
                foreach ($listener->childNodes->item(1)->childNodes as $argument) {
351
                    if ($argument instanceof DOMElement) {
352
                        $arguments[] = PHPUnit_Util_XML::xmlToVariable($argument);
353
                    }
354
                }
355
            }
356
 
357
            $result[] = array(
358
              'class'     => $class,
359
              'file'      => $file,
360
              'arguments' => $arguments
361
            );
362
        }
363
 
364
        return $result;
365
    }
366
 
367
    /**
368
     * Returns the logging configuration.
369
     *
370
     * @return array
371
     */
372
    public function getLoggingConfiguration()
373
    {
374
        $result = array();
375
 
376
        foreach ($this->xpath->query('logging/log') as $log) {
377
            $type   = (string)$log->getAttribute('type');
378
            $target = (string)$log->getAttribute('target');
379
 
380
            if ($type == 'coverage-html') {
381
                if ($log->hasAttribute('title')) {
382
                    $result['title'] = (string)$log->getAttribute('title');
383
                }
384
 
385
                if ($log->hasAttribute('charset')) {
386
                    $result['charset'] = (string)$log->getAttribute('charset');
387
                }
388
 
389
                if ($log->hasAttribute('lowUpperBound')) {
390
                    $result['lowUpperBound'] = (string)$log->getAttribute('lowUpperBound');
391
                }
392
 
393
                if ($log->hasAttribute('highLowerBound')) {
394
                    $result['highLowerBound'] = (string)$log->getAttribute('highLowerBound');
395
                }
396
 
397
                if ($log->hasAttribute('yui')) {
398
                    $result['yui'] = $this->getBoolean(
399
                      (string)$log->getAttribute('yui'),
400
                      FALSE
401
                    );
402
                }
403
 
404
                if ($log->hasAttribute('highlight')) {
405
                    $result['highlight'] = $this->getBoolean(
406
                      (string)$log->getAttribute('highlight'),
407
                      FALSE
408
                    );
409
                }
410
            }
411
 
412
            else if ($type == 'pmd-xml') {
413
                if ($log->hasAttribute('cpdMinLines')) {
414
                    $result['cpdMinLines'] = (string)$log->getAttribute('cpdMinLines');
415
                }
416
 
417
                if ($log->hasAttribute('cpdMinMatches')) {
418
                    $result['cpdMinMatches'] = (string)$log->getAttribute('cpdMinMatches');
419
                }
420
            }
421
 
422
            else if ($type == 'junit' || $type == 'test-xml') {
423
                if ($log->hasAttribute('logIncompleteSkipped')) {
424
                    $result['logIncompleteSkipped'] = $this->getBoolean(
425
                      (string)$log->getAttribute('logIncompleteSkipped'),
426
                      FALSE
427
                    );
428
                }
429
            }
430
 
431
            $result[$type] = $target;
432
        }
433
 
434
        return $result;
435
    }
436
 
437
    /**
438
     * Returns the PHP configuration.
439
     *
440
     * @return array
441
     * @since  Method available since Release 3.2.1
442
     */
443
    public function getPHPConfiguration()
444
    {
445
        $result = array(
446
          'ini'   => array(),
447
          'const' => array(),
448
          'var'   => array()
449
        );
450
 
451
        foreach ($this->xpath->query('php/ini') as $ini) {
452
            $name  = (string)$ini->getAttribute('name');
453
            $value = (string)$ini->getAttribute('value');
454
 
455
            $result['ini'][$name] = $value;
456
        }
457
 
458
        foreach ($this->xpath->query('php/const') as $const) {
459
            $name  = (string)$const->getAttribute('name');
460
            $value = (string)$const->getAttribute('value');
461
 
462
            if (strtolower($value) == 'false') {
463
                $value = FALSE;
464
            }
465
 
466
            else if (strtolower($value) == 'true') {
467
                $value = TRUE;
468
            }
469
 
470
            $result['const'][$name] = $value;
471
        }
472
 
473
        foreach ($this->xpath->query('php/var') as $var) {
474
            $name  = (string)$var->getAttribute('name');
475
            $value = (string)$var->getAttribute('value');
476
 
477
            if (strtolower($value) == 'false') {
478
                $value = FALSE;
479
            }
480
 
481
            else if (strtolower($value) == 'true') {
482
                $value = TRUE;
483
            }
484
 
485
            $result['var'][$name] = $value;
486
        }
487
 
488
        return $result;
489
    }
490
 
491
    /**
492
     * Handles the PHP configuration.
493
     *
494
     * @since  Method available since Release 3.2.20
495
     */
496
    public function handlePHPConfiguration()
497
    {
498
        $configuration = $this->getPHPConfiguration();
499
 
500
        foreach ($configuration['ini'] as $name => $value) {
501
            if (defined($value)) {
502
                $value = constant($value);
503
            }
504
 
505
            ini_set($name, $value);
506
        }
507
 
508
        foreach ($configuration['const'] as $name => $value) {
509
            if (!defined($name)) {
510
                define($name, $value);
511
            }
512
        }
513
 
514
        foreach ($configuration['var'] as $name => $value) {
515
            $GLOBALS[$name] = $value;
516
        }
517
    }
518
 
519
    /**
520
     * Returns the PHPUnit configuration.
521
     *
522
     * @return array
523
     * @since  Method available since Release 3.2.14
524
     */
525
    public function getPHPUnitConfiguration()
526
    {
527
        $result = array();
528
 
529
        if ($this->document->documentElement->hasAttribute('colors')) {
530
            $result['colors'] = $this->getBoolean(
531
              (string)$this->document->documentElement->getAttribute('colors'),
532
              FALSE
533
            );
534
        }
535
 
536
        else if ($this->document->documentElement->hasAttribute('ansi')) {
537
            $result['colors'] = $this->getBoolean(
538
              (string)$this->document->documentElement->getAttribute('ansi'),
539
              FALSE
540
            );
541
        }
542
 
543
        if ($this->document->documentElement->hasAttribute('backupGlobals')) {
544
            $result['backupGlobals'] = $this->getBoolean(
545
              (string)$this->document->documentElement->getAttribute('backupGlobals'),
546
              TRUE
547
            );
548
        }
549
 
550
        if ($this->document->documentElement->hasAttribute('backupStaticAttributes')) {
551
            $result['backupStaticAttributes'] = $this->getBoolean(
552
              (string)$this->document->documentElement->getAttribute('backupStaticAttributes'),
553
              FALSE
554
            );
555
        }
556
 
557
        if ($this->document->documentElement->hasAttribute('bootstrap')) {
558
            $result['bootstrap'] = (string)$this->document->documentElement->getAttribute('bootstrap');
559
        }
560
 
561
        if ($this->document->documentElement->hasAttribute('convertErrorsToExceptions')) {
562
            $result['convertErrorsToExceptions'] = $this->getBoolean(
563
              (string)$this->document->documentElement->getAttribute('convertErrorsToExceptions'),
564
              TRUE
565
            );
566
        }
567
 
568
        if ($this->document->documentElement->hasAttribute('convertNoticesToExceptions')) {
569
            $result['convertNoticesToExceptions'] = $this->getBoolean(
570
              (string)$this->document->documentElement->getAttribute('convertNoticesToExceptions'),
571
              TRUE
572
            );
573
        }
574
 
575
        if ($this->document->documentElement->hasAttribute('convertWarningsToExceptions')) {
576
            $result['convertWarningsToExceptions'] = $this->getBoolean(
577
              (string)$this->document->documentElement->getAttribute('convertWarningsToExceptions'),
578
              TRUE
579
            );
580
        }
581
 
582
        if ($this->document->documentElement->hasAttribute('processIsolation')) {
583
            $result['processIsolation'] = $this->getBoolean(
584
              (string)$this->document->documentElement->getAttribute('processIsolation'),
585
              FALSE
586
            );
587
        }
588
 
589
        if ($this->document->documentElement->hasAttribute('stopOnFailure')) {
590
            $result['stopOnFailure'] = $this->getBoolean(
591
              (string)$this->document->documentElement->getAttribute('stopOnFailure'),
592
              FALSE
593
            );
594
        }
595
 
596
        if ($this->document->documentElement->hasAttribute('syntaxCheck')) {
597
            $result['syntaxCheck'] = $this->getBoolean(
598
              (string)$this->document->documentElement->getAttribute('syntaxCheck'),
599
              FALSE
600
            );
601
        }
602
 
603
        if ($this->document->documentElement->hasAttribute('testSuiteLoaderClass')) {
604
            $result['testSuiteLoaderClass'] = (string)$this->document->documentElement->getAttribute('testSuiteLoaderClass');
605
        }
606
 
607
        if ($this->document->documentElement->hasAttribute('testSuiteLoaderFile')) {
608
            $result['testSuiteLoaderFile'] = (string)$this->document->documentElement->getAttribute('testSuiteLoaderFile');
609
        }
610
 
611
        return $result;
612
    }
613
 
614
    /**
615
     * Returns the configuration for PMD rules.
616
     *
617
     * @return array
618
     */
619
    public function getPMDConfiguration()
620
    {
621
        $result = array();
622
 
623
        foreach ($this->xpath->query('logging/pmd/rule') as $rule) {
624
            $class     = (string)$rule->getAttribute('class');
625
 
626
            $threshold = (string)$rule->getAttribute('threshold');
627
            $threshold = explode(',', $threshold);
628
 
629
            if (count($threshold) == 1) {
630
                $threshold = $threshold[0];
631
            }
632
 
633
            $priority = (int)$rule->getAttribute('priority');
634
 
635
            $result[$class] = array(
636
              'threshold' => $threshold,
637
              'priority'  => $priority
638
            );
639
        }
640
 
641
        return $result;
642
    }
643
 
644
    /**
645
     * Returns the SeleniumTestCase browser configuration.
646
     *
647
     * @return array
648
     * @since  Method available since Release 3.2.9
649
     */
650
    public function getSeleniumBrowserConfiguration()
651
    {
652
        $result = array();
653
 
654
        foreach ($this->xpath->query('selenium/browser') as $config) {
655
            $name    = (string)$config->getAttribute('name');
656
            $browser = (string)$config->getAttribute('browser');
657
 
658
            if ($config->hasAttribute('host')) {
659
                $host = (string)$config->getAttribute('host');
660
            } else {
661
                $host = 'localhost';
662
            }
663
 
664
            if ($config->hasAttribute('port')) {
665
                $port = (int)$config->getAttribute('port');
666
            } else {
667
                $port = 4444;
668
            }
669
 
670
            if ($config->hasAttribute('timeout')) {
671
                $timeout = (int)$config->getAttribute('timeout');
672
            } else {
673
                $timeout = 30000;
674
            }
675
 
676
            $result[] = array(
677
              'name'    => $name,
678
              'browser' => $browser,
679
              'host'    => $host,
680
              'port'    => $port,
681
              'timeout' => $timeout
682
            );
683
        }
684
 
685
        return $result;
686
    }
687
 
688
    /**
689
     * Returns the test suite configuration.
690
     *
691
     * @param  boolean $syntaxCheck
692
     * @return PHPUnit_Framework_TestSuite
693
     * @since  Method available since Release 3.2.1
694
     */
695
    public function getTestSuiteConfiguration($syntaxCheck = FALSE)
696
    {
697
        $testSuiteNodes = $this->xpath->query('testsuites/testsuite');
698
 
699
        if ($testSuiteNodes->length == 0) {
700
            $testSuiteNodes = $this->xpath->query('testsuite');
701
        }
702
 
703
        if ($testSuiteNodes->length == 1) {
704
            return $this->getTestSuite($testSuiteNodes->item(0), $syntaxCheck);
705
        }
706
 
707
        if ($testSuiteNodes->length > 1) {
708
            $suite = new PHPUnit_Framework_TestSuite;
709
 
710
            foreach ($testSuiteNodes as $testSuiteNode) {
711
                $suite->addTestSuite(
712
                  $this->getTestSuite($testSuiteNode, $syntaxCheck)
713
                );
714
            }
715
 
716
            return $suite;
717
        }
718
    }
719
 
720
    /**
721
     * @param  DOMElement $testSuiteNode
722
     * @param  boolean    $syntaxCheck
723
     * @return PHPUnit_Framework_TestSuite
724
     * @since  Method available since Release 3.4.0
725
     */
726
    protected function getTestSuite(DOMElement $testSuiteNode, $syntaxCheck)
727
    {
728
        if ($testSuiteNode->hasAttribute('name')) {
729
            $suite = new PHPUnit_Framework_TestSuite(
730
              (string)$testSuiteNode->getAttribute('name')
731
            );
732
        } else {
733
            $suite = new PHPUnit_Framework_TestSuite;
734
        }
735
 
736
        foreach ($testSuiteNode->getElementsByTagName('directory') as $directoryNode) {
737
            $directory = (string)$directoryNode->nodeValue;
738
 
739
            if (empty($directory)) {
740
                continue;
741
            }
742
 
743
            if ($directoryNode->hasAttribute('prefix')) {
744
                $prefix = (string)$directoryNode->getAttribute('prefix');
745
            } else {
746
                $prefix = '';
747
            }
748
 
749
            if ($directoryNode->hasAttribute('suffix')) {
750
                $suffix = (string)$directoryNode->getAttribute('suffix');
751
            } else {
752
                $suffix = 'Test.php';
753
            }
754
 
755
            $testCollector = new PHPUnit_Runner_IncludePathTestCollector(
756
              array($directory), $suffix, $prefix
757
            );
758
 
759
            $suite->addTestFiles($testCollector->collectTests(), $syntaxCheck);
760
        }
761
 
762
        foreach ($testSuiteNode->getElementsByTagName('file') as $fileNode) {
763
            $file = (string)$fileNode->nodeValue;
764
 
765
            if (empty($file)) {
766
                continue;
767
            }
768
 
769
            $suite->addTestFile($file, $syntaxCheck);
770
        }
771
 
772
        return $suite;
773
    }
774
 
775
    /**
776
     * @param  string  $value
777
     * @param  boolean $default
778
     * @return boolean
779
     * @since  Method available since Release 3.2.3
780
     */
781
    protected function getBoolean($value, $default)
782
    {
783
        if (strtolower($value) == 'false') {
784
            return FALSE;
785
        }
786
 
787
        else if (strtolower($value) == 'true') {
788
            return TRUE;
789
        }
790
 
791
        return $default;
792
    }
793
 
794
    /**
795
     * @param  string $query
796
     * @return array
797
     * @since  Method available since Release 3.2.3
798
     */
799
    protected function readFilterDirectories($query)
800
    {
801
        $directories = array();
802
 
803
        foreach ($this->xpath->query($query) as $directory) {
804
            if ($directory->hasAttribute('prefix')) {
805
                $prefix = (string)$directory->getAttribute('prefix');
806
            } else {
807
                $prefix = '';
808
            }
809
 
810
            if ($directory->hasAttribute('suffix')) {
811
                $suffix = (string)$directory->getAttribute('suffix');
812
            } else {
813
                $suffix = '.php';
814
            }
815
 
816
            if ($directory->hasAttribute('group')) {
817
                $group = (string)$directory->getAttribute('group');
818
            } else {
819
                $group = 'DEFAULT';
820
            }
821
 
822
            $directories[] = array(
823
              'path'   => (string)$directory->nodeValue,
824
              'prefix' => $prefix,
825
              'suffix' => $suffix,
826
              'group'  => $group
827
            );
828
        }
829
 
830
        return $directories;
831
    }
832
 
833
    /**
834
     * @param  string $query
835
     * @return array
836
     * @since  Method available since Release 3.2.3
837
     */
838
    protected function readFilterFiles($query)
839
    {
840
        $files = array();
841
 
842
        foreach ($this->xpath->query($query) as $file) {
843
            $files[] = (string)$file->nodeValue;
844
        }
845
 
846
        return $files;
847
    }
848
}
849
?>