~ballot/wordpress/openstack-objectstorage-breaking-insight

« back to all changes in this revision

Viewing changes to vendor/phpunit/php-timer/Tests/TimerTest.php

  • Committer: Jacek Nykis
  • Date: 2015-02-11 15:35:31 UTC
  • Revision ID: jacek.nykis@canonical.com-20150211153531-hmy6zi0ov2qfkl0b
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * PHP_Timer
 
4
 *
 
5
 * Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
 
6
 * All rights reserved.
 
7
 *
 
8
 * Redistribution and use in source and binary forms, with or without
 
9
 * modification, are permitted provided that the following conditions
 
10
 * are met:
 
11
 *
 
12
 *   * Redistributions of source code must retain the above copyright
 
13
 *     notice, this list of conditions and the following disclaimer.
 
14
 *
 
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
 
18
 *     distribution.
 
19
 *
 
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.
 
23
 *
 
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.
 
36
 *
 
37
 * @package    PHP
 
38
 * @subpackage Timer
 
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
 
44
 */
 
45
 
 
46
require_once dirname(dirname(__FILE__)) . '/PHP/Timer.php';
 
47
 
 
48
/**
 
49
 * Tests for PHP_Timer.
 
50
 *
 
51
 * @package    PHP
 
52
 * @subpackage 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
 
59
 */
 
60
class PHP_TimerTest extends PHPUnit_Framework_TestCase
 
61
{
 
62
    /**
 
63
     * @covers PHP_Timer::start
 
64
     * @covers PHP_Timer::stop
 
65
     */
 
66
    public function testStartStop()
 
67
    {
 
68
        $this->assertInternalType('float', PHP_Timer::stop());
 
69
    }
 
70
 
 
71
    /**
 
72
     * @covers       PHP_Timer::secondsToTimeString
 
73
     * @dataProvider secondsProvider
 
74
     */
 
75
    public function testSecondsToTimeString($string, $seconds)
 
76
    {
 
77
        $this->assertEquals(
 
78
          $string, PHP_Timer::secondsToTimeString($seconds)
 
79
        );
 
80
    }
 
81
 
 
82
    /**
 
83
     * @covers PHP_Timer::timeSinceStartOfRequest
 
84
     */
 
85
    public function testTimeSinceStartOfRequest()
 
86
    {
 
87
        $this->assertStringMatchesFormat(
 
88
          '%f %s', PHP_Timer::timeSinceStartOfRequest()
 
89
        );
 
90
    }
 
91
 
 
92
 
 
93
    /**
 
94
     * @covers PHP_Timer::resourceUsage
 
95
     */
 
96
    public function testResourceUsage()
 
97
    {
 
98
        $this->assertStringMatchesFormat(
 
99
          'Time: %s, Memory: %s', PHP_Timer::resourceUsage()
 
100
        );
 
101
    }
 
102
 
 
103
    public function secondsProvider()
 
104
    {
 
105
        return array(
 
106
          array('0 ms', 0),
 
107
          array('1 ms', .001),
 
108
          array('10 ms', .01),
 
109
          array('100 ms', .1),
 
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),
 
140
        );
 
141
    }
 
142
}