Browse Source

Replace constant DEBUG to use in Config. Remove start profiler from FrontController (moved to bootstrap).

master
Alexander Demidov 13 years ago
parent
commit
cfd6536c5f
  1. 7
      app/FrontController.php
  2. 2
      logger/Logger.php
  3. 2
      model/MongoStatement.php
  4. 2
      model/MySQLiStatement.php
  5. 2
      redis/RedisManager.php
  6. 4
      tests/LoadTest.php
  7. 17
      tests/app/ActionTest.php
  8. 15
      tests/app/AjaxActionTest.php
  9. 10
      tests/app/ErrorActionTest.php
  10. 5
      tests/app/FrontControllerTest.php
  11. 25
      tests/app/PagerActionTest.php
  12. 10
      tests/app/StaticActionTest.php
  13. 10
      tests/classes/EnvTest.php
  14. 10
      tests/layout/ErrorLayoutTest.php
  15. 20
      tests/layout/LayoutTest.php
  16. 5
      tests/logger/CliLoggerTest.php
  17. 12
      tests/logger/FileLoggerTest.php
  18. 64
      tests/model/MongoDriverTest.php
  19. 40
      tests/model/MongoModelTest.php
  20. 76
      tests/model/MongoStatementTest.php
  21. 32
      tests/model/MySQLiDriverTest.php
  22. 40
      tests/model/MySQLiStatementTest.php
  23. 12
      tests/redis/RedisDebugTest.php
  24. 4
      tests/redis/RedisManagerTest.php
  25. 28
      tests/util/profiler/ProfilerTest.php
  26. 2
      util/profiler/Profiler.php

7
app/FrontController.php

