Passed
Push — master ( 972120...1c77fc )
by Michiel
08:19
created

SleepTaskTest.php$0 ➔ timer()   A

Complexity

Conditions 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 6
rs 10
c 0
b 0
f 0

1 Method

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