Finished up tests
This commit is contained in:
parent
4167d99623
commit
d884f5a3df
4 changed files with 135 additions and 0 deletions
|
@ -435,5 +435,92 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
Pickles\Database::getInstance();
|
Pickles\Database::getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testProfilerWithoutParameters()
|
||||||
|
{
|
||||||
|
// Clears out the Config for ease of testing
|
||||||
|
Pickles\Object::$instances = [];
|
||||||
|
|
||||||
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||||
|
$_SERVER['SERVER_NAME'] = '127.0.0.1';
|
||||||
|
|
||||||
|
file_put_contents('/tmp/pickles.php', '<?php
|
||||||
|
$config = [
|
||||||
|
"environments" => [
|
||||||
|
"local" => "127.0.0.1",
|
||||||
|
"production" => "123.456.789.0",
|
||||||
|
],
|
||||||
|
"pickles" => [
|
||||||
|
"datasource" => "mysql",
|
||||||
|
"profiler" => true,
|
||||||
|
],
|
||||||
|
"datasources" => [
|
||||||
|
"mysql" => [
|
||||||
|
"type" => "mysql",
|
||||||
|
"driver" => "pdo_mysql",
|
||||||
|
"database" => "test",
|
||||||
|
"hostname" => "localhost",
|
||||||
|
"username" => "root",
|
||||||
|
"password" => "",
|
||||||
|
"database" => "test",
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
');
|
||||||
|
|
||||||
|
Pickles\Config::getInstance('/tmp/pickles.php');
|
||||||
|
|
||||||
|
$db = Pickles\Database::getInstance();
|
||||||
|
$db->execute('SELECT * FROM `users`');
|
||||||
|
|
||||||
|
$report = Pickles\Profiler::report();
|
||||||
|
$this->assertEquals(7, count($report));
|
||||||
|
$this->assertEquals(2, count($report['logs']));
|
||||||
|
$this->assertTrue(isset($report['logs'][1]['details']['explain']));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testProfilerWithParameters()
|
||||||
|
{
|
||||||
|
// Clears out the Config for ease of testing
|
||||||
|
Pickles\Object::$instances = [];
|
||||||
|
|
||||||
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||||
|
$_SERVER['SERVER_NAME'] = '127.0.0.1';
|
||||||
|
|
||||||
|
file_put_contents('/tmp/pickles.php', '<?php
|
||||||
|
$config = [
|
||||||
|
"environments" => [
|
||||||
|
"local" => "127.0.0.1",
|
||||||
|
"production" => "123.456.789.0",
|
||||||
|
],
|
||||||
|
"pickles" => [
|
||||||
|
"datasource" => "mysql",
|
||||||
|
"profiler" => true,
|
||||||
|
],
|
||||||
|
"datasources" => [
|
||||||
|
"mysql" => [
|
||||||
|
"type" => "mysql",
|
||||||
|
"driver" => "pdo_mysql",
|
||||||
|
"database" => "test",
|
||||||
|
"hostname" => "localhost",
|
||||||
|
"username" => "root",
|
||||||
|
"password" => "",
|
||||||
|
"database" => "test",
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
');
|
||||||
|
|
||||||
|
Pickles\Config::getInstance('/tmp/pickles.php');
|
||||||
|
|
||||||
|
$db = Pickles\Database::getInstance();
|
||||||
|
$db->execute('SELECT * FROM `users` WHERE id = ?', [1000000]);
|
||||||
|
|
||||||
|
$report = Pickles\Profiler::report();
|
||||||
|
$this->assertEquals(7, count($report));
|
||||||
|
$this->assertEquals(3, count($report['logs']));
|
||||||
|
$this->assertEquals([1000000], $report['logs'][2]['details']['parameters']);
|
||||||
|
$this->assertTrue(isset($report['logs'][2]['details']['explain']));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,9 @@ class ProfilerTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testProfiler()
|
public function testProfiler()
|
||||||
{
|
{
|
||||||
|
// Clears out any previous logging
|
||||||
|
Pickles\Profiler::report();
|
||||||
|
|
||||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||||
$_SERVER['SERVER_NAME'] = '127.0.0.1';
|
$_SERVER['SERVER_NAME'] = '127.0.0.1';
|
||||||
|
|
||||||
|
|
|
@ -204,6 +204,49 @@ namespace
|
||||||
new Pickles\Router();
|
new Pickles\Router();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testBasicAuth()
|
||||||
|
{
|
||||||
|
Pickles\Object::$instances = [];
|
||||||
|
|
||||||
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||||
|
$_SERVER['SERVER_NAME'] = '127.0.0.1';
|
||||||
|
|
||||||
|
file_put_contents('/tmp/pickles.php', '<?php
|
||||||
|
$config = [
|
||||||
|
"environments" => [
|
||||||
|
"local" => "127.0.0.1",
|
||||||
|
"production" => "123.456.789.0",
|
||||||
|
],
|
||||||
|
"pickles" => [
|
||||||
|
"namespace" => "",
|
||||||
|
"datasource" => "mysql",
|
||||||
|
"auth" => "basic",
|
||||||
|
],
|
||||||
|
"datasources" => [
|
||||||
|
"mysql" => [
|
||||||
|
"driver" => "pdo_mysql",
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
');
|
||||||
|
|
||||||
|
Pickles\Config::getInstance('/tmp/pickles.php');
|
||||||
|
|
||||||
|
$response = json_encode([
|
||||||
|
'meta' => [
|
||||||
|
'status' => 405,
|
||||||
|
'message' => 'Method not allowed.',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->expectOutputString($response);
|
||||||
|
|
||||||
|
$_SERVER['REQUEST_METHOD'] = 'DELETE';
|
||||||
|
$_REQUEST['request'] = 'v1/resource/1';
|
||||||
|
|
||||||
|
new Pickles\Router();
|
||||||
|
}
|
||||||
|
|
||||||
public function testMethodNotAllowed()
|
public function testMethodNotAllowed()
|
||||||
{
|
{
|
||||||
$response = json_encode([
|
$response = json_encode([
|
||||||
|
|
|
@ -53,3 +53,5 @@ CREATE TABLE `users` (
|
||||||
`is_deleted` tinyint(1) unsigned DEFAULT '0',
|
`is_deleted` tinyint(1) unsigned DEFAULT '0',
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||||||
|
|
||||||
|
INSERT INTO users (id, username, created_at) VALUES (1000000, 'test', NOW());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue