5
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
8
* Redistribution and use in source and binary forms, with or without
9
* modification, are permitted provided that the following conditions
12
* * Redistributions of source code must retain the above copyright
13
* notice, this list of conditions and the following disclaimer.
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
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.
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.
39
* @author Sebastian Bergmann <sebastian@phpunit.de>
40
* @copyright 2010 Sebastian Bergmann <sebastian@phpunit.de>
41
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
42
* @link http://github.com/sebastianbergmann/php-timer
43
* @since File available since Release 1.0.0
46
require_once dirname(dirname(__FILE__)) . '/PHP/Timer.php';
49
* Tests for PHP_Timer.
53
* @author Sebastian Bergmann <sebastian@phpunit.de>
54
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
55
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
56
* @version Release: @package_version@
57
* @link http://github.com/sebastianbergmann/php-timer
58
* @since Class available since Release 1.0.0
60
class PHP_TimerTest extends PHPUnit_Framework_TestCase
63
* @covers PHP_Timer::start
64
* @covers PHP_Timer::stop
66
public function testStartStop()
68
$this->assertInternalType('float', PHP_Timer::stop());
72
* @covers PHP_Timer::secondsToTimeString
73
* @dataProvider secondsProvider
75
public function testSecondsToTimeString($string, $seconds)
78
$string, PHP_Timer::secondsToTimeString($seconds)
83
* @covers PHP_Timer::timeSinceStartOfRequest
85
public function testTimeSinceStartOfRequest()
87
$this->assertStringMatchesFormat(
88
'%f %s', PHP_Timer::timeSinceStartOfRequest()
94
* @covers PHP_Timer::resourceUsage
96
public function testResourceUsage()
98
$this->assertStringMatchesFormat(
99
'Time: %s, Memory: %s', PHP_Timer::resourceUsage()
103
public function secondsProvider()
110
array('999 ms', .999),
111
array('1 second', .9999),
112
array('1 second', 1),
113
array('2 seconds', 2),
114
array('59.9 seconds', 59.9),
115
array('59.99 seconds', 59.99),
116
array('59.99 seconds', 59.999),
117
array('1 minute', 59.9999),
118
array('59 seconds', 59.001),
119
array('59.01 seconds', 59.01),
120
array('1 minute', 60),
121
array('1.01 minutes', 61),
122
array('2 minutes', 120),
123
array('2.01 minutes', 121),
124
array('59.99 minutes', 3599.9),
125
array('59.99 minutes', 3599.99),
126
array('59.99 minutes', 3599.999),
127
array('1 hour', 3599.9999),
128
array('59.98 minutes', 3599.001),
129
array('59.98 minutes', 3599.01),
130
array('1 hour', 3600),
131
array('1 hour', 3601),
132
array('1 hour', 3601.9),
133
array('1 hour', 3601.99),
134
array('1 hour', 3601.999),
135
array('1 hour', 3601.9999),
136
array('1.01 hours', 3659.9999),
137
array('1.01 hours', 3659.001),
138
array('1.01 hours', 3659.01),
139
array('2 hours', 7199.9999),