TimerTest.php (2713B)
1 <?php 2 /* 3 * This file is part of the PHP_Timer package. 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 * Tests for PHP_Timer. 13 * 14 * @since Class available since Release 1.0.0 15 */ 16 class PHP_TimerTest extends PHPUnit_Framework_TestCase 17 { 18 /** 19 * @covers PHP_Timer::start 20 * @covers PHP_Timer::stop 21 */ 22 public function testStartStop() 23 { 24 $this->assertInternalType('float', PHP_Timer::stop()); 25 } 26 27 /** 28 * @covers PHP_Timer::secondsToTimeString 29 * @dataProvider secondsProvider 30 */ 31 public function testSecondsToTimeString($string, $seconds) 32 { 33 $this->assertEquals( 34 $string, 35 PHP_Timer::secondsToTimeString($seconds) 36 ); 37 } 38 39 /** 40 * @covers PHP_Timer::timeSinceStartOfRequest 41 */ 42 public function testTimeSinceStartOfRequest() 43 { 44 $this->assertStringMatchesFormat( 45 '%f %s', 46 PHP_Timer::timeSinceStartOfRequest() 47 ); 48 } 49 50 51 /** 52 * @covers PHP_Timer::resourceUsage 53 */ 54 public function testResourceUsage() 55 { 56 $this->assertStringMatchesFormat( 57 'Time: %s, Memory: %s', 58 PHP_Timer::resourceUsage() 59 ); 60 } 61 62 public function secondsProvider() 63 { 64 return array( 65 array('0 ms', 0), 66 array('1 ms', .001), 67 array('10 ms', .01), 68 array('100 ms', .1), 69 array('999 ms', .999), 70 array('1 second', .9999), 71 array('1 second', 1), 72 array('2 seconds', 2), 73 array('59.9 seconds', 59.9), 74 array('59.99 seconds', 59.99), 75 array('59.99 seconds', 59.999), 76 array('1 minute', 59.9999), 77 array('59 seconds', 59.001), 78 array('59.01 seconds', 59.01), 79 array('1 minute', 60), 80 array('1.01 minutes', 61), 81 array('2 minutes', 120), 82 array('2.01 minutes', 121), 83 array('59.99 minutes', 3599.9), 84 array('59.99 minutes', 3599.99), 85 array('59.99 minutes', 3599.999), 86 array('1 hour', 3599.9999), 87 array('59.98 minutes', 3599.001), 88 array('59.98 minutes', 3599.01), 89 array('1 hour', 3600), 90 array('1 hour', 3601), 91 array('1 hour', 3601.9), 92 array('1 hour', 3601.99), 93 array('1 hour', 3601.999), 94 array('1 hour', 3601.9999), 95 array('1.01 hours', 3659.9999), 96 array('1.01 hours', 3659.001), 97 array('1.01 hours', 3659.01), 98 array('2 hours', 7199.9999), 99 ); 100 } 101 }