@ -32,9 +32,6 @@ class FrontController
private function __construct() private function __construct()
{ {
ErrorHandler::init(); ErrorHandler::init();
if (DEBUG == true) {
Profiler::getInstance()->start();
}
$this->router = new Router(); $this->router = new Router();
} }
@ -120,7 +117,7 @@ class FrontController
$layout = new $layout_class(); $layout = new $layout_class();
$html = $layout->fetch($action); $html = $layout->fetch($action);
if (DEBUG) {
if (Config::get('PROFILER')) {
if (is_subclass_of($action, 'AjaxAction')) { if (is_subclass_of($action, 'AjaxAction')) {
Profiler::getInstance()->getJson(); Profiler::getInstance()->getJson();
} else { } else {
@ -129,7 +126,7 @@ class FrontController
} }
return $html; return $html;
} catch (Exception $e) { } catch (Exception $e) {
if (DEBUG == true) {
if (Config::get('DEBUG')) {
if (!headers_sent()) { if (!headers_sent()) {
header('HTTP/1.0 500 Internal Server Error'); header('HTTP/1.0 500 Internal Server Error');
} }

2
logger/Logger.php

@ -43,7 +43,7 @@ abstract class Logger
*/ */
public function log($message) public function log($message)
{ {
if (DEBUG) {
if (Config::get('LOGGING')) {
$this->concreteLog($message); $this->concreteLog($message);
} }
} }

2
model/MongoStatement.php

@ -138,7 +138,7 @@ class MongoStatement extends DbStatement
$this->result = false; $this->result = false;
$mongo = $this->driver->getConnection(); $mongo = $this->driver->getConnection();
if ($mongo instanceof Mongo) { if ($mongo instanceof Mongo) {
if (DEBUG) {
if (Config::get('PROFILER_DETAILS')) {
$profiler = Profiler::getInstance()->profilerCommand('Mongo', $request); $profiler = Profiler::getInstance()->profilerCommand('Mongo', $request);
$result = $request->execute(); $result = $request->execute();
$profiler->end(); $profiler->end();

2
model/MySQLiStatement.php

@ -157,7 +157,7 @@ class MySQLiStatement extends DbStatement
* @var MySQLi * @var MySQLi
*/ */
$mysqli = $this->driver->getConnection(); $mysqli = $this->driver->getConnection();
if (DEBUG) {
if (Config::get('PROFILER_DETAILS')) {
$profiler = Profiler::getInstance()->profilerCommand('MySQL', $request); $profiler = Profiler::getInstance()->profilerCommand('MySQL', $request);
$result = $mysqli->query($request); $result = $mysqli->query($request);
$profiler->end(); $profiler->end();

2
redis/RedisManager.php

@ -49,7 +49,7 @@ class RedisManager
* @var Redis * @var Redis
*/ */
$connection = new Redis(); $connection = new Redis();
if (defined('DEBUG') && DEBUG == true) {
if (Config::get('DEBUG')) {
$connection = new RedisDebug($connection); $connection = new RedisDebug($connection);
} }
if (!$connection->connect($host, $port)) { if (!$connection->connect($host, $port)) {

4
tests/LoadTest.php

@ -164,9 +164,7 @@ class LoadTest extends PHPUnit_Framework_TestCase
$autoload = require(self::$file); $autoload = require(self::$file);
$this->assertNotEmpty($autoload); $this->assertNotEmpty($autoload);
if (!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1);
Load::autoload('Some'); Load::autoload('Some');
Load::autoload('DbDriver'); Load::autoload('DbDriver');
} }

17
tests/app/ActionTest.php

@ -20,9 +20,7 @@ class ActionTest extends Action_TestCase
*/ */
public function testActionConstructWithParams() public function testActionConstructWithParams()
{ {
if(!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
Env::setParams(array('param1' => 'value1', 'param2' => 'value2')); Env::setParams(array('param1' => 'value1', 'param2' => 'value2'));
$action = $this->getMockForAbstractClass('Action' ); $action = $this->getMockForAbstractClass('Action' );
$this->assertSame('value1', $action->param1); $this->assertSame('value1', $action->param1);
@ -33,9 +31,7 @@ class ActionTest extends Action_TestCase
*/ */
public function testFetch() public function testFetch()
{ {
if(!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$load = new ReflectionClass('Load'); $load = new ReflectionClass('Load');
$classes = $load->getProperty('autoload'); $classes = $load->getProperty('autoload');
$classes->setAccessible(true); $classes->setAccessible(true);
@ -53,9 +49,7 @@ class ActionTest extends Action_TestCase
*/ */
public function testFetchNoTemplate() public function testFetchNoTemplate()
{ {
if(!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
Env::setParams(array('template' => '')); Env::setParams(array('template' => ''));
$controller = FrontController::getInstance(); $controller = FrontController::getInstance();
$controller->setView('SomeView'); $controller->setView('SomeView');
@ -70,9 +64,8 @@ class ActionTest extends Action_TestCase
public function testRedirect() public function testRedirect()
{ {
set_exit_overload(function() { return false; }); set_exit_overload(function() { return false; });
if(!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$load = new ReflectionClass('Action'); $load = new ReflectionClass('Action');
$redirect = $load->getMethod('redirect'); $redirect = $load->getMethod('redirect');
$redirect->setAccessible(true); $redirect->setAccessible(true);

15
tests/app/AjaxActionTest.php

@ -21,9 +21,8 @@ class AjaxActionTest extends Action_TestCase
*/ */
public function testConstruct() public function testConstruct()
{ {
if(!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
Env::setParams(array('ajax' => 'AjaxTemplate', 'param2' => 'value2')); Env::setParams(array('ajax' => 'AjaxTemplate', 'param2' => 'value2'));
$action = $this->getMockForAbstractClass('AjaxAction' ); $action = $this->getMockForAbstractClass('AjaxAction' );
$this->assertAttributeEquals('ajax', 'template', $action); $this->assertAttributeEquals('ajax', 'template', $action);
@ -34,9 +33,8 @@ class AjaxActionTest extends Action_TestCase
*/ */
public function testFetchWithEncode() public function testFetchWithEncode()
{ {
if(!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$controller = FrontController::getInstance(); $controller = FrontController::getInstance();
$controller->setView('SomeView'); $controller->setView('SomeView');
$action = $this->getMockForAbstractClass('AjaxAction' ); $action = $this->getMockForAbstractClass('AjaxAction' );
@ -51,9 +49,8 @@ class AjaxActionTest extends Action_TestCase
*/ */
public function testFetchNoEncode() public function testFetchNoEncode()
{ {
if(!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
Env::setParams(array('encode' => false)); Env::setParams(array('encode' => false));
$controller = FrontController::getInstance(); $controller = FrontController::getInstance();
$controller->setView('SomeView'); $controller->setView('SomeView');

10
tests/app/ErrorActionTest.php

@ -80,9 +80,8 @@ class ErrorActionTest extends Action_TestCase
*/ */
public function testFetchNoTemplate() public function testFetchNoTemplate()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$exception = $this->getMock('ErrorException'); $exception = $this->getMock('ErrorException');
$controller = FrontController::getInstance(); $controller = FrontController::getInstance();
$controller->setView('SomeView'); $controller->setView('SomeView');
@ -123,9 +122,8 @@ class ErrorActionTest extends Action_TestCase
private function setConstants($val = false) private function setConstants($val = false)
{ {
if (!defined('DEBUG')) {
define('DEBUG', $val);
}
Config::set('DEBUG', $val);
} }
private function header() private function header()

5
tests/app/FrontControllerTest.php

@ -210,9 +210,8 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase
private function setConstants($val = false) private function setConstants($val = false)
{ {
if (!defined('DEBUG')) {
define('DEBUG', $val);
}
Config::set('DEBUG', $val);
} }
public function tearDown() public function tearDown()

25
tests/app/PagerActionTest.php

@ -21,9 +21,8 @@ class PagerActionTest extends Action_TestCase
*/ */
public function testConstructWithParams() public function testConstructWithParams()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$action = $this->getMockForAbstractClass('PagerAction'); $action = $this->getMockForAbstractClass('PagerAction');
$this->assertSame(20, $action->getLimit()); $this->assertSame(20, $action->getLimit());
$action = $this->getMockForAbstractClass('PagerAction', array(50)); $action = $this->getMockForAbstractClass('PagerAction', array(50));
@ -35,9 +34,8 @@ class PagerActionTest extends Action_TestCase
*/ */
public function testSetCount() public function testSetCount()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$action = $this->getMockForAbstractClass('PagerAction'); $action = $this->getMockForAbstractClass('PagerAction');
$action->setCount(50); $action->setCount(50);
$this->assertSame(1, $action->page); $this->assertSame(1, $action->page);
@ -60,9 +58,8 @@ class PagerActionTest extends Action_TestCase
*/ */
public function testGetOffset() public function testGetOffset()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$action = $this->getMockForAbstractClass('PagerAction'); $action = $this->getMockForAbstractClass('PagerAction');
$this->assertSame(0, $action->getOffset()); $this->assertSame(0, $action->getOffset());
} }
@ -72,9 +69,8 @@ class PagerActionTest extends Action_TestCase
*/ */
public function testFetchNoTemplate() public function testFetchNoTemplate()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
Env::setParams(array('template' => '')); Env::setParams(array('template' => ''));
$controller = FrontController::getInstance(); $controller = FrontController::getInstance();
$controller->setView('SomeView'); $controller->setView('SomeView');
@ -88,9 +84,8 @@ class PagerActionTest extends Action_TestCase
*/ */
public function testFetchWithTemplate() public function testFetchWithTemplate()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
Env::setParams(array('template' => 'SomeTemplate')); Env::setParams(array('template' => 'SomeTemplate'));
$controller = FrontController::getInstance(); $controller = FrontController::getInstance();
$controller->setView('SomeView'); $controller->setView('SomeView');

10
tests/app/StaticActionTest.php

@ -21,9 +21,8 @@ class StaticActionTest extends Action_TestCase
*/ */
public function testFetchNoTemplate() public function testFetchNoTemplate()
{ {
if(!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
Env::setParams(array('template' => '')); Env::setParams(array('template' => ''));
$controller = FrontController::getInstance(); $controller = FrontController::getInstance();
$controller->setView('SomeView'); $controller->setView('SomeView');
@ -37,9 +36,8 @@ class StaticActionTest extends Action_TestCase
*/ */
public function testFetchWithTemplate() public function testFetchWithTemplate()
{ {
if(!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
Env::setParams(array('template' => 'SomeTemplate')); Env::setParams(array('template' => 'SomeTemplate'));
$controller = FrontController::getInstance(); $controller = FrontController::getInstance();
$controller->setView('SomeView'); $controller->setView('SomeView');

10
tests/classes/EnvTest.php

@ -24,9 +24,8 @@ class EnvTest extends PHPUnit_Framework_TestCase
*/ */
public function testGetRequestUri() public function testGetRequestUri()
{ {
if(!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$_SERVER['REQUEST_URI'] = '/test/index.php?id=1&test=wet&id_theme=512'; $_SERVER['REQUEST_URI'] = '/test/index.php?id=1&test=wet&id_theme=512';
$this->assertSame('/test/index.php', Env::getRequestUri()); $this->assertSame('/test/index.php', Env::getRequestUri());
$_SERVER['REQUEST_URI'] = '/tes?t/index.php?id=1&test=wet&id_theme=512'; $_SERVER['REQUEST_URI'] = '/tes?t/index.php?id=1&test=wet&id_theme=512';
@ -38,9 +37,8 @@ class EnvTest extends PHPUnit_Framework_TestCase
*/ */
public function testTrimBaseRequestUri() public function testTrimBaseRequestUri()
{ {
if(!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$class = new ReflectionClass('Env'); $class = new ReflectionClass('Env');
$this->started = $class->getProperty('request'); $this->started = $class->getProperty('request');
$this->started->setAccessible(true); $this->started->setAccessible(true);

10
tests/layout/ErrorLayoutTest.php

@ -40,9 +40,8 @@ class ErrorLayoutTest extends PHPUnit_Framework_TestCase
public function testSetException() public function testSetException()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$layout = new ErrorLayout(); $layout = new ErrorLayout();
$layout->setException(new GeneralException()); $layout->setException(new GeneralException());
$this->assertAttributeInstanceOf('GeneralException', 'exception', $layout); $this->assertAttributeInstanceOf('GeneralException', 'exception', $layout);
@ -50,9 +49,8 @@ class ErrorLayoutTest extends PHPUnit_Framework_TestCase
public function testExecute() public function testExecute()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$action = $this->getMock('Action', array('fetch')); $action = $this->getMock('Action', array('fetch'));
$action->expects($this->once()) $action->expects($this->once())
->method('fetch') ->method('fetch')

20
tests/layout/LayoutTest.php

@ -40,18 +40,16 @@ class LayoutTest extends PHPUnit_Framework_TestCase
public function testConstruct() public function testConstruct()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$layout = $this->getMockForAbstractClass('Layout'); $layout = $this->getMockForAbstractClass('Layout');
$this->assertAttributeInstanceOf('PHPView', 'view', $layout); $this->assertAttributeInstanceOf('PHPView', 'view', $layout);
} }
public function testFetch() public function testFetch()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$layout = $this->getMockForAbstractClass('Layout'); $layout = $this->getMockForAbstractClass('Layout');
$action = $this->getMock('Action', array('fetch')); $action = $this->getMock('Action', array('fetch'));
@ -64,9 +62,8 @@ class LayoutTest extends PHPUnit_Framework_TestCase
public function testFetchWithTemplate() public function testFetchWithTemplate()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$layout = $this->getMockForAbstractClass('Layout'); $layout = $this->getMockForAbstractClass('Layout');
$class = new ReflectionClass('Layout'); $class = new ReflectionClass('Layout');
@ -89,9 +86,8 @@ class LayoutTest extends PHPUnit_Framework_TestCase
public function testAppend() public function testAppend()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$layout = $this->getMockForAbstractClass('Layout', array('append', 'prepend'), 'LayoutMock'); $layout = $this->getMockForAbstractClass('Layout', array('append', 'prepend'), 'LayoutMock');
$action = $this->getMock('Action', array('fetch')); $action = $this->getMock('Action', array('fetch'));

5
tests/logger/CliLoggerTest.php

@ -43,9 +43,8 @@ class CliLoggerTest extends PHPUnit_Framework_TestCase
*/ */
public function testLog() public function testLog()
{ {
if(!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1);
$logger = Logger::getInstance(); $logger = Logger::getInstance();
ob_start(); ob_start();
$logger->setPid(123); $logger->setPid(123);

12
tests/logger/FileLoggerTest.php

@ -54,9 +54,7 @@ class FileLoggerTest extends PHPUnit_Framework_TestCase
*/ */
public function testCannotWrite() public function testCannotWrite()
{ {
if (!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1);
$conf = array('logger' => 'FileLogger', 'filepath' => '/log.txt'); $conf = array('logger' => 'FileLogger', 'filepath' => '/log.txt');
Config::set('Logger', $conf); Config::set('Logger', $conf);
@ -71,9 +69,7 @@ class FileLoggerTest extends PHPUnit_Framework_TestCase
*/ */
public function testLog() public function testLog()
{ {
if (!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1);
$this->assertFileNotExists($this->conf['filepath']); $this->assertFileNotExists($this->conf['filepath']);
$logger = Logger::getInstance(); $logger = Logger::getInstance();
$logger->setPid(123); $logger->setPid(123);
@ -86,9 +82,7 @@ class FileLoggerTest extends PHPUnit_Framework_TestCase
*/ */
public function testDestruct() public function testDestruct()
{ {
if (!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1);
$my_pid = posix_getpid(); $my_pid = posix_getpid();
$fd_command = 'lsof -n -p ' . $my_pid . ' | wc -l'; $fd_command = 'lsof -n -p ' . $my_pid . ' | wc -l';
$fd_count_start = (int) `$fd_command`; $fd_count_start = (int) `$fd_command`;

64
tests/model/MongoDriverTest.php

@ -114,9 +114,7 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase
*/ */
public function testFind() public function testFind()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$mongo = new MongoDriver($this->conf); $mongo = new MongoDriver($this->conf);
$this->assertEquals(1, $mongo->find('items', array('name' => 'bread'))->numRows()); $this->assertEquals(1, $mongo->find('items', array('name' => 'bread'))->numRows());
@ -145,9 +143,7 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase
*/ */
public function testOrderSkipLimit() public function testOrderSkipLimit()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$mongo = new MongoDriver($this->conf); $mongo = new MongoDriver($this->conf);
@ -184,9 +180,7 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase
*/ */
public function testCount() public function testCount()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$mongo = new MongoDriver($this->conf); $mongo = new MongoDriver($this->conf);
$this->assertEquals(5, $mongo->count('items')); $this->assertEquals(5, $mongo->count('items'));
$this->assertEquals(2, $mongo->count('items', array('name' => 'eggs'))); $this->assertEquals(2, $mongo->count('items', array('name' => 'eggs')));
@ -199,9 +193,7 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase
*/ */
public function testCursorCount() public function testCursorCount()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$mongo = new MongoDriver($this->conf); $mongo = new MongoDriver($this->conf);
$this->assertEquals(5, $mongo->find('items')->count(5)); $this->assertEquals(5, $mongo->find('items')->count(5));
$this->assertCount(3, $mongo->find('items')->limit(3)->fetchAll()); $this->assertCount(3, $mongo->find('items')->limit(3)->fetchAll());
@ -214,9 +206,7 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase
*/ */
public function testGet() public function testGet()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$mongo = new MongoDriver($this->conf); $mongo = new MongoDriver($this->conf);
$eggs = $mongo->get('items', array('name' => 'eggs'))->fetchObject(); $eggs = $mongo->get('items', array('name' => 'eggs'))->fetchObject();
@ -232,9 +222,7 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase
*/ */
public function testRemove() public function testRemove()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$mongo = new MongoDriver($this->conf); $mongo = new MongoDriver($this->conf);
$this->assertEquals(1, $mongo->find('items', array('name' => 'bread'))->numRows()); $this->assertEquals(1, $mongo->find('items', array('name' => 'bread'))->numRows());
@ -250,9 +238,7 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase
*/ */
public function testInsert() public function testInsert()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$mongo = new MongoDriver($this->conf); $mongo = new MongoDriver($this->conf);
$this->assertEquals(1, $mongo->find('items', array('name' => 'bread'))->numRows()); $this->assertEquals(1, $mongo->find('items', array('name' => 'bread'))->numRows());
@ -269,9 +255,7 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase
*/ */
public function testBatchInsert() public function testBatchInsert()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$data = array( $data = array(
array('name' => 'first object'), array('name' => 'first object'),
@ -292,9 +276,7 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase
*/ */
public function testGetInsertId() public function testGetInsertId()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$mongo = new MongoDriver($this->conf); $mongo = new MongoDriver($this->conf);
$this->assertEquals(0, $mongo->getInsertId()); $this->assertEquals(0, $mongo->getInsertId());
@ -316,9 +298,7 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase
*/ */
public function testUpdate() public function testUpdate()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$mongo = new MongoDriver($this->conf); $mongo = new MongoDriver($this->conf);
$this->assertEquals(1, $mongo->find('items', array('name' => 'bread'))->numRows()); $this->assertEquals(1, $mongo->find('items', array('name' => 'bread'))->numRows());
@ -336,9 +316,7 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase
*/ */
public function testUpsert() public function testUpsert()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$mongo = new MongoDriver($this->conf); $mongo = new MongoDriver($this->conf);
@ -353,9 +331,7 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase
*/ */
public function testFindAndModify() public function testFindAndModify()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$mongo = new MongoDriver($this->conf); $mongo = new MongoDriver($this->conf);
@ -371,9 +347,7 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase
*/ */
public function testFindAndModifyNoItem() public function testFindAndModifyNoItem()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$mongo = new MongoDriver($this->conf); $mongo = new MongoDriver($this->conf);
@ -389,9 +363,7 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase
*/ */
public function testEvalCommand() public function testEvalCommand()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$mongo = new MongoDriver($this->conf); $mongo = new MongoDriver($this->conf);
$result = $mongo->command('items', array('$eval' => 'function() { return db.items.count();}')); $result = $mongo->command('items', array('$eval' => 'function() { return db.items.count();}'));
$this->assertEquals(5, $result->fetch()); $this->assertEquals(5, $result->fetch());
@ -406,9 +378,7 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase
*/ */
public function testEval() public function testEval()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$mongo = new MongoDriver($this->conf); $mongo = new MongoDriver($this->conf);
$result = $mongo->command('items', array('$eval' => 'function() {return true; }')); $result = $mongo->command('items', array('$eval' => 'function() {return true; }'));
$this->assertTrue($result->fetch()); $this->assertTrue($result->fetch());
@ -424,9 +394,7 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase
*/ */
public function testCommand() public function testCommand()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$mongo = new MongoDriver($this->conf); $mongo = new MongoDriver($this->conf);
$result = $mongo->command('items', array('distinct' => 'items', 'key' => 'name')); $result = $mongo->command('items', array('distinct' => 'items', 'key' => 'name'));
$this->assertEquals(4, count($result->fetch(DB::FETCH_ASSOC))); $this->assertEquals(4, count($result->fetch(DB::FETCH_ASSOC)));

40
tests/model/MongoModelTest.php

@ -64,9 +64,7 @@ class MongoModelTest extends PHPUnit_Framework_TestCase
*/ */
public function testFind() public function testFind()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$result = $this->model->find(); $result = $this->model->find();
$this->assertInstanceOf('MongoStatement', $result); $this->assertInstanceOf('MongoStatement', $result);
$this->assertEquals('milk', $result->limit(2)->order(array('name' => -1))->fetch()->name); $this->assertEquals('milk', $result->limit(2)->order(array('name' => -1))->fetch()->name);
@ -83,9 +81,7 @@ class MongoModelTest extends PHPUnit_Framework_TestCase
*/ */
public function testGet() public function testGet()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$result = $this->model->find()->limit(1)->order(array('name' => 1)); $result = $this->model->find()->limit(1)->order(array('name' => 1));
$result = $result->fetch(); $result = $result->fetch();
$this->assertEquals('bread', $result->name); $this->assertEquals('bread', $result->name);
@ -99,9 +95,7 @@ class MongoModelTest extends PHPUnit_Framework_TestCase
*/ */
public function testDelete() public function testDelete()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$result = $this->model->find()->limit(1)->order(array('name' => 1)); $result = $this->model->find()->limit(1)->order(array('name' => 1));
$id = $result->fetch()->_id; $id = $result->fetch()->_id;
$this->assertEquals(1, $this->model->delete($id)); $this->assertEquals(1, $this->model->delete($id));
@ -114,9 +108,7 @@ class MongoModelTest extends PHPUnit_Framework_TestCase
*/ */
public function testBatchInsert() public function testBatchInsert()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$data = array( $data = array(
array('name' => 'first object'), array('name' => 'first object'),
array('name' => 'second object'), array('name' => 'second object'),
@ -135,9 +127,7 @@ class MongoModelTest extends PHPUnit_Framework_TestCase
*/ */
public function testDeleteAll() public function testDeleteAll()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$this->assertEquals(2, $this->model->count(array('name' => 'eggs'))); $this->assertEquals(2, $this->model->count(array('name' => 'eggs')));
$this->assertEquals(0, $this->model->deleteAll(array('name' => 'eggs'))); $this->assertEquals(0, $this->model->deleteAll(array('name' => 'eggs')));
@ -150,9 +140,7 @@ class MongoModelTest extends PHPUnit_Framework_TestCase
*/ */
public function testCount() public function testCount()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$this->assertEquals(5, $this->model->count()); $this->assertEquals(5, $this->model->count());
$this->assertEquals(2, $this->model->count(array('name' => 'eggs'))); $this->assertEquals(2, $this->model->count(array('name' => 'eggs')));
} }
@ -163,9 +151,7 @@ class MongoModelTest extends PHPUnit_Framework_TestCase
*/ */
public function testFetch() public function testFetch()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$mock = $this->getMock('CacheKey', array('set', 'get')); $mock = $this->getMock('CacheKey', array('set', 'get'));
$mock->expects($this->exactly(3)) $mock->expects($this->exactly(3))
@ -204,9 +190,7 @@ class MongoModelTest extends PHPUnit_Framework_TestCase
*/ */
public function testUseMongoId() public function testUseMongoId()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$this->assertAttributeEquals(true, 'useMongoId', $this->model); $this->assertAttributeEquals(true, 'useMongoId', $this->model);
} }
@ -217,9 +201,7 @@ class MongoModelTest extends PHPUnit_Framework_TestCase
*/ */
public function testId() public function testId()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$class = new ReflectionClass('MongoModel'); $class = new ReflectionClass('MongoModel');
$prop = $class->getProperty('useMongoId'); $prop = $class->getProperty('useMongoId');
$prop->setAccessible(true); $prop->setAccessible(true);
@ -239,9 +221,7 @@ class MongoModelTest extends PHPUnit_Framework_TestCase
*/ */
public function testIdToMongoId() public function testIdToMongoId()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$this->model->insert(array('name' => 'testbread', 'price' => 3.2, 'quantity' => 10)); $this->model->insert(array('name' => 'testbread', 'price' => 3.2, 'quantity' => 10));
$this->model->insert(array('name' => 'testbread', 'price' => 12, 'quantity' => 2)); $this->model->insert(array('name' => 'testbread', 'price' => 12, 'quantity' => 2));

76
tests/model/MongoStatementTest.php

@ -61,9 +61,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testAffectedNumRowsNoResult() public function testAffectedNumRowsNoResult()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$this->assertFalse($this->stmt->affectedRows()); $this->assertFalse($this->stmt->affectedRows());
$this->assertFalse($this->stmt->numRows()); $this->assertFalse($this->stmt->numRows());
@ -82,9 +80,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testAffectedNumRows() public function testAffectedNumRows()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$this->setDriverGetConnectionMethod(); $this->setDriverGetConnectionMethod();
$this->request $this->request
->expects($this->once()) ->expects($this->once())
@ -100,9 +96,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testGetInsertId() public function testGetInsertId()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$this->setDriverGetConnectionMethod(); $this->setDriverGetConnectionMethod();
$this->request = $this->getMockBuilder('InsertMongoCommand') $this->request = $this->getMockBuilder('InsertMongoCommand')
@ -131,9 +125,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testExecute() public function testExecute()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$this->setDriverGetConnectionMethod()->setRequestExecuteMethod(); $this->setDriverGetConnectionMethod()->setRequestExecuteMethod();
$this->assertTrue($this->stmt->execute()); $this->assertTrue($this->stmt->execute());
@ -145,9 +137,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testExecuteNoResult() public function testExecuteNoResult()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$this->setDriverGetConnectionMethod(); $this->setDriverGetConnectionMethod();
$this->request $this->request
->expects($this->any()) ->expects($this->any())
@ -163,9 +153,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testExecuteNoConnection() public function testExecuteNoConnection()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$this->driver $this->driver
->expects($this->any()) ->expects($this->any())
->method('getConnection') ->method('getConnection')
@ -180,9 +168,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testExecuteWithDebug() public function testExecuteWithDebug()
{ {
if (!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1;
$this->setDriverGetConnectionMethod()->setRequestExecuteMethod(); $this->setDriverGetConnectionMethod()->setRequestExecuteMethod();
$this->assertTrue($this->stmt->execute()); $this->assertTrue($this->stmt->execute());
$this->assertEquals(10, $this->stmt->numRows()); $this->assertEquals(10, $this->stmt->numRows());
@ -194,9 +180,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testBindParam() public function testBindParam()
{ {
if (!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1;
$this->request $this->request
->expects($this->once()) ->expects($this->once())
@ -217,9 +201,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testFetch() public function testFetch()
{ {
if (!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1;
$this->assertFalse($this->stmt->fetch()); $this->assertFalse($this->stmt->fetch());
$this->setDriverGetConnectionMethod()->setRequestForFetch(); $this->setDriverGetConnectionMethod()->setRequestForFetch();
@ -236,9 +218,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testFetchWithInitialArray() public function testFetchWithInitialArray()
{ {
if (!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1;
$this->assertFalse($this->stmt->fetch()); $this->assertFalse($this->stmt->fetch());
$this->setDriverGetConnectionMethod(); $this->setDriverGetConnectionMethod();
@ -257,9 +237,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testFetchAssocFromCursor() public function testFetchAssocFromCursor()
{ {
if (!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1;
$this->assertFalse($this->stmt->fetch()); $this->assertFalse($this->stmt->fetch());
$this->setDriverGetConnectionMethod()->setRequestForFetch(); $this->setDriverGetConnectionMethod()->setRequestForFetch();
@ -276,9 +254,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testFetchAssocFromArray() public function testFetchAssocFromArray()
{ {
if (!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1;
$this->assertFalse($this->stmt->fetch()); $this->assertFalse($this->stmt->fetch());
$this->setDriverGetConnectionMethod(); $this->setDriverGetConnectionMethod();
@ -298,9 +274,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testFetchWrongMode() public function testFetchWrongMode()
{ {
if (!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1;
$this->assertFalse($this->stmt->fetch()); $this->assertFalse($this->stmt->fetch());
$this->setDriverGetConnectionMethod(); $this->setDriverGetConnectionMethod();
@ -320,9 +294,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testSkipOrderLimit() public function testSkipOrderLimit()
{ {
if (!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1;
$this->setDriverGetConnectionMethod()->setRequestForFetch(); $this->setDriverGetConnectionMethod()->setRequestForFetch();
$this->stmt->execute(); $this->stmt->execute();
@ -340,9 +312,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testCount() public function testCount()
{ {
if (!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1;
$this->setDriverGetConnectionMethod()->setRequestForFetch(); $this->setDriverGetConnectionMethod()->setRequestForFetch();
$this->stmt->execute(); $this->stmt->execute();
@ -357,9 +327,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testCountException() public function testCountException()
{ {
if (!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1;
$this->setDriverGetConnectionMethod(); $this->setDriverGetConnectionMethod();
$this->request $this->request
->expects($this->once()) ->expects($this->once())
@ -377,9 +345,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testOrderException() public function testOrderException()
{ {
if (!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1;
$this->setDriverGetConnectionMethod(); $this->setDriverGetConnectionMethod();
$this->request $this->request
->expects($this->once()) ->expects($this->once())
@ -397,9 +363,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testSkipException() public function testSkipException()
{ {
if (!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1;
$this->setDriverGetConnectionMethod(); $this->setDriverGetConnectionMethod();
$this->request $this->request
->expects($this->once()) ->expects($this->once())
@ -417,9 +381,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testLimitException() public function testLimitException()
{ {
if (!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1;
$this->setDriverGetConnectionMethod(); $this->setDriverGetConnectionMethod();
$this->request $this->request
->expects($this->once()) ->expects($this->once())

32
tests/model/MySQLiDriverTest.php

@ -57,9 +57,7 @@ class MySQLiDriverTest extends PHPUnit_Extensions_Database_TestCase
*/ */
public function testDriver() public function testDriver()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$driver = new MySQLiDriver($this->conf); $driver = new MySQLiDriver($this->conf);
@ -78,9 +76,7 @@ class MySQLiDriverTest extends PHPUnit_Extensions_Database_TestCase
*/ */
public function testGetConnection() public function testGetConnection()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$driver = new MySQLiDriver($this->conf); $driver = new MySQLiDriver($this->conf);
$this->assertInstanceOf('mysqli', $driver->getConnection()); $this->assertInstanceOf('mysqli', $driver->getConnection());
@ -91,9 +87,7 @@ class MySQLiDriverTest extends PHPUnit_Extensions_Database_TestCase
*/ */
public function testGetConnectionWrongConfig() public function testGetConnectionWrongConfig()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$this->conf['database'] = 'nodb'; $this->conf['database'] = 'nodb';
$driver = new MySQLiDriver($this->conf); $driver = new MySQLiDriver($this->conf);
@ -106,9 +100,7 @@ class MySQLiDriverTest extends PHPUnit_Extensions_Database_TestCase
*/ */
public function testDisconnect() public function testDisconnect()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$driver = new MySQLiDriver($this->conf); $driver = new MySQLiDriver($this->conf);
@ -125,9 +117,7 @@ class MySQLiDriverTest extends PHPUnit_Extensions_Database_TestCase
*/ */
public function testInsert() public function testInsert()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$driver = new MySQLiDriver($this->conf); $driver = new MySQLiDriver($this->conf);
@ -147,9 +137,7 @@ class MySQLiDriverTest extends PHPUnit_Extensions_Database_TestCase
*/ */
public function testGetInsertId() public function testGetInsertId()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$driver = new MySQLiDriver($this->conf); $driver = new MySQLiDriver($this->conf);
@ -161,9 +149,7 @@ class MySQLiDriverTest extends PHPUnit_Extensions_Database_TestCase
*/ */
public function testTransaction() public function testTransaction()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$driver = new MySQLiDriver($this->conf); $driver = new MySQLiDriver($this->conf);
@ -194,9 +180,7 @@ class MySQLiDriverTest extends PHPUnit_Extensions_Database_TestCase
*/ */
public function testRollback() public function testRollback()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$driver = new MySQLiDriver($this->conf); $driver = new MySQLiDriver($this->conf);

40
tests/model/MySQLiStatementTest.php

@ -81,9 +81,7 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testExecute() public function testExecute()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$this->driver $this->driver
->expects($this->any()) ->expects($this->any())
@ -102,9 +100,7 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testExecuteNoPlaceholders() public function testExecuteNoPlaceholders()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$this->setDriverGetConnectionMethod(); $this->setDriverGetConnectionMethod();
$this->sql = 'PLAIN SQL'; $this->sql = 'PLAIN SQL';
@ -118,9 +114,7 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testFetchNoResult() public function testFetchNoResult()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$this->assertFalse($this->stmt->fetch()); $this->assertFalse($this->stmt->fetch());
} }
@ -130,9 +124,7 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testDriverExecuteNoResult() public function testDriverExecuteNoResult()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$this->setDriverGetConnectionWrongResultMethod(); $this->setDriverGetConnectionWrongResultMethod();
$this->setExpectedException('GeneralException', 'ERROR'); $this->setExpectedException('GeneralException', 'ERROR');
$this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val')); $this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
@ -144,9 +136,7 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testFetch() public function testFetch()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$this->setDriverGetConnectionMethod(); $this->setDriverGetConnectionMethod();
$this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val')); $this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
$this->assertSame('OBJECT', $this->stmt->fetch()); $this->assertSame('OBJECT', $this->stmt->fetch());
@ -161,9 +151,7 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testFetchObject() public function testFetchObject()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$this->setDriverGetConnectionMethod(); $this->setDriverGetConnectionMethod();
$this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val')); $this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
$this->assertSame('OBJECT', $this->stmt->fetchObject()); $this->assertSame('OBJECT', $this->stmt->fetchObject());
@ -175,9 +163,7 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testFetchPairs() public function testFetchPairs()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$resultMock = $this->getMockBuilder('mysqli_result') $resultMock = $this->getMockBuilder('mysqli_result')
->disableOriginalConstructor() ->disableOriginalConstructor()
@ -232,9 +218,7 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testClose() public function testClose()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$this->assertAttributeEquals(null, 'result', $this->stmt); $this->assertAttributeEquals(null, 'result', $this->stmt);
$this->setDriverGetConnectionMethod(); $this->setDriverGetConnectionMethod();
$this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val')); $this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
@ -275,9 +259,7 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
public function testNumRows() public function testNumRows()
{ {
$this->markTestSkipped('Unable to execute a method or access a property of an incomplete object.'); $this->markTestSkipped('Unable to execute a method or access a property of an incomplete object.');
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$this->setDriverGetConnectionMethod(); $this->setDriverGetConnectionMethod();
$this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val')); $this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
$this->assertNull($this->stmt->numRows()); $this->assertNull($this->stmt->numRows());
@ -289,9 +271,7 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
*/ */
public function testFetchInvalidMode() public function testFetchInvalidMode()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$this->setDriverGetConnectionMethod(); $this->setDriverGetConnectionMethod();
$this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val')); $this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));

12
tests/redis/RedisDebugTest.php

@ -57,9 +57,7 @@ class RedisDebugTest extends PHPUnit_Framework_TestCase
*/ */
public function testCallSimpleParams() public function testCallSimpleParams()
{ {
if (!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1);
$mock = $this->getMock('Redis', array('connect')); $mock = $this->getMock('Redis', array('connect'));
$mock->expects($this->once()) $mock->expects($this->once())
@ -77,9 +75,7 @@ class RedisDebugTest extends PHPUnit_Framework_TestCase
*/ */
public function testCallArrayParam() public function testCallArrayParam()
{ {
if (!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1);
$mock = $this->getMock('Redis', array('connect')); $mock = $this->getMock('Redis', array('connect'));
$mock->expects($this->once()) $mock->expects($this->once())
@ -97,9 +93,7 @@ class RedisDebugTest extends PHPUnit_Framework_TestCase
*/ */
public function testCallUndefinedMethod() public function testCallUndefinedMethod()
{ {
if (!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1);
$mock = $this->getMock('Redis', array('connect')); $mock = $this->getMock('Redis', array('connect'));
$redisDebug = new RedisDebug($mock); $redisDebug = new RedisDebug($mock);

4
tests/redis/RedisManagerTest.php

@ -107,9 +107,7 @@ class RedisManagerTest extends PHPUnit_Framework_TestCase
*/ */
public function testConnectWithDebug() public function testConnectWithDebug()
{ {
if (!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1);
$this->getMock('RedisDebug'); $this->getMock('RedisDebug');
Config::set('Redis', array('new' => array('host' => true, 'port' => 2023, 'database' => true))); Config::set('Redis', array('new' => array('host' => true, 'port' => 2023, 'database' => true)));

28
tests/util/profiler/ProfilerTest.php

@ -36,9 +36,7 @@ class ProfilerTest extends PHPUnit_Framework_TestCase
*/ */
public function testGetInstaceNoDebug() public function testGetInstaceNoDebug()
{ {
if (!defined('DEBUG')) {
define('DEBUG', false);
}
Config::set('DEBUG', 0);
$this->setExpectedException('GeneralException', 'Need to turn on DEBUG before use.'); $this->setExpectedException('GeneralException', 'Need to turn on DEBUG before use.');
Profiler::getInstance(); Profiler::getInstance();
} }
@ -48,9 +46,7 @@ class ProfilerTest extends PHPUnit_Framework_TestCase
*/ */
public function testGetInstance() public function testGetInstance()
{ {
if (!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1);
$profiler = Profiler::getInstance(); $profiler = Profiler::getInstance();
$this->assertInstanceOf('Profiler', $profiler); $this->assertInstanceOf('Profiler', $profiler);
$this->assertSame($profiler, Profiler::getInstance()); $this->assertSame($profiler, Profiler::getInstance());
@ -61,9 +57,7 @@ class ProfilerTest extends PHPUnit_Framework_TestCase
*/ */
public function testProfilerCommand() public function testProfilerCommand()
{ {
if (!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1);
$this->getMock('CommandProfiler', array('getType', 'getCommand', 'getElapsed'), array(), 'CommandProfilerMock', false); $this->getMock('CommandProfiler', array('getType', 'getCommand', 'getElapsed'), array(), 'CommandProfilerMock', false);
$profiler = Profiler::getInstance(); $profiler = Profiler::getInstance();
$cmdProfiler = $profiler->profilerCommand('command', 'type'); $cmdProfiler = $profiler->profilerCommand('command', 'type');
@ -75,9 +69,7 @@ class ProfilerTest extends PHPUnit_Framework_TestCase
*/ */
public function testStartEndNoCommandProfiler() public function testStartEndNoCommandProfiler()
{ {
if (!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1);
$profiler = Profiler::getInstance(); $profiler = Profiler::getInstance();
$profiler->start(); $profiler->start();
$result = $profiler->end('<body></body>'); $result = $profiler->end('<body></body>');
@ -95,9 +87,7 @@ class ProfilerTest extends PHPUnit_Framework_TestCase
*/ */
public function testStartEndWithCommandProfiler() public function testStartEndWithCommandProfiler()
{ {
if (!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1);
$this->getMock('CommandProfiler', array('getType', 'getCommand', 'getElapsed'), array(), 'CommandProfilerMock', false); $this->getMock('CommandProfiler', array('getType', 'getCommand', 'getElapsed'), array(), 'CommandProfilerMock', false);
$profiler = Profiler::getInstance(); $profiler = Profiler::getInstance();
@ -115,9 +105,7 @@ class ProfilerTest extends PHPUnit_Framework_TestCase
*/ */
public function testGetJSON() public function testGetJSON()
{ {
if (!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1);
$this->getMock('CommandProfiler', array('getType', 'getCommand', 'getElapsed'), array(), 'CommandProfilerMock', false); $this->getMock('CommandProfiler', array('getType', 'getCommand', 'getElapsed'), array(), 'CommandProfilerMock', false);
$profiler = Profiler::getInstance(); $profiler = Profiler::getInstance();
@ -130,9 +118,7 @@ class ProfilerTest extends PHPUnit_Framework_TestCase
*/ */
public function testGetCLI() public function testGetCLI()
{ {
if (!defined('DEBUG')) {
define('DEBUG', true);
}
Config::set('DEBUG', 1);
$this->getMock('CommandProfiler', array('getType', 'getCommand', 'getElapsed'), array(), 'CommandProfilerMock', false); $this->getMock('CommandProfiler', array('getType', 'getCommand', 'getElapsed'), array(), 'CommandProfilerMock', false);
$profiler = Profiler::getInstance(); $profiler = Profiler::getInstance();

2
util/profiler/Profiler.php

@ -22,7 +22,7 @@ class Profiler
private function __construct() private function __construct()
{ {
if (DEBUG == false) {
if (Config::get('DEBUG') == false) {
throw new GeneralException('Need to turn on DEBUG before use.'); throw new GeneralException('Need to turn on DEBUG before use.');
} }
} }

Loading…
Cancel
Save