Removed modules/contrib/media module to allow update to the core media module
[yaffs-website] / vendor / phpunit / phpunit / src / Extensions / RepeatedTest.php
1 <?php
2 /*
3  * This file is part of PHPUnit.
4  *
5  * (c) Sebastian Bergmann <sebastian@phpunit.de>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * A Decorator that runs a test repeatedly.
13  *
14  * @since Class available since Release 2.0.0
15  */
16 class PHPUnit_Extensions_RepeatedTest extends PHPUnit_Extensions_TestDecorator
17 {
18     /**
19      * @var bool
20      */
21     protected $processIsolation = false;
22
23     /**
24      * @var int
25      */
26     protected $timesRepeat = 1;
27
28     /**
29      * @param PHPUnit_Framework_Test $test
30      * @param int                    $timesRepeat
31      * @param bool                   $processIsolation
32      *
33      * @throws PHPUnit_Framework_Exception
34      */
35     public function __construct(PHPUnit_Framework_Test $test, $timesRepeat = 1, $processIsolation = false)
36     {
37         parent::__construct($test);
38
39         if (is_integer($timesRepeat) &&
40             $timesRepeat >= 0) {
41             $this->timesRepeat = $timesRepeat;
42         } else {
43             throw PHPUnit_Util_InvalidArgumentHelper::factory(
44                 2,
45                 'positive integer'
46             );
47         }
48
49         $this->processIsolation = $processIsolation;
50     }
51
52     /**
53      * Counts the number of test cases that
54      * will be run by this test.
55      *
56      * @return int
57      */
58     public function count()
59     {
60         return $this->timesRepeat * count($this->test);
61     }
62
63     /**
64      * Runs the decorated test and collects the
65      * result in a TestResult.
66      *
67      * @param PHPUnit_Framework_TestResult $result
68      *
69      * @return PHPUnit_Framework_TestResult
70      *
71      * @throws PHPUnit_Framework_Exception
72      */
73     public function run(PHPUnit_Framework_TestResult $result = null)
74     {
75         if ($result === null) {
76             $result = $this->createResult();
77         }
78
79         //@codingStandardsIgnoreStart
80         for ($i = 0; $i < $this->timesRepeat && !$result->shouldStop(); $i++) {
81             //@codingStandardsIgnoreEnd
82             if ($this->test instanceof PHPUnit_Framework_TestSuite) {
83                 $this->test->setRunTestInSeparateProcess($this->processIsolation);
84             }
85             $this->test->run($result);
86         }
87
88         return $result;
89     }
90 }