~ubuntu-branches/ubuntu/natty/phpunit/natty

« back to all changes in this revision

Viewing changes to PHPUnit-3.4.14/PHPUnit/Framework/TestSuite.php

  • Committer: Package Import Robot
  • Author(s): Ivan Borzenkov
  • Date: 2010-12-11 18:19:39 UTC
  • mfrom: (0.11.1) (1.5.3) (12.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20101211181939-8650nbu08hf2z9v1
Tags: 3.5.5-2
fix doc-base-file-references-missing-file

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 2.0.0
44
 
 */
45
 
 
46
 
require_once 'PHPUnit/Framework.php';
47
 
 
48
 
require_once 'PHPUnit/Runner/BaseTestRunner.php';
49
 
require_once 'PHPUnit/Util/Class.php';
50
 
require_once 'PHPUnit/Util/Fileloader.php';
51
 
require_once 'PHPUnit/Util/InvalidArgumentHelper.php';
52
 
require_once 'PHPUnit/Util/Test.php';
53
 
require_once 'PHPUnit/Util/TestSuiteIterator.php';
54
 
 
55
 
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
56
 
 
57
 
/**
58
 
 * A TestSuite is a composite of Tests. It runs a collection of test cases.
59
 
 *
60
 
 * Here is an example using the dynamic test definition.
61
 
 *
62
 
 * <code>
63
 
 * <?php
64
 
 * $suite = new PHPUnit_Framework_TestSuite;
65
 
 * $suite->addTest(new MathTest('testPass'));
66
 
 * ?>
67
 
 * </code>
68
 
 *
69
 
 * Alternatively, a TestSuite can extract the tests to be run automatically.
70
 
 * To do so you pass a ReflectionClass instance for your
71
 
 * PHPUnit_Framework_TestCase class to the PHPUnit_Framework_TestSuite
72
 
 * constructor.
73
 
 *
74
 
 * <code>
75
 
 * <?php
76
 
 * $suite = new PHPUnit_Framework_TestSuite(
77
 
 *   new ReflectionClass('MathTest')
78
 
 * );
79
 
 * ?>
80
 
 * </code>
81
 
 *
82
 
 * This constructor creates a suite with all the methods starting with
83
 
 * "test" that take no arguments.
84
 
 *
85
 
 * @category   Testing
86
 
 * @package    PHPUnit
87
 
 * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
88
 
 * @copyright  2002-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
89
 
 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
90
 
 * @version    Release: 3.4.14
91
 
 * @link       http://www.phpunit.de/
92
 
 * @since      Class available since Release 2.0.0
93
 
 */
94
 
class PHPUnit_Framework_TestSuite implements PHPUnit_Framework_Test, PHPUnit_Framework_SelfDescribing, IteratorAggregate
95
 
{
96
 
    /**
97
 
     * Enable or disable the backup and restoration of the $GLOBALS array.
98
 
     *
99
 
     * @var    boolean
100
 
     */
101
 
    protected $backupGlobals = NULL;
102
 
 
103
 
    /**
104
 
     * Enable or disable the backup and restoration of static attributes.
105
 
     *
106
 
     * @var    boolean
107
 
     */
108
 
    protected $backupStaticAttributes = NULL;
109
 
 
110
 
    /**
111
 
     * Fixture that is shared between the tests of this test suite.
112
 
     *
113
 
     * @var    mixed
114
 
     */
115
 
    protected $sharedFixture;
116
 
 
117
 
    /**
118
 
     * The name of the test suite.
119
 
     *
120
 
     * @var    string
121
 
     */
122
 
    protected $name = '';
123
 
 
124
 
    /**
125
 
     * The test groups of the test suite.
126
 
     *
127
 
     * @var    array
128
 
     */
129
 
    protected $groups = array();
130
 
 
131
 
    /**
132
 
     * The tests in the test suite.
133
 
     *
134
 
     * @var    array
135
 
     */
136
 
    protected $tests = array();
137
 
 
138
 
    /**
139
 
     * The number of tests in the test suite.
140
 
     *
141
 
     * @var    integer
142
 
     */
143
 
    protected $numTests = -1;
144
 
 
145
 
    /**
146
 
     * @var boolean
147
 
     */
148
 
    protected $testCase = FALSE;
149
 
 
150
 
    /**
151
 
     * Constructs a new TestSuite:
152
 
     *
153
 
     *   - PHPUnit_Framework_TestSuite() constructs an empty TestSuite.
154
 
     *
155
 
     *   - PHPUnit_Framework_TestSuite(ReflectionClass) constructs a
156
 
     *     TestSuite from the given class.
157
 
     *
158
 
     *   - PHPUnit_Framework_TestSuite(ReflectionClass, String)
159
 
     *     constructs a TestSuite from the given class with the given
160
 
     *     name.
161
 
     *
162
 
     *   - PHPUnit_Framework_TestSuite(String) either constructs a
163
 
     *     TestSuite from the given class (if the passed string is the
164
 
     *     name of an existing class) or constructs an empty TestSuite
165
 
     *     with the given name.
166
 
     *
167
 
     * @param  mixed  $theClass
168
 
     * @param  string $name
169
 
     * @throws InvalidArgumentException
170
 
     */
171
 
    public function __construct($theClass = '', $name = '')
172
 
    {
173
 
        $argumentsValid = FALSE;
174
 
 
175
 
        if (is_object($theClass) &&
176
 
            $theClass instanceof ReflectionClass) {
177
 
            $argumentsValid = TRUE;
178
 
        }
179
 
 
180
 
        else if (is_string($theClass) && $theClass !== ''
181
 
                 && class_exists($theClass, FALSE)) {
182
 
            $argumentsValid = TRUE;
183
 
 
184
 
            if ($name == '') {
185
 
                $name = $theClass;
186
 
            }
187
 
 
188
 
            $theClass = new ReflectionClass($theClass);
189
 
        }
190
 
 
191
 
        else if (is_string($theClass)) {
192
 
            $this->setName($theClass);
193
 
            return;
194
 
        }
195
 
 
196
 
        if (!$argumentsValid) {
197
 
            throw new InvalidArgumentException;
198
 
        }
199
 
 
200
 
        $filename = $theClass->getFilename();
201
 
 
202
 
        if (strpos($filename, 'eval()') === FALSE) {
203
 
            PHPUnit_Util_Filter::addFileToFilter(realpath($filename), 'TESTS');
204
 
        }
205
 
 
206
 
        if ($name != '') {
207
 
            $this->setName($name);
208
 
        } else {
209
 
            $this->setName($theClass->getName());
210
 
        }
211
 
 
212
 
        $constructor = $theClass->getConstructor();
213
 
 
214
 
        if ($constructor !== NULL &&
215
 
            !$constructor->isPublic()) {
216
 
            $this->addTest(
217
 
              self::warning(
218
 
                sprintf(
219
 
                  'Class "%s" has no public constructor.',
220
 
 
221
 
                  $theClass->getName()
222
 
                )
223
 
              )
224
 
            );
225
 
 
226
 
            return;
227
 
        }
228
 
 
229
 
        $names = array();
230
 
 
231
 
        foreach ($theClass->getMethods() as $method) {
232
 
            if (strpos($method->getDeclaringClass()->getName(), 'PHPUnit_') !== 0) {
233
 
                $this->addTestMethod($theClass, $method, $names);
234
 
            }
235
 
        }
236
 
 
237
 
        if (empty($this->tests)) {
238
 
            $this->addTest(
239
 
              self::warning(
240
 
                sprintf(
241
 
                  'No tests found in class "%s".',
242
 
 
243
 
                  $theClass->getName()
244
 
                )
245
 
              )
246
 
            );
247
 
        }
248
 
 
249
 
        $this->testCase = TRUE;
250
 
    }
251
 
 
252
 
    /**
253
 
     * Returns a string representation of the test suite.
254
 
     *
255
 
     * @return string
256
 
     */
257
 
    public function toString()
258
 
    {
259
 
        return $this->getName();
260
 
    }
261
 
 
262
 
    /**
263
 
     * Adds a test to the suite.
264
 
     *
265
 
     * @param  PHPUnit_Framework_Test $test
266
 
     * @param  array                  $groups
267
 
     */
268
 
    public function addTest(PHPUnit_Framework_Test $test, $groups = array())
269
 
    {
270
 
        $class = new ReflectionClass($test);
271
 
 
272
 
        if (!$class->isAbstract()) {
273
 
            $this->tests[]  = $test;
274
 
            $this->numTests = -1;
275
 
 
276
 
            if ($test instanceof PHPUnit_Framework_TestSuite &&
277
 
                empty($groups)) {
278
 
                $groups = $test->getGroups();
279
 
            }
280
 
 
281
 
            if (empty($groups)) {
282
 
                $groups = array('__nogroup__');
283
 
            }
284
 
 
285
 
            foreach ($groups as $group) {
286
 
                if (!isset($this->groups[$group])) {
287
 
                    $this->groups[$group] = array($test);
288
 
                } else {
289
 
                    $this->groups[$group][] = $test;
290
 
                }
291
 
            }
292
 
        }
293
 
    }
294
 
 
295
 
    /**
296
 
     * Adds the tests from the given class to the suite.
297
 
     *
298
 
     * @param  mixed $testClass
299
 
     * @throws InvalidArgumentException
300
 
     */
301
 
    public function addTestSuite($testClass)
302
 
    {
303
 
        if (is_string($testClass) && class_exists($testClass)) {
304
 
            $testClass = new ReflectionClass($testClass);
305
 
        }
306
 
 
307
 
        if (!is_object($testClass)) {
308
 
            throw PHPUnit_Util_InvalidArgumentHelper::factory(
309
 
              1, 'class name or object'
310
 
            );
311
 
        }
312
 
 
313
 
        if ($testClass instanceof PHPUnit_Framework_TestSuite) {
314
 
            $this->addTest($testClass);
315
 
        }
316
 
 
317
 
        else if ($testClass instanceof ReflectionClass) {
318
 
            $suiteMethod = FALSE;
319
 
 
320
 
            if (!$testClass->isAbstract()) {
321
 
                if ($testClass->hasMethod(PHPUnit_Runner_BaseTestRunner::SUITE_METHODNAME)) {
322
 
                    $method = $testClass->getMethod(
323
 
                      PHPUnit_Runner_BaseTestRunner::SUITE_METHODNAME
324
 
                    );
325
 
 
326
 
                    if ($method->isStatic()) {
327
 
                        $this->addTest(
328
 
                          $method->invoke(NULL, $testClass->getName())
329
 
                        );
330
 
 
331
 
                        $suiteMethod = TRUE;
332
 
                    }
333
 
                }
334
 
            }
335
 
 
336
 
            if (!$suiteMethod && !$testClass->isAbstract()) {
337
 
                $this->addTest(new PHPUnit_Framework_TestSuite($testClass));
338
 
            }
339
 
        }
340
 
 
341
 
        else {
342
 
            throw new InvalidArgumentException;
343
 
        }
344
 
    }
345
 
 
346
 
    /**
347
 
     * Wraps both <code>addTest()</code> and <code>addTestSuite</code>
348
 
     * as well as the separate import statements for the user's convenience.
349
 
     *
350
 
     * If the named file cannot be read or there are no new tests that can be
351
 
     * added, a <code>PHPUnit_Framework_Warning</code> will be created instead,
352
 
     * leaving the current test run untouched.
353
 
     *
354
 
     * @param  string  $filename
355
 
     * @param  boolean $syntaxCheck
356
 
     * @param  array   $phptOptions Array with ini settings for the php instance
357
 
     *                              run, key being the name if the setting,
358
 
     *                              value the ini value.
359
 
     * @throws InvalidArgumentException
360
 
     * @since  Method available since Release 2.3.0
361
 
     * @author Stefano F. Rausch <stefano@rausch-e.net>
362
 
     */
363
 
    public function addTestFile($filename, $syntaxCheck = FALSE, $phptOptions = array())
364
 
    {
365
 
        if (!is_string($filename)) {
366
 
            throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
367
 
        }
368
 
 
369
 
        if (file_exists($filename) && substr($filename, -5) == '.phpt') {
370
 
            require_once 'PHPUnit/Extensions/PhptTestCase.php';
371
 
 
372
 
            $this->addTest(
373
 
              new PHPUnit_Extensions_PhptTestCase($filename, $phptOptions)
374
 
            );
375
 
 
376
 
            return;
377
 
        }
378
 
 
379
 
        if (!file_exists($filename)) {
380
 
            $includePaths = explode(PATH_SEPARATOR, get_include_path());
381
 
 
382
 
            foreach ($includePaths as $includePath) {
383
 
                $file = $includePath . DIRECTORY_SEPARATOR . $filename;
384
 
 
385
 
                if (file_exists($file)) {
386
 
                    $filename = $file;
387
 
                    break;
388
 
                }
389
 
            }
390
 
        }
391
 
 
392
 
        PHPUnit_Util_Class::collectStart();
393
 
        PHPUnit_Util_Fileloader::checkAndLoad($filename, $syntaxCheck);
394
 
        $newClasses = PHPUnit_Util_Class::collectEnd();
395
 
        $baseName   = str_replace('.php', '', basename($filename));
396
 
 
397
 
        foreach ($newClasses as $className) {
398
 
            if (substr($className, 0 - strlen($baseName)) == $baseName) {
399
 
                $newClasses = array($className);
400
 
                break;
401
 
            }
402
 
        }
403
 
 
404
 
        $testsFound = FALSE;
405
 
 
406
 
        foreach ($newClasses as $className) {
407
 
            $class = new ReflectionClass($className);
408
 
 
409
 
            if (!$class->isAbstract()) {
410
 
                if ($class->hasMethod(PHPUnit_Runner_BaseTestRunner::SUITE_METHODNAME)) {
411
 
                    $method = $class->getMethod(
412
 
                      PHPUnit_Runner_BaseTestRunner::SUITE_METHODNAME
413
 
                    );
414
 
 
415
 
                    if ($method->isStatic()) {
416
 
                        $this->addTest($method->invoke(NULL, $className));
417
 
 
418
 
                        $testsFound = TRUE;
419
 
                    }
420
 
                }
421
 
 
422
 
                else if ($class->implementsInterface('PHPUnit_Framework_Test')) {
423
 
                    $this->addTestSuite($class);
424
 
 
425
 
                    $testsFound = TRUE;
426
 
                }
427
 
            }
428
 
        }
429
 
 
430
 
        $this->numTests = -1;
431
 
    }
432
 
 
433
 
    /**
434
 
     * Wrapper for addTestFile() that adds multiple test files.
435
 
     *
436
 
     * @param  array|Iterator $filenames
437
 
     * @throws InvalidArgumentException
438
 
     * @since  Method available since Release 2.3.0
439
 
     */
440
 
    public function addTestFiles($filenames, $syntaxCheck = FALSE)
441
 
    {
442
 
        if (!(is_array($filenames) ||
443
 
             (is_object($filenames) && $filenames instanceof Iterator))) {
444
 
            throw PHPUnit_Util_InvalidArgumentHelper::factory(
445
 
              1, 'array or iterator'
446
 
            );
447
 
        }
448
 
 
449
 
        foreach ($filenames as $filename) {
450
 
            $this->addTestFile((string)$filename, $syntaxCheck);
451
 
        }
452
 
    }
453
 
 
454
 
    /**
455
 
     * Counts the number of test cases that will be run by this test.
456
 
     *
457
 
     * @return integer
458
 
     */
459
 
    public function count()
460
 
    {
461
 
        if ($this->numTests > -1) {
462
 
            return $this->numTests;
463
 
        }
464
 
 
465
 
        $this->numTests = 0;
466
 
 
467
 
        foreach ($this->tests as $test) {
468
 
            $this->numTests += count($test);
469
 
        }
470
 
 
471
 
        return $this->numTests;
472
 
    }
473
 
 
474
 
    /**
475
 
     * @param  ReflectionClass $theClass
476
 
     * @param  string          $name
477
 
     * @param  array           $classGroups
478
 
     * @return PHPUnit_Framework_Test
479
 
     */
480
 
    public static function createTest(ReflectionClass $theClass, $name, array $classGroups = array())
481
 
    {
482
 
        $className = $theClass->getName();
483
 
 
484
 
        if (!$theClass->isInstantiable()) {
485
 
            return self::warning(
486
 
              sprintf('Cannot instantiate class "%s".', $className)
487
 
            );
488
 
        }
489
 
 
490
 
        $classDocComment          = $theClass->getDocComment();
491
 
        $method                   = new ReflectionMethod($className, $name);
492
 
        $methodDocComment         = $method->getDocComment();
493
 
        $backupSettings           = PHPUnit_Util_Test::getBackupSettings(
494
 
                                      $className, $name
495
 
                                    );
496
 
        $preserveGlobalState      = PHPUnit_Util_Test::getPreserveGlobalStateSettings(
497
 
                                      $className, $name
498
 
                                    );
499
 
        $runTestInSeparateProcess = PHPUnit_Util_Test::getProcessIsolationSettings(
500
 
                                      $className, $name
501
 
                                    );
502
 
 
503
 
        $constructor = $theClass->getConstructor();
504
 
 
505
 
        if ($constructor !== NULL) {
506
 
            $parameters = $constructor->getParameters();
507
 
 
508
 
            // TestCase() or TestCase($name)
509
 
            if (count($parameters) < 2) {
510
 
                $test = new $className;
511
 
            }
512
 
 
513
 
            // TestCase($name, $data)
514
 
            else {
515
 
                try {
516
 
                    $data = PHPUnit_Util_Test::getProvidedData(
517
 
                      $className, $name
518
 
                    );
519
 
                }
520
 
 
521
 
                catch (Exception $e) {
522
 
                    $message = sprintf(
523
 
                      'The data provider specified for %s::%s is invalid.',
524
 
                      $className,
525
 
                      $name
526
 
                    );
527
 
 
528
 
                    $_message = $e->getMessage();
529
 
 
530
 
                    if (!empty($_message)) {
531
 
                        $message .= "\n" . $_message;
532
 
                    }
533
 
 
534
 
                    return new PHPUnit_Framework_Warning($message);
535
 
                }
536
 
 
537
 
                $groups = PHPUnit_Util_Test::getGroups($className, $name);
538
 
 
539
 
                // Test method with @dataProvider.
540
 
                if (isset($data)) {
541
 
                    $test = new PHPUnit_Framework_TestSuite_DataProvider(
542
 
                      $className . '::' . $name
543
 
                    );
544
 
 
545
 
                    foreach ($data as $_dataName => $_data) {
546
 
                        $_test = new $className($name, $_data, $_dataName);
547
 
 
548
 
                        if ($runTestInSeparateProcess) {
549
 
                            $_test->setRunTestInSeparateProcess(TRUE);
550
 
 
551
 
                            if ($preserveGlobalState !== NULL) {
552
 
                                $_test->setPreserveGlobalState($preserveGlobalState);
553
 
                            }
554
 
                        }
555
 
 
556
 
                        if ($backupSettings['backupGlobals'] !== NULL) {
557
 
                            $_test->setBackupGlobals(
558
 
                              $backupSettings['backupGlobals']
559
 
                            );
560
 
                        }
561
 
 
562
 
                        if ($backupSettings['backupStaticAttributes'] !== NULL) {
563
 
                            $_test->setBackupStaticAttributes(
564
 
                              $backupSettings['backupStaticAttributes']
565
 
                            );
566
 
                        }
567
 
 
568
 
                        $test->addTest($_test, $groups);
569
 
                    }
570
 
                }
571
 
 
572
 
                else {
573
 
                    $test = new $className;
574
 
                }
575
 
            }
576
 
        }
577
 
 
578
 
        if ($test instanceof PHPUnit_Framework_TestCase) {
579
 
            $test->setName($name);
580
 
 
581
 
            if ($runTestInSeparateProcess) {
582
 
                $test->setRunTestInSeparateProcess(TRUE);
583
 
 
584
 
                if ($preserveGlobalState !== NULL) {
585
 
                    $test->setPreserveGlobalState($preserveGlobalState);
586
 
                }
587
 
            }
588
 
 
589
 
            if ($backupSettings['backupGlobals'] !== NULL) {
590
 
                $test->setBackupGlobals($backupSettings['backupGlobals']);
591
 
            }
592
 
 
593
 
            if ($backupSettings['backupStaticAttributes'] !== NULL) {
594
 
                $test->setBackupStaticAttributes(
595
 
                  $backupSettings['backupStaticAttributes']
596
 
                );
597
 
            }
598
 
        }
599
 
 
600
 
        return $test;
601
 
    }
602
 
 
603
 
    /**
604
 
     * Creates a default TestResult object.
605
 
     *
606
 
     * @return PHPUnit_Framework_TestResult
607
 
     */
608
 
    protected function createResult()
609
 
    {
610
 
        return new PHPUnit_Framework_TestResult;
611
 
    }
612
 
 
613
 
    /**
614
 
     * Returns the name of the suite.
615
 
     *
616
 
     * @return string
617
 
     */
618
 
    public function getName()
619
 
    {
620
 
        return $this->name;
621
 
    }
622
 
 
623
 
    /**
624
 
     * Returns the test groups of the suite.
625
 
     *
626
 
     * @return array
627
 
     * @since  Method available since Release 3.2.0
628
 
     */
629
 
    public function getGroups()
630
 
    {
631
 
        return array_keys($this->groups);
632
 
    }
633
 
 
634
 
    /**
635
 
     * Runs the tests and collects their result in a TestResult.
636
 
     *
637
 
     * @param  PHPUnit_Framework_TestResult $result
638
 
     * @param  mixed                        $filter
639
 
     * @param  array                        $groups
640
 
     * @param  array                        $excludeGroups
641
 
     * @param  boolean                      $processIsolation
642
 
     * @return PHPUnit_Framework_TestResult
643
 
     * @throws InvalidArgumentException
644
 
     */
645
 
    public function run(PHPUnit_Framework_TestResult $result = NULL, $filter = FALSE, array $groups = array(), array $excludeGroups = array(), $processIsolation = FALSE)
646
 
    {
647
 
        if ($result === NULL) {
648
 
            $result = $this->createResult();
649
 
        }
650
 
 
651
 
        $result->startTestSuite($this);
652
 
 
653
 
        try {
654
 
            $this->setUp();
655
 
 
656
 
            if ($this->testCase &&
657
 
                method_exists($this->name, 'setUpBeforeClass')) {
658
 
                call_user_func(array($this->name, 'setUpBeforeClass'));
659
 
            }
660
 
        }
661
 
 
662
 
        catch (PHPUnit_Framework_SkippedTestSuiteError $e) {
663
 
            $numTests = count($this);
664
 
 
665
 
            for ($i = 0; $i < $numTests; $i++) {
666
 
                $result->addFailure($this, $e, 0);
667
 
            }
668
 
 
669
 
            return $result;
670
 
        }
671
 
 
672
 
        if (empty($groups)) {
673
 
            $tests = $this->tests;
674
 
        } else {
675
 
            $tests = new SplObjectStorage;
676
 
 
677
 
            foreach ($groups as $group) {
678
 
                if (isset($this->groups[$group])) {
679
 
                    foreach ($this->groups[$group] as $test) {
680
 
                        $tests->attach($test);
681
 
                    }
682
 
                }
683
 
            }
684
 
        }
685
 
 
686
 
        foreach ($tests as $test) {
687
 
            if ($result->shouldStop()) {
688
 
                break;
689
 
            }
690
 
 
691
 
            if ($test instanceof PHPUnit_Framework_TestSuite) {
692
 
                $test->setBackupGlobals($this->backupGlobals);
693
 
                $test->setBackupStaticAttributes($this->backupStaticAttributes);
694
 
                $test->setSharedFixture($this->sharedFixture);
695
 
 
696
 
                $test->run(
697
 
                  $result, $filter, $groups, $excludeGroups, $processIsolation
698
 
                );
699
 
            } else {
700
 
                $runTest = TRUE;
701
 
 
702
 
                if ($filter !== FALSE ) {
703
 
                    $tmp = PHPUnit_Util_Test::describe($test, FALSE);
704
 
 
705
 
                    if ($tmp[0] != '') {
706
 
                        $name = join('::', $tmp);
707
 
                    } else {
708
 
                        $name = $tmp[1];
709
 
                    }
710
 
 
711
 
                    if (preg_match($filter, $name) == 0) {
712
 
                        $runTest = FALSE;
713
 
                    }
714
 
                }
715
 
 
716
 
                if ($runTest && !empty($excludeGroups)) {
717
 
                    foreach ($this->groups as $_group => $_tests) {
718
 
                        if (in_array($_group, $excludeGroups)) {
719
 
                            foreach ($_tests as $_test) {
720
 
                                if ($test === $_test) {
721
 
                                    $runTest = FALSE;
722
 
                                    break 2;
723
 
                                }
724
 
                            }
725
 
                        }
726
 
                    }
727
 
                }
728
 
 
729
 
                if ($runTest) {
730
 
                    if ($test instanceof PHPUnit_Framework_TestCase) {
731
 
                        $test->setBackupGlobals($this->backupGlobals);
732
 
                        $test->setBackupStaticAttributes(
733
 
                          $this->backupStaticAttributes
734
 
                        );
735
 
                        $test->setSharedFixture($this->sharedFixture);
736
 
                        $test->setRunTestInSeparateProcess($processIsolation);
737
 
                    }
738
 
 
739
 
                    $this->runTest($test, $result);
740
 
                }
741
 
            }
742
 
        }
743
 
 
744
 
        if ($this->testCase &&
745
 
            method_exists($this->name, 'tearDownAfterClass')) {
746
 
            call_user_func(array($this->name, 'tearDownAfterClass'));
747
 
        }
748
 
 
749
 
        $this->tearDown();
750
 
        $result->endTestSuite($this);
751
 
 
752
 
        return $result;
753
 
    }
754
 
 
755
 
    /**
756
 
     * Runs a test.
757
 
     *
758
 
     * @param  PHPUnit_Framework_Test        $test
759
 
     * @param  PHPUnit_Framework_TestResult  $testResult
760
 
     */
761
 
    public function runTest(PHPUnit_Framework_Test $test, PHPUnit_Framework_TestResult $result)
762
 
    {
763
 
        $test->run($result);
764
 
    }
765
 
 
766
 
    /**
767
 
     * Sets the name of the suite.
768
 
     *
769
 
     * @param  string
770
 
     */
771
 
    public function setName($name)
772
 
    {
773
 
        $this->name = $name;
774
 
    }
775
 
 
776
 
    /**
777
 
     * Returns the test at the given index.
778
 
     *
779
 
     * @param  integer
780
 
     * @return PHPUnit_Framework_Test
781
 
     */
782
 
    public function testAt($index)
783
 
    {
784
 
        if (isset($this->tests[$index])) {
785
 
            return $this->tests[$index];
786
 
        } else {
787
 
            return FALSE;
788
 
        }
789
 
    }
790
 
 
791
 
    /**
792
 
     * Returns the tests as an enumeration.
793
 
     *
794
 
     * @return array
795
 
     */
796
 
    public function tests()
797
 
    {
798
 
        return $this->tests;
799
 
    }
800
 
 
801
 
    /**
802
 
     * Mark the test suite as skipped.
803
 
     *
804
 
     * @param  string  $message
805
 
     * @throws PHPUnit_Framework_SkippedTestSuiteError
806
 
     * @since  Method available since Release 3.0.0
807
 
     */
808
 
    public function markTestSuiteSkipped($message = '')
809
 
    {
810
 
        throw new PHPUnit_Framework_SkippedTestSuiteError($message);
811
 
    }
812
 
 
813
 
    /**
814
 
     * @param  ReflectionClass  $class
815
 
     * @param  ReflectionMethod $method
816
 
     * @param  array            $names
817
 
     */
818
 
    protected function addTestMethod(ReflectionClass $class, ReflectionMethod $method, array &$names)
819
 
    {
820
 
        $name = $method->getName();
821
 
 
822
 
        if (in_array($name, $names)) {
823
 
            return;
824
 
        }
825
 
 
826
 
        if ($this->isPublicTestMethod($method)) {
827
 
            $names[] = $name;
828
 
 
829
 
            $test = self::createTest($class, $name);
830
 
 
831
 
            if ($test instanceof PHPUnit_Framework_TestCase ||
832
 
                $test instanceof PHPUnit_Framework_TestSuite_DataProvider) {
833
 
                $test->setDependencies(
834
 
                  PHPUnit_Util_Test::getDependencies($class->getName(), $name)
835
 
                );
836
 
            }
837
 
 
838
 
            $this->addTest($test, PHPUnit_Util_Test::getGroups(
839
 
              $class->getName(), $name)
840
 
            );
841
 
        }
842
 
 
843
 
        else if ($this->isTestMethod($method)) {
844
 
            $this->addTest(
845
 
              self::warning(
846
 
                sprintf(
847
 
                  'Test method "%s" is not public.',
848
 
 
849
 
                  $name
850
 
                )
851
 
              )
852
 
            );
853
 
        }
854
 
    }
855
 
 
856
 
    /**
857
 
     * @param  ReflectionMethod $method
858
 
     * @return boolean
859
 
     */
860
 
    public static function isPublicTestMethod(ReflectionMethod $method)
861
 
    {
862
 
        return (self::isTestMethod($method) && $method->isPublic());
863
 
    }
864
 
 
865
 
    /**
866
 
     * @param  ReflectionMethod $method
867
 
     * @return boolean
868
 
     */
869
 
    public static function isTestMethod(ReflectionMethod $method)
870
 
    {
871
 
        if (strpos($method->name, 'test') === 0) {
872
 
            return TRUE;
873
 
        }
874
 
 
875
 
        // @scenario on TestCase::testMethod()
876
 
        // @test     on TestCase::testMethod()
877
 
        return strpos($method->getDocComment(), '@test')     !== FALSE ||
878
 
               strpos($method->getDocComment(), '@scenario') !== FALSE;
879
 
    }
880
 
 
881
 
    /**
882
 
     * @param  string  $message
883
 
     * @return PHPUnit_Framework_Warning
884
 
     */
885
 
    protected static function warning($message)
886
 
    {
887
 
        return new PHPUnit_Framework_Warning($message);
888
 
    }
889
 
 
890
 
    /**
891
 
     * @param  boolean $backupGlobals
892
 
     * @since  Method available since Release 3.3.0
893
 
     */
894
 
    public function setBackupGlobals($backupGlobals)
895
 
    {
896
 
        if (is_null($this->backupGlobals) && is_bool($backupGlobals)) {
897
 
            $this->backupGlobals = $backupGlobals;
898
 
        }
899
 
    }
900
 
 
901
 
    /**
902
 
     * @param  boolean $backupStaticAttributes
903
 
     * @since  Method available since Release 3.4.0
904
 
     */
905
 
    public function setBackupStaticAttributes($backupStaticAttributes)
906
 
    {
907
 
        if (is_null($this->backupStaticAttributes) &&
908
 
            is_bool($backupStaticAttributes)) {
909
 
            $this->backupStaticAttributes = $backupStaticAttributes;
910
 
        }
911
 
    }
912
 
 
913
 
    /**
914
 
     * Sets the shared fixture for the tests of this test suite.
915
 
     *
916
 
     * @param  mixed $sharedFixture
917
 
     * @since  Method available since Release 3.1.0
918
 
     */
919
 
    public function setSharedFixture($sharedFixture)
920
 
    {
921
 
        $this->sharedFixture = $sharedFixture;
922
 
    }
923
 
 
924
 
    /**
925
 
     * Returns an iterator for this test suite.
926
 
     *
927
 
     * @return RecursiveIteratorIterator
928
 
     * @since  Method available since Release 3.1.0
929
 
     */
930
 
    public function getIterator()
931
 
    {
932
 
        return new RecursiveIteratorIterator(
933
 
          new PHPUnit_Util_TestSuiteIterator($this)
934
 
        );
935
 
    }
936
 
 
937
 
    /**
938
 
     * Template Method that is called before the tests
939
 
     * of this test suite are run.
940
 
     *
941
 
     * @since  Method available since Release 3.1.0
942
 
     */
943
 
    protected function setUp()
944
 
    {
945
 
    }
946
 
 
947
 
    /**
948
 
     * Template Method that is called after the tests
949
 
     * of this test suite have finished running.
950
 
     *
951
 
     * @since  Method available since Release 3.1.0
952
 
     */
953
 
    protected function tearDown()
954
 
    {
955
 
    }
956
 
}
957
 
?>
 
 
b'\\ No newline at end of file'