Finished up Profiler and test coverage
This commit is contained in:
parent
9e65b2cfc2
commit
173136ddce
2 changed files with 57 additions and 81 deletions
|
@ -2,60 +2,62 @@
|
|||
|
||||
class ProfilerTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testReport()
|
||||
public function testProfiler()
|
||||
{
|
||||
$this->expectOutputRegex('//');
|
||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||
$_SERVER['SERVER_NAME'] = '127.0.0.1';
|
||||
|
||||
Pickles\Profiler::report();
|
||||
}
|
||||
file_put_contents('/tmp/pickles.php', '<?php
|
||||
$config = [
|
||||
"environments" => [
|
||||
"local" => "127.0.0.1",
|
||||
"production" => "123.456.789.0",
|
||||
],
|
||||
"pickles" => [
|
||||
"profiler" => true,
|
||||
],
|
||||
];
|
||||
');
|
||||
|
||||
public function testEnabled()
|
||||
{
|
||||
$config = Pickles\Config::getInstance();
|
||||
$config->data['pickles']['profiler'] = true;
|
||||
new Pickles\Config('/tmp/pickles.php');
|
||||
|
||||
$this->assertTrue(Pickles\Profiler::enabled());
|
||||
}
|
||||
|
||||
public function testEnabledType()
|
||||
{
|
||||
$config = Pickles\Config::getInstance();
|
||||
$config->data['pickles']['profiler'] = 'timers';
|
||||
|
||||
$this->assertTrue(Pickles\Profiler::enabled('timers'));
|
||||
}
|
||||
|
||||
public function testLogAndTimer()
|
||||
{
|
||||
Pickles\Profiler::log('timer', 'timer-one');
|
||||
Pickles\Profiler::log('i am a string');
|
||||
Pickles\Profiler::log(['foo' => 'bar']);
|
||||
Pickles\Profiler::log(new Pickles\Object);
|
||||
Pickles\Profiler::log('string');
|
||||
Pickles\Profiler::log(3.14, 'method', true);
|
||||
Pickles\Profiler::log('timer', 'timer-one');
|
||||
}
|
||||
Pickles\Profiler::log($this, 'testProfiler');
|
||||
Pickles\Profiler::timer('swatch');
|
||||
Pickles\Profiler::query('SELECT', ['foo' => 'bar'], ['results'], 1, 'EXPLAIN');
|
||||
Pickles\Profiler::timer('swatch');
|
||||
Pickles\Profiler::query('SELECT', ['foo' => 'bar'], ['results'], 1);
|
||||
|
||||
public function testLogQuery()
|
||||
{
|
||||
$explain = [
|
||||
[
|
||||
'key' => '',
|
||||
'possible_keys' => '',
|
||||
'type' => '',
|
||||
'rows' => '',
|
||||
'Extra' => '',
|
||||
],
|
||||
];
|
||||
$report = Pickles\Profiler::report();
|
||||
|
||||
Pickles\Profiler::query('SELECT * FROM table;');
|
||||
Pickles\Profiler::query('SELECT * FROM table WHERE column = ?;', ['foo']);
|
||||
Pickles\Profiler::query('SELECT * FROM table;', false, $explain);
|
||||
}
|
||||
|
||||
public function testTimer()
|
||||
{
|
||||
Pickles\Profiler::timer('timer-two');
|
||||
Pickles\Profiler::timer('timer-two');
|
||||
$this->assertEquals(7, count($report));
|
||||
$this->assertEquals(7, count($report['logs']));
|
||||
$this->assertEquals(5, count($report['logs'][0]));
|
||||
$this->assertEquals('string', $report['logs'][0]['type']);
|
||||
$this->assertEquals('i am a string', $report['logs'][0]['details']);
|
||||
$this->assertEquals('array', $report['logs'][1]['type']);
|
||||
$this->assertEquals(['foo' => 'bar'], $report['logs'][1]['details']);
|
||||
$this->assertEquals('object', $report['logs'][2]['type']);
|
||||
$this->assertEquals(['class' => 'ProfilerTest', 'method' => 'testProfiler()'], $report['logs'][2]['details']);
|
||||
$this->assertEquals('timer', $report['logs'][3]['type']);
|
||||
$this->assertEquals('swatch', $report['logs'][3]['details']['name']);
|
||||
$this->assertEquals('start', $report['logs'][3]['details']['action']);
|
||||
$this->assertEquals('database', $report['logs'][4]['type']);
|
||||
$this->assertEquals('SELECT', $report['logs'][4]['details']['query']);
|
||||
$this->assertEquals(['foo' => 'bar'], $report['logs'][4]['details']['parameters']);
|
||||
$this->assertEquals(['results'], $report['logs'][4]['details']['results']);
|
||||
$this->assertEquals(1, $report['logs'][4]['details']['execution_time']);
|
||||
$this->assertEquals('EXPLAIN', $report['logs'][4]['details']['explain']);
|
||||
$this->assertEquals('timer', $report['logs'][5]['type']);
|
||||
$this->assertEquals('swatch', $report['logs'][5]['details']['name']);
|
||||
$this->assertEquals('stop', $report['logs'][5]['details']['action']);
|
||||
$this->assertEquals('database', $report['logs'][6]['type']);
|
||||
$this->assertEquals('SELECT', $report['logs'][6]['details']['query']);
|
||||
$this->assertEquals(['foo' => 'bar'], $report['logs'][6]['details']['parameters']);
|
||||
$this->assertEquals(['results'], $report['logs'][6]['details']['results']);
|
||||
$this->assertEquals(1, $report['logs'][6]['details']['execution_time']);
|
||||
$this->assertFalse(isset($report['logs'][6]['details']['explain']));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue