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