Passed
Push — master ( 8f9505...f00c46 )
by Michiel
07:03
created

SleepTaskTest.php$0 ➔ time()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the LGPL. For more information please see
17
 * <http://phing.info>.
18
 */
19
20
use Phing\Exception\BuildException;
21
22
/**
23
 * Tests the SleepTask
24
 *
25
 * @author  Siad Ardroumli <[email protected]>
26
 * @package phing.tasks.system
27
 */
28
class SleepTaskTest extends BuildFileTest
29
{
30
    private const ERROR_RANGE = 1000000000;
31
32
    public function setUp(): void
33
    {
34
        $this->configureProject(
35
            PHING_TEST_BASE . '/etc/tasks/system/SleepTaskTest.xml'
36
        );
37
    }
38
39
    public function test1()
40
    {
41
        $timer = $this->timer();
42
        $this->executeTarget(__FUNCTION__);
43
        $timer->stop();
44
        $this->assertGreaterThanOrEqual(0, $timer->time());
45
    }
46
47
    private function timer()
48
    {
49
        return new class extends Timer
50
        {
51
            public function time()
52
            {
53
                return $this->etime - $this->stime;
54
            }
55
        };
56
    }
57
58
    public function test2()
59
    {
60
        $timer = $this->timer();
61
        $this->executeTarget(__FUNCTION__);
62
        $timer->stop();
63
        $this->assertGreaterThanOrEqual(0, $timer->time());
64
    }
65
66
    public function test3()
67
    {
68
        $timer = $this->timer();
69
        $this->executeTarget(__FUNCTION__);
70
        $timer->stop();
71
        $this->assertGreaterThanOrEqual(2000000000 - self::ERROR_RANGE, $timer->time());
72
    }
73
74
    public function test4()
75
    {
76
        $timer = $this->timer();
77
        $this->executeTarget(__FUNCTION__);
78
        $timer->stop();
79
        $this->assertTrue($timer->time() >= (2000000000 - self::ERROR_RANGE) && $timer->time() < 60000000000);
80
    }
81
82
    /**
83
     * Expected failure: negative sleep periods are not supported
84
     */
85
    public function test5()
86
    {
87
        $this->expectException(BuildException::class);
88
        $this->executeTarget(__FUNCTION__);
89
    }
90
91
    public function test6()
92
    {
93
        $timer = $this->timer();
94
        $this->executeTarget(__FUNCTION__);
95
        $timer->stop();
96
        $this->assertLessThan(2000000000, $timer->time());
97
    }
98
}
99