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