improve integration tests
This commit is contained in:
72
common/components/StopWatch.php
Normal file
72
common/components/StopWatch.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace common\components;
|
||||
|
||||
|
||||
class StopWatch
|
||||
{
|
||||
|
||||
public $start;
|
||||
|
||||
public $splits = [];
|
||||
|
||||
public $stop;
|
||||
|
||||
// public function _(){
|
||||
// $this->start();
|
||||
// }
|
||||
public function __construct()
|
||||
{
|
||||
$this->start();
|
||||
}
|
||||
|
||||
|
||||
public function start()
|
||||
{
|
||||
$this->start = $this->time();
|
||||
}
|
||||
|
||||
public function split()
|
||||
{
|
||||
$this->splits[] = $this->time();
|
||||
return $this->getSplit();
|
||||
}
|
||||
|
||||
public function stop()
|
||||
{
|
||||
$this->stop = $this->time();
|
||||
}
|
||||
|
||||
function time()
|
||||
{
|
||||
return time();
|
||||
}
|
||||
|
||||
function diff($start, $end)
|
||||
{
|
||||
if (!isset($start) || !isset($end)) {
|
||||
return -1;
|
||||
}
|
||||
return $end - $start;
|
||||
}
|
||||
|
||||
function getSplit()
|
||||
{
|
||||
$lastSplit = null;
|
||||
if (isset($this->stop)) {
|
||||
$lastSplit = $this->stop;
|
||||
} else {
|
||||
$count = count($this->splits);
|
||||
if ($count > 0) {
|
||||
$lastSplit = $this->splits[$count - 1];
|
||||
}
|
||||
}
|
||||
return $this->diff($this->start, $lastSplit);
|
||||
}
|
||||
function getTotal(){
|
||||
return $this->diff($this->start, $this->stop);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user