Completed
Push — master ( dd5309...9fb870 )
by Siad
20:07
created

SleepTaskTest.php$0 ➔ test5()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 4
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
/**
21
 * Tests the SleepTask
22
 *
23
 * @author  Siad Ardroumli <[email protected]>
24
 * @package phing.tasks.system
25
 */
26
class SleepTaskTest extends BuildFileTest
27
{
28
    private const ERROR_RANGE = 1000000000;
29
30
    public function setUp(): void
31
    {
32
        $this->configureProject(
33
            PHING_TEST_BASE . '/etc/tasks/system/SleepTaskTest.xml'
34
        );
35
    }
36
37
    public function test1()
38
    {
39
        $timer = $this->timer();
40
        $this->executeTarget(__FUNCTION__);
41
        $timer->stop();
42
        $this->assertGreaterThanOrEqual(0, $timer->time());
43
    }
44
45
    private function timer()
46
    {
47
        return new class extends Timer
48
        {
49
            public function time()
50
            {
51
                return $this->etime - $this->stime;
52
            }
53
        };
54
    }
55
56
    public function test2()
57
    {
58
        $timer = $this->timer();
59
        $this->executeTarget(__FUNCTION__);
60
        $timer->stop();
61
        $this->assertGreaterThanOrEqual(0, $timer->time());
62
    }
63
64
    public function test3()
65
    {
66
        $timer = $this->timer();
67
        $this->executeTarget(__FUNCTION__);
68
        $timer->stop();
69
        $this->assertGreaterThanOrEqual(2000000000 - self::ERROR_RANGE, $timer->time());
70
    }
71
72
    public function test4()
73
    {
74
        $timer = $this->timer();
75
        $this->executeTarget(__FUNCTION__);
76
        $timer->stop();
77
        $this->assertTrue($timer->time() >= (2000000000 - self::ERROR_RANGE) && $timer->time() < 60000000000);
78
    }
79
80
    /**
81
     * Expected failure: negative sleep periods are not supported
82
     */
83
    public function test5()
84
    {
85
        $this->expectException(BuildException::class);
86
        $this->executeTarget(__FUNCTION__);
87
    }
88
89
    public function test6()
90
    {
91
        $timer = $this->timer();
92
        $this->executeTarget(__FUNCTION__);
93
        $timer->stop();
94
        $this->assertLessThan(2000000000, $timer->time());
95
    }
96
}
97