Browse Source

merge mongo with master

master
Anton Grebnev 13 years ago
parent
commit
47b5843ef6
  1. 1
      .gitignore
  2. 2
      Config.php
  3. 2
      app/router/Route.php
  4. 2
      cache/Cacher.php
  5. 2
      cache/MemcacheCache.php
  6. 12
      exception/InitializationException.php
  7. 2
      form/Form.php
  8. 6
      form/FormField.php
  9. 2
      form/FormViewHelper.php
  10. 4
      i18n/I18N.php
  11. 7
      model/Db.php
  12. 2
      model/DbDriver.php
  13. 4
      model/DbStatement.php
  14. 2
      model/MySQLiDriver.php
  15. 4
      model/MySQLiStatement.php
  16. 6
      redis/RedisDebug.php
  17. 11
      redis/RedisManager.php
  18. 13
      tests/ConfigTest.php
  19. 10
      tests/LoadTest.php
  20. 28
      tests/MySQLTestsSuite.php
  21. 27
      tests/RedisTestsSuite.php
  22. 13
      tests/RegistryTest.php
  23. 6
      tests/app/ActionTest.php
  24. 8
      tests/app/AjaxActionTest.php
  25. 14
      tests/app/ErrorActionTest.php
  26. 6
      tests/app/FrontControllerTest.php
  27. 24
      tests/app/PagerActionTest.php
  28. 4
      tests/app/StaticActionTest.php
  29. 17
      tests/app/router/RouteTest.php
  30. 16
      tests/app/router/RouterTest.php
  31. 4
      tests/cache/CacheKeyTest.php
  32. 6
      tests/cache/CacherTest.php
  33. 22
      tests/cache/MemcacheCacheTest.php
  34. 8
      tests/captcha/CaptchaTest.php
  35. 4
      tests/captcha/CaptchaValidatorTest.php
  36. 48
      tests/classes/EnvTest.php
  37. 74
      tests/classes/FormatTest.php
  38. 11
      tests/exception/Error404ExceptionTest.php
  39. 13
      tests/exception/ErrorHandlerTest.php
  40. 11
      tests/exception/GeneralExceptionTest.php
  41. 28
      tests/exception/InitializationExceptionTest.php
  42. 11
      tests/form/FormFieldTest.php
  43. 6
      tests/form/FormTest.php
  44. 8
      tests/form/FormViewHelperTest.php
  45. 22
      tests/i18n/I18NTest.php
  46. 8
      tests/layout/LayoutTest.php
  47. 7
      tests/logger/FileLoggerTest.php
  48. 3
      tests/model/DbExprTest.php
  49. 9
      tests/model/DbStatementTest.php
  50. 31
      tests/model/DbTest.php
  51. 60
      tests/model/MySQLiDriverTest.php
  52. 40
      tests/model/MySQLiStatementTest.php
  53. 41
      tests/model/SqlDbDriverTest.php
  54. 23
      tests/model/SqlModelTest.php
  55. 25
      tests/phpunit.xml
  56. 16
      tests/redis/RedisDebugTest.php
  57. 31
      tests/redis/RedisManagerTest.php
  58. 22
      tests/session/SessionTest.php
  59. 8
      tests/util/AutoloadBuilderTest.php
  60. 4
      tests/util/AutoloadBuilderTestVFS.php
  61. 4
      tests/util/profiler/CommandProfilerTest.php
  62. 5
      tests/util/profiler/ProfilerTest.php
  63. 6
      tests/validator/EqualValidatorTest.php
  64. 18
      tests/validator/RegexValidatorTest.php
  65. 23
      tests/view/PHPViewTest.php
  66. 12
      tests/view/helpers/GetViewHelperTest.php
  67. 9
      tests/view/helpers/MsgViewHelperTest.php
  68. 2
      validator/EqualValidator.php
  69. 2
      validator/RegexValidator.php
  70. 2
      validator/Validator.php
  71. 4
      view/PHPView.php
  72. 2
      view/helpers/MsgViewHelper.php

1
.gitignore

@ -3,3 +3,4 @@
/.cache
/tests/report
*~
/.idea

2
Config.php

@ -33,7 +33,7 @@ class ConfigArray extends ArrayObject
public function offsetGet($index)
{
if (!$this->offsetExists($index)) {
throw new Exception('Configuration variable "' . $index . '" undefined');
throw new GeneralException('Configuration variable "' . $index . '" undefined');
}
return parent::offsetGet($index);
}

2
app/router/Route.php

@ -32,7 +32,6 @@ class Route
{
$parts = explode('/', $this->route);
$cnt = count($parts);
if(count($request) != $cnt) {
return false;
}
@ -52,6 +51,7 @@ class Route
return false;
}
}
return true;
}

2
cache/Cacher.php

@ -27,7 +27,7 @@ class Cacher
}
$cache = new $cacher($config);
if (!$cache instanceof Cache) {
throw new Exception('Cache driver "' . $cacher . '" must extends Cache');
throw new InitializationException('Cache driver "' . $cacher . '" must extends Cache');
}
self::$caches[$cacher] = $cache;
}

2
cache/MemcacheCache.php

@ -40,7 +40,7 @@ class MemcacheCache extends Cache
foreach ($config as $c) {
foreach ($required as $option) {
if (!isset($c[$option])) {
throw new Exception('Configuration must have a "' . $option . '".');
throw new InitializationException('Configuration must have a "' . $option . '".');
}
}
$this->connection->addServer($c['hostname'], $c['port']);

12
exception/InitializationException.php

@ -0,0 +1,12 @@
<?php
/**
* @copyright NetMonsters <team@netmonsters.ru>
* @link http://netmonsters.ru
* @package Majestic
* @subpackage exception
* @since 2011-11-24
*
* Exception from initializtion object
*/
class InitializationException extends Exception {}

2
form/Form.php

@ -39,7 +39,7 @@ abstract class Form
public function isValid($data)
{
if (!is_array($data)) {
throw new Exception(__CLASS__ . '::' . __METHOD__ . ' expects an array');
throw new InitializationException(__CLASS__ . '::' . __METHOD__ . ' expects an array');
}
foreach ($this->fields as $field_name => $field) {

6
form/FormField.php

@ -72,7 +72,7 @@ class FormField
$name = $validator . 'Validator';
$validator = new $name();
} else {
throw new Exception('Invalid validator provided to addValidator; must be string or iValidator');
throw new InitializationException('Invalid validator provided to addValidator; must be string or iValidator');
}
$this->validators[$name] = $validator;
return $this;
@ -94,7 +94,7 @@ class FormField
$name = $filter . 'Filter';
$filter = new $name();
} else {
throw new Exception('Invalid filter provided to addFilter; must be string or iFilter');
throw new InitializationException('Invalid filter provided to addFilter; must be string or iFilter');
}
$this->filters[$name] = $filter;
return $this;
@ -147,7 +147,7 @@ class FormField
if (!$validator->isValid($val, $context)) {
$valid = false;
if (!$this->default_message) {
throw new Exception('Define default message for array fields');
throw new InitializationException('Define default message for array fields');
}
$this->message = $this->default_message;
}

2
form/FormViewHelper.php

@ -18,7 +18,7 @@ class FormViewHelper extends ViewHelper
{
if ($this->data === null) {
if ($form == null) {
throw new Exception('Form name required for helper init');
throw new InitializationException('Form name required for helper init');
}
$this->data = Session::get($form, array());
Session::del($form);

4
i18n/I18N.php

@ -29,6 +29,10 @@ class I18N
{
$config = Config::get(__CLASS__);
if (!is_array($config['locales'])) {
throw new InitializationException('key \'locales\' array\'s config is empty');
}
self::$locales = $config['locales'];
if (isset($config['bidi'])) {

7
model/Db.php

@ -36,11 +36,14 @@ class Db
{
if (!isset(self::$connections[$name])) {
if (!$config) {
if (!is_object(Config::get(__CLASS__))) {
throw new InitializationException('Trying to get property of non-object');
}
$config = Config::get(__CLASS__)->$name;
}
if (!is_array($config)) {
throw new Exception('Connection parameters must be an array');
throw new InitializationException('Connection parameters must be an array');
}
$driver = 'MySQLiDriver';
@ -52,7 +55,7 @@ class Db
$connection = new $driver($config);
if (!$connection instanceof DbDriver) {
throw new Exception('Database driver must extends DbDriver');
throw new InitializationException('Database driver must extends DbDriver');
}
self::$connections[$name] = $connection;
}

2
model/DbDriver.php

@ -38,7 +38,7 @@ abstract class DbDriver
$required = array('database', 'username', 'password', 'hostname');
foreach ($required as $option) {
if (!isset($config[$option])) {
throw new Exception('Configuration must have a "' . $option . '".');
throw new GeneralException('Configuration must have a "' . $option . '".');
}
}
}

4
model/DbStatement.php

@ -28,8 +28,8 @@ abstract class DbStatement
public function __construct($driver, $request)
{
$this->driver = $driver;
$this->request = $request;
$this->driver = $driver;
$this->request = $request;
}
/**

2
model/MySQLiDriver.php

@ -80,7 +80,7 @@ class MySQLiDriver extends SqlDbDriver
$port);
// Connection errors check
if (mysqli_connect_error()) {
throw new Exception(mysqli_connect_error(), mysqli_connect_errno());
throw new GeneralException(mysqli_connect_error(), mysqli_connect_errno());
}
$charset = (!empty($this->config['charset'])) ? $this->config['charset'] : 'utf8';

4
model/MySQLiStatement.php

@ -105,7 +105,7 @@ class MySQLiStatement extends DbStatement
$row = $this->result->fetch_array(MYSQLI_BOTH);
break;
default:
throw new Exception('Invalid fetch mode "' . $style . '" specified');
throw new GeneralException('Invalid fetch mode "' . $style . '" specified');
}
return $row;
}
@ -166,7 +166,7 @@ class MySQLiStatement extends DbStatement
}
if ($result === false) {
$message = $mysqli->error . "\nQuery: \"" . $request . '"';
throw new Exception($message, $mysqli->errno);
throw new GeneralException($message, $mysqli->errno);
}
if ($result instanceof MySQLi_Result) {
$this->result = $result;

6
redis/RedisDebug.php

@ -25,6 +25,12 @@ class RedisDebug
{
$command = $this->r_implode(', ', $arguments);
$profiler = Profiler::getInstance()->profilerCommand('Redis->' . $name, $command);
$search = array_search($name, get_class_methods($this->redis));
if (empty($search)) {
throw new GeneralException('undefined method:'.$name);
}
$data = call_user_func_array(array($this->redis, $name), $arguments);
$profiler->end();
return $data;

11
redis/RedisManager.php

@ -31,11 +31,14 @@ class RedisManager
{
if (!isset(self::$connections[$name])) {
if (!$config) {
$config = Config::get('Redis')->$name;
if (!is_object(Config::get('Redis'))) {
throw new GeneralException('Redis config no existence');
}
$config = Config::get('Redis')->$name;
}
if (!is_array($config)) {
throw new Exception('Connection parameters must be an array');
throw new GeneralException('Connection parameters must be an array');
}
$host = isset($config['host']) ? $config['host'] : 'localhost';
@ -50,11 +53,11 @@ class RedisManager
$connection = new RedisDebug($connection);
}
if (!$connection->connect($host, $port)) {
throw new Exception('Failed to connect to Redis server at ' . $host . ':' . $port);
throw new GeneralException('Failed to connect to Redis server at ' . $host . ':' . $port);
}
if ($database) {
if (!$connection->select($database)) {
throw new Exception('Failed to select Redis database with index ' . $database);
throw new GeneralException('Failed to select Redis database with index ' . $database);
}
}
self::$connections[$name] = $connection;

13
tests/ConfigTest.php

@ -12,6 +12,7 @@
require_once dirname(__FILE__) . '/../Registry.php';
require_once dirname(__FILE__) . '/../Config.php';
require_once dirname(__FILE__) . '/../exception/GeneralException.php';
class ConfigTest extends PHPUnit_Framework_TestCase
{
@ -33,10 +34,6 @@ class ConfigTest extends PHPUnit_Framework_TestCase
$this->assertNotEquals('Config', get_class(Config::getInstance()));
}
/**
* @expectedException Exception
* @expectedExceptionMessage Configuration variable
*/
public function testArrayAsParam()
{
$arr = array(
@ -45,14 +42,14 @@ class ConfigTest extends PHPUnit_Framework_TestCase
'three' => 3,
4 => 'four'
);
Config::set(0, $arr);
$new_arr = Config::get(0);
$this->assertEquals('ConfigArray', get_class($new_arr));
$this->assertEquals('four', $new_arr->offsetGet(4));
$this->assertEquals(1, $new_arr->one);
$this->assertSame('ConfigArray', get_class($new_arr));
$this->assertSame('four', $new_arr->offsetGet(4));
$this->assertSame(1, $new_arr->one);
$this->assertNotEquals(1, $new_arr->offsetGet('two'));
$this->setExpectedException('GeneralException', 'Configuration variable');
$new_arr->some;
}

10
tests/LoadTest.php

@ -84,7 +84,7 @@ class LoadTest extends PHPUnit_Framework_TestCase
Load::setAutoloadFrom(self::$file);
$autoload = require(self::$file);
$this->assertEquals(self::$autoload_array, $autoload);
$this->assertSame(self::$autoload_array, $autoload);
Load::autoload('Db');
}
@ -100,7 +100,7 @@ class LoadTest extends PHPUnit_Framework_TestCase
Load::setAutoloadFrom(self::$file);
$autoload = require(self::$file);
$this->assertEquals(self::$autoload_array, $autoload);
$this->assertSame(self::$autoload_array, $autoload);
}
public function testAutoloadArrayExists()
@ -109,6 +109,7 @@ class LoadTest extends PHPUnit_Framework_TestCase
}
/**
* @runInSeparateProcess
* @TODO: Load - check if input file returns array
*/
public function testFileForArray()
@ -117,6 +118,9 @@ class LoadTest extends PHPUnit_Framework_TestCase
$this->assertInternalType('array', $autoload);
}
/**
* @runInSeparateProcess
*/
public function testAutoloadArrayNotEmpty()
{
$autoload = require(self::$file);
@ -136,7 +140,6 @@ class LoadTest extends PHPUnit_Framework_TestCase
/**
* @TODO: Load::getFilePath - check for wrong index
* @expectedException PHPUnit_Framework_Error
* @runInSeparateProcess
*/
public function testAutoloadGetFilePathNullIndex()
@ -144,6 +147,7 @@ class LoadTest extends PHPUnit_Framework_TestCase
$this->setConstants();
Load::setAutoloadFrom(self::$file);
$autoload = require(self::$file);
$this->setExpectedException('PHPUnit_Framework_Error');
$this->assertNotEmpty(Load::getFilePath('anton'));
}

28
tests/MySQLTestsSuite.php

@ -0,0 +1,28 @@
<?php
/*
* @copyright NetMonsters <team@netmonsters.ru>
* @link http://netmonsters.ru
* @package Majestic
* @subpackage UnitTests
* @since 2011-12-02
*
* Test set for MySQL
*/
require_once 'model/MySQLiDriverTest.php';
require_once 'model/MySQLiStatementTest.php';
class PackageMySQLTests
{
public static function suite()
{
$suite = new PHPUnit_Framework_TestSuite('MySQL');
$suite->addTestSuite('MySQLiDriverTest');
$suite->addTestSuite('MySQLiStatementTest');
return $suite;
}
}

27
tests/RedisTestsSuite.php

@ -0,0 +1,27 @@
<?php
/*
* @copyright NetMonsters <team@netmonsters.ru>
* @link http://netmonsters.ru
* @package Majestic
* @subpackage UnitTests
* @since 2011-12-02
*
* Test set for Redis
*/
require_once 'redis/RedisDebugTest.php';
require_once 'redis/RedisManagerTest.php';
class PackageRedisTests
{
public static function suite()
{
$suite = new PHPUnit_Framework_TestSuite('Redis');
$suite->addTestSuite('RedisDebugTest');
$suite->addTestSuite('RedisManagerTest');
return $suite;
}
}

13
tests/RegistryTest.php

@ -45,27 +45,28 @@ class RegistryTest extends PHPUnit_Framework_TestCase
{
Registry::set(1, 1);
Registry::set('two', 2);
$this->assertEquals(Registry::get(1), $this->_registry->get(1));
$this->assertEquals(2, Registry::get('two'));
$this->assertSame(Registry::get(1), $this->_registry->get(1));
$this->assertSame(2, Registry::get('two'));
}
public function testGet()
{
$this->assertEquals(Registry::get(1), $this->_registry->get(1));
$this->assertEquals(Registry::get('two'), 2);
$this->assertSame(Registry::get(1), $this->_registry->get(1));
$this->assertSame(Registry::get('two'), 2);
$this->assertNull(Registry::get(4));
}
/**
* @TODO: Registry::isRegistered - check input for null
* @expectedException PHPUnit_Framework_Error
*/
public function testIsRegistered()
{
$this->assertFalse(Registry::isRegistered(43));
$this->_registry->set(3, 'three');
$this->assertTrue(Registry::isRegistered(3));
$this->setExpectedException('PHPUnit_Framework_Error');
$this->assertFalse(Registry::isRegistered(null));
}
}

6
tests/app/ActionTest.php

@ -25,7 +25,7 @@ class ActionTest extends Action_TestCase
}
Env::setParams(array('param1' => 'value1', 'param2' => 'value2'));
$action = $this->getMockForAbstractClass('Action' );
$this->assertEquals('value1', $action->param1);
$this->assertSame('value1', $action->param1);
}
/**
@ -45,7 +45,7 @@ class ActionTest extends Action_TestCase
$controller->setView('SomeView');
$action = $this->getMockForAbstractClass('Action', array(), 'ActionMock');
$result = $action->fetch();
$this->assertEquals('/actions/to/SomeTemplate', $result['template']);
$this->assertSame('/actions/to/SomeTemplate', $result['template']);
}
/**
@ -61,7 +61,7 @@ class ActionTest extends Action_TestCase
$controller->setView('SomeView');
$action = $this->getMockForAbstractClass('Action', array(), 'ActionMock');
$result = $action->fetch();
$this->assertEquals('/actions//Acti', $result['template']);
$this->assertSame('/actions//Acti', $result['template']);
}
/**

8
tests/app/AjaxActionTest.php

@ -42,8 +42,8 @@ class AjaxActionTest extends Action_TestCase
$action = $this->getMockForAbstractClass('AjaxAction' );
$action->data = array('var' => 'val');
$result = $action->fetch();
$this->assertEquals('/actions//ajax', $result['template']);
$this->assertEquals('{"var":"val"}', $result['data']);
$this->assertSame('/actions//ajax', $result['template']);
$this->assertSame('{"var":"val"}', $result['data']);
}
/**
@ -60,7 +60,7 @@ class AjaxActionTest extends Action_TestCase
$action = $this->getMockForAbstractClass('AjaxAction' );
$action->data = array('var' => 'val');
$result = $action->fetch();
$this->assertEquals('/actions//ajax', $result['template']);
$this->assertEquals( $action->data, $result['data']);
$this->assertSame('/actions//ajax', $result['template']);
$this->assertSame( $action->data, $result['data']);
}
}

14
tests/app/ErrorActionTest.php

@ -38,7 +38,7 @@ class ErrorActionTest extends Action_TestCase
$this->setConstants(false);
$exception = $this->getMock('ErrorException', array(), array('', 0, E_NOTICE));
$action = new ErrorAction($exception);
$this->assertEquals($exception, $action->exception);
$this->assertSame($exception, $action->exception);
}
/**
@ -49,7 +49,7 @@ class ErrorActionTest extends Action_TestCase
$this->setConstants(false);
$exception = $this->getMock('ErrorException', array(), array('', 0, E_WARNING));
$action = new ErrorAction($exception);
$this->assertEquals($exception, $action->exception);
$this->assertSame($exception, $action->exception);
}
/**
@ -60,7 +60,7 @@ class ErrorActionTest extends Action_TestCase
$this->setConstants(false);
$exception = $this->getMock('ErrorException', array(), array('', 0, E_ERROR));
$action = new ErrorAction($exception);
$this->assertEquals($exception, $action->exception);
$this->assertSame($exception, $action->exception);
}
/**
@ -71,7 +71,7 @@ class ErrorActionTest extends Action_TestCase
$this->setConstants(false);
$exception = $this->getMock('ErrorException', array(), array('', 0, 211));
$action = new ErrorAction($exception);
$this->assertEquals($exception, $action->exception);
$this->assertSame($exception, $action->exception);
}
@ -88,7 +88,7 @@ class ErrorActionTest extends Action_TestCase
$controller->setView('SomeView');
$action = new ErrorAction($exception);
$result = $action->fetch();
$this->assertEquals('/actions/500', $result['template']);
$this->assertSame('/actions/500', $result['template']);
}
/**
@ -103,7 +103,7 @@ class ErrorActionTest extends Action_TestCase
->will($this->returnValue(array('one' => array('class' => 'AjaxAction'))));
$action = new ErrorAction($exception);
$this->assertEquals($exception, $action->exception);
$this->assertSame($exception, $action->exception);
}
/**
@ -118,7 +118,7 @@ class ErrorActionTest extends Action_TestCase
->will($this->returnValue(array('one' => array('class' => 'Action'))));
$action = new ErrorAction($exception);
$this->assertEquals($exception, $action->exception);
$this->assertSame($exception, $action->exception);
}
private function setConstants($val = false)

6
tests/app/FrontControllerTest.php

@ -79,7 +79,7 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase
{
$this->setConstants(false);
$controller = FrontController::getInstance();
$this->assertEquals($controller, $controller->setView('View'));
$this->assertSame($controller, $controller->setView('View'));
}
/**
@ -110,9 +110,9 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase
{
$this->setConstants(false);
$controller = FrontController::getInstance();
$this->assertEquals('', $controller->getBaseUrl());
$this->assertSame('', $controller->getBaseUrl());
$controller->setBaseUrl('/index/');
$this->assertEquals('/index', $controller->getBaseUrl());
$this->assertSame('/index', $controller->getBaseUrl());
}
/**

24
tests/app/PagerActionTest.php

@ -25,9 +25,9 @@ class PagerActionTest extends Action_TestCase
define('DEBUG', false);
}
$action = $this->getMockForAbstractClass('PagerAction');
$this->assertEquals(20, $action->getLimit());
$this->assertSame(20, $action->getLimit());
$action = $this->getMockForAbstractClass('PagerAction', array(50));
$this->assertEquals(50, $action->getLimit());
$this->assertSame(50, $action->getLimit());
}
/**
@ -40,19 +40,19 @@ class PagerActionTest extends Action_TestCase
}
$action = $this->getMockForAbstractClass('PagerAction');
$action->setCount(50);
$this->assertEquals(1, $action->page);
$this->assertEquals(0, $action->getOffset());
$this->assertSame(1, $action->page);
$this->assertSame(0, $action->getOffset());
$_GET['p'] = 'last';
$action->setCount(50);
$this->assertEquals(3, $action->page);
$this->assertEquals(40, $action->getOffset());
$this->assertSame(3.0, $action->page);
$this->assertSame(40, $action->getOffset());
$_GET['p'] = 2;
$action->setCount(50);
$this->assertEquals(2, $action->page);
$this->assertEquals(20, $action->getOffset());
$this->assertSame(2, $action->page);
$this->assertSame(20, $action->getOffset());
$_GET['p'] = -3;
$action->setCount(50);
$this->assertEquals(1, $action->page);
$this->assertSame(1, $action->page);
}
/**
@ -64,7 +64,7 @@ class PagerActionTest extends Action_TestCase
define('DEBUG', false);
}
$action = $this->getMockForAbstractClass('PagerAction');
$this->assertEquals(0, $action->getOffset());
$this->assertSame(0, $action->getOffset());
}
/**
@ -80,7 +80,7 @@ class PagerActionTest extends Action_TestCase
$controller->setView('SomeView');
$action = $this->getMockForAbstractClass('PagerAction', array(), 'PagerActionMock');
$result = $action->fetch();
$this->assertEquals('/actions/PagerActi', $result['template']);
$this->assertSame('/actions/PagerActi', $result['template']);
}
/**
@ -96,6 +96,6 @@ class PagerActionTest extends Action_TestCase
$controller->setView('SomeView');
$action = $this->getMockForAbstractClass('PagerAction');
$result = $action->fetch();
$this->assertEquals('/actions/SomeTemplate', $result['template']);
$this->assertSame('/actions/SomeTemplate', $result['template']);
}
}

4
tests/app/StaticActionTest.php

@ -29,7 +29,7 @@ class StaticActionTest extends Action_TestCase
$controller->setView('SomeView');
$action = $this->getMockForAbstractClass('StaticAction', array(), 'StaticActionMock');
$result = $action->fetch();
$this->assertEquals('/static/StaticActi', $result['template']);
$this->assertSame('/static/StaticActi', $result['template']);
}
/**
@ -45,6 +45,6 @@ class StaticActionTest extends Action_TestCase
$controller->setView('SomeView');
$action = $this->getMockForAbstractClass('StaticAction', array(), 'StaticActionMock');
$result = $action->fetch();
$this->assertEquals('/static/SomeTemplate', $result['template']);
$this->assertSame('/static/SomeTemplate', $result['template']);
}
}

17
tests/app/router/RouteTest.php

@ -18,8 +18,8 @@ class RouteTest extends PHPUnit_Framework_TestCase
public function testConstructNoParams()
{
$route = new Route('index', 'user');
$this->assertEquals('userAction', $route->getAction());
$this->assertEquals('Layout', $route->getLayout());
$this->assertSame('userAction', $route->getAction());
$this->assertSame('Layout', $route->getLayout());
$this->assertEmpty($route->getParams());
$this->assertAttributeEquals('index', 'route', $route);
}
@ -28,7 +28,7 @@ class RouteTest extends PHPUnit_Framework_TestCase
{
$route = new Route('index', 'user', array('name' => 'tony', 'role' => 'user'));
$this->assertArrayHasKey('role', $route->getParams());
$this->assertEquals(array('name' => 'tony', 'role' => 'user'), $route->getParams());
$this->assertSame(array('name' => 'tony', 'role' => 'user'), $route->getParams());
}
public function testMatchDiffCount()
@ -50,30 +50,31 @@ class RouteTest extends PHPUnit_Framework_TestCase
{
$route = new Route('user/account/:id', 'user');
$this->assertTrue($route->match(array('user', 'account', '142')));
$this->assertEquals(array('id' => '142'), $route->getParams());
$this->assertSame(array('id' => '142'), $route->getParams());
}
public function testMatchDiffPregParts()
{
$route = new Route('user/account/(?<key>value)', 'user');
$this->assertFalse($route->match(array('user', 'account', 'wrong')));
$this->assertEquals(0, count($route->getParams()));
$this->assertSame(0, count($route->getParams()));
}
public function testMatchPregPasses()
{
$route = new Route('user/account/(?<key>[a-z]+)', 'user');
$this->assertTrue($route->match(array('user', 'account', 'value')));
$this->assertEquals(array('key' => 'value'), $route->getParams());
$this->assertEquals(1, count($route->getParams()));
$this->assertSame(array('key' => 'value'), $route->getParams());
$this->assertSame(1, count($route->getParams()));
}
/**
* @expectedException Exception
* @TODO Need check empty parameters from constructor Route
*/
public function testMatchEmptyRequest()
{
$route = new Route('', 'user', array('name' => 'tony', 'role' => 'user'));
$this->setExpectedException('PHPUnit_Framework_Error');
$route->match('');
}
}

16
tests/app/router/RouterTest.php

@ -28,9 +28,9 @@ class RouterTest extends PHPUnit_Framework_TestCase
$router = new Router();
$router->add('user', 'user/account/:id', 'user');
$route = $router->route('user/account/213');
$this->assertEquals(1, count($route->getParams()));
$this->assertEquals(array('id' => 213), $route->getParams());
$this->assertEquals('user', $router->getRouteName());
$this->assertSame(1, count($route->getParams()));
$this->assertSame(array('id' => '213'), $route->getParams());
$this->assertSame('user', $router->getRouteName());
}
public function testRouterMultipleRoutes()
@ -39,12 +39,12 @@ class RouterTest extends PHPUnit_Framework_TestCase
$router->add('user', 'user/account/:id', 'user');
$router->add('sale', 'sale/order/:id', 'user');
$route = $router->route('user/account/213');
$this->assertEquals('user', $router->getRouteName());
$this->assertEquals(1, count($route->getParams()));
$this->assertEquals(array('id' => 213), $route->getParams());
$this->assertSame('user', $router->getRouteName());
$this->assertSame(1, count($route->getParams()));
$this->assertSame(array('id' => '213'), $route->getParams());
$route = $router->route('sale/order/22');
$this->assertEquals('sale', $router->getRouteName());
$this->assertEquals(array('id' => 22), $route->getParams());
$this->assertSame('sale', $router->getRouteName());
$this->assertSame(array('id' => '22'), $route->getParams());
}
public function testRouteNotmatch()

4
tests/cache/CacheKeyTest.php

@ -49,7 +49,7 @@ class CacheKeyTest extends PHPUnit_Framework_TestCase
$getExpireMethod = new ReflectionMethod('CacheKey', 'getExpire');
$getExpireMethod->setAccessible(TRUE);
$this->assertEquals(100, $getExpireMethod->invoke($this->cache));
$this->assertSame(100, $getExpireMethod->invoke($this->cache));
}
public function testGetSet()
@ -66,7 +66,7 @@ class CacheKeyTest extends PHPUnit_Framework_TestCase
$this->cache = new CacheKey($mockCacher, 'any');
$this->cache->set('some');
$this->assertEquals('some', $this->cache->get());
$this->assertSame('some', $this->cache->get());
}
public function testDel()

6
tests/cache/CacherTest.php

@ -15,6 +15,7 @@ require_once dirname(__FILE__) . '/../../cache/Cache.php';
require_once dirname(__FILE__) . '/../../cache/Cacher.php';
require_once dirname(__FILE__) . '/../../Registry.php';
require_once dirname(__FILE__) . '/../../Config.php';
require_once dirname(__FILE__) . '/../../exception/InitializationException.php';
class CacherTest extends PHPUnit_Framework_TestCase
{
@ -26,12 +27,9 @@ class CacherTest extends PHPUnit_Framework_TestCase
set_new_overload(array($this, 'newCallback'));
}
/**
* @expectedException Exception
* @expectedExcepptionMessage Cache driver
*/
public function testNotExtendsCache()
{
$this->setExpectedException('InitializationException', 'Cache driver');
Cacher::get('Cacher');
}

22
tests/cache/MemcacheCacheTest.php

@ -15,6 +15,7 @@
require_once dirname(__FILE__) . '/../../cache/Cache.php';
require_once dirname(__FILE__) . '/../../cache/MemcacheCache.php';
require_once dirname(__FILE__) . '/../../exception/InitializationException.php';
class MemcacheCacheTest extends PHPUnit_Framework_TestCase
{
@ -35,15 +36,10 @@ class MemcacheCacheTest extends PHPUnit_Framework_TestCase
$this->assertAttributeInstanceOf('TestCache', 'connection', $memcache);
}
/**
* @expectedException Exception
* @expectedExceptionMessage Configuration must have a
* @TODO: MemcacheCache::__construct - empty config array passes with no host params
*/
public function testWrongConfig()
{
$config = array('some' => array());
$this->setExpectedException('InitializationException', 'Configuration must have a');
$memcache = new MemcacheCache($config);
}
@ -51,7 +47,7 @@ class MemcacheCacheTest extends PHPUnit_Framework_TestCase
{
$memcache = new MemcacheCache(array());
$this->assertTrue($memcache->add('key', 'value'));
$this->assertEquals('value', $memcache->get('key'));
$this->assertSame('value', $memcache->get('key'));
$this->assertFalse($memcache->add('key', 'newvalue'));
}
@ -64,9 +60,9 @@ class MemcacheCacheTest extends PHPUnit_Framework_TestCase
$memcache->add('three', 'three');
$this->assertTrue($memcache->increment('one'));
$this->assertEquals(2, $memcache->get('one'));
$this->assertSame(2, $memcache->get('one'));
$this->assertTrue($memcache->decrement('two'));
$this->assertEquals(1, $memcache->get('two'));
$this->assertSame(1, $memcache->get('two'));
$this->assertFalse($memcache->decrement('three'));
}
@ -79,7 +75,7 @@ class MemcacheCacheTest extends PHPUnit_Framework_TestCase
$memcache->add('two', 2);
$memcache->del('one');
$this->assertEquals(2, $memcache->get('two'));
$this->assertSame(2, $memcache->get('two'));
$this->assertFalse($memcache->get('one'));
}
@ -91,7 +87,7 @@ class MemcacheCacheTest extends PHPUnit_Framework_TestCase
$memcache->add('two', 2);
$memcache->add('three', 'three');
$this->assertEquals('three', 'three');
$this->assertSame('three', 'three');
$memcache->flush();
@ -109,8 +105,8 @@ class MemcacheCacheTest extends PHPUnit_Framework_TestCase
$memcache->set('one', 30);
$memcache->replace('three', 3);
$this->assertEquals(30, $memcache->get('one'));
$this->assertEquals(3, $memcache->get('three'));
$this->assertSame(30, $memcache->get('one'));
$this->assertSame(3, $memcache->get('three'));
}
protected function newCallback($className)

8
tests/captcha/CaptchaTest.php

@ -68,9 +68,9 @@ class CaptchaTest extends PHPUnit_Framework_TestCase
$code = Session::get('_ccode');
$this->assertNotEmpty($token);
$this->assertNotEmpty($code);
$this->assertEquals(5, strlen($code));
$this->assertEquals(Session::get('_ctoken'), $token);
$this->assertEquals(32, strlen($token));
$this->assertSame(5, strlen($code));
$this->assertSame(Session::get('_ctoken'), $token);
$this->assertSame(32, strlen($token));
}
public function testCheckCode()
@ -78,7 +78,7 @@ class CaptchaTest extends PHPUnit_Framework_TestCase
$token = Session::get('_ctoken');
$code = Session::get('_ccode');
$this->assertFalse($this->captcha->checkCode($token . 'asd', $code));
$this->assertEquals(Session::get('_ctoken'), $token);
$this->assertSame(Session::get('_ctoken'), $token);
$this->assertTrue($this->captcha->checkCode($token, $code));
$this->assertNull(Session::get('_ctoken'));
}

4
tests/captcha/CaptchaValidatorTest.php

@ -31,13 +31,13 @@ class CaptchaValidatorTest extends PHPUnit_Framework_TestCase
$validator = new CaptchaValidator();
$this->assertTrue($validator->isValid(null, array('ctoken' => $token, 'ccode' => $code)));
$this->assertFalse($validator->isValid(null, array('ctoken' => $token . 'asd', 'ccode' => $code)));
$this->assertEquals('Entered code wrong', $validator->getMessage());
$this->assertSame('Entered code wrong', $validator->getMessage());
}
public function testIsValidInvalid()
{
$validator = new CaptchaValidator();
$this->assertFalse($validator->isValid(null, array()));
$this->assertEquals('Entered code wrong', $validator->getMessage());
$this->assertSame('Entered code wrong', $validator->getMessage());
}
}

48
tests/classes/EnvTest.php

@ -28,9 +28,9 @@ class EnvTest extends PHPUnit_Framework_TestCase
define('DEBUG', false);
}
$_SERVER['REQUEST_URI'] = '/test/index.php?id=1&test=wet&id_theme=512';
$this->assertEquals('/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';
$this->assertEquals('/test/index.php', Env::getRequestUri());
$this->assertSame('/test/index.php', Env::getRequestUri());
}
/**
@ -48,13 +48,13 @@ class EnvTest extends PHPUnit_Framework_TestCase
FrontController::getInstance()->setBaseUrl('/test');
$_SERVER['REQUEST_URI'] = '/test/index.php?id=1&test=wet&id_theme=512';
$this->assertEquals('/index.php', Env::getRequestUri(true));
$this->assertSame('/index.php', Env::getRequestUri(true));
}
public function testServer()
{
$this->assertEquals($_SERVER, Env::Server());
$this->assertEquals($_SERVER['DOCUMENT_ROOT'], Env::Server('DOCUMENT_ROOT'));
$this->assertSame($_SERVER, Env::Server());
$this->assertSame($_SERVER['DOCUMENT_ROOT'], Env::Server('DOCUMENT_ROOT'));
$this->assertNotEmpty(Env::Server());
$this->assertArrayHasKey('DOCUMENT_ROOT', Env::Server());
}
@ -63,52 +63,52 @@ class EnvTest extends PHPUnit_Framework_TestCase
{
$this->assertTrue(Env::setCookie('var', 'value', 20));
$_COOKIE['var'] = 'value';
$this->assertEquals(array('var' => 'value'), Env::Cookie());
$this->assertEquals('value', Env::Cookie('var'));
$this->assertEquals('default', Env::Cookie('new', 'default'));
$this->assertSame(array('var' => 'value'), Env::Cookie());
$this->assertSame('value', Env::Cookie('var'));
$this->assertSame('default', Env::Cookie('new', 'default'));
}
public function testPost()
{
$_POST['var'] = 'value';
$this->assertEquals(array('var' => 'value'), Env::Post());
$this->assertEquals('value', Env::Post('var'));
$this->assertEquals('default', Env::Post('new', 'default'));
$this->assertSame(array('var' => 'value'), Env::Post());
$this->assertSame('value', Env::Post('var'));
$this->assertSame('default', Env::Post('new', 'default'));
}
public function testGet()
{
$_GET['var'] = 'value';
$this->assertEquals(array('var' => 'value'), Env::Get());
$this->assertEquals('value', Env::Get('var'));
$this->assertEquals('default', Env::Get('new', 'default'));
$this->assertSame(array('var' => 'value'), Env::Get());
$this->assertSame('value', Env::Get('var'));
$this->assertSame('default', Env::Get('new', 'default'));
}
public function testFiles()
{
$this->assertEquals('default', Env::Files('file.txt', 'default'));
$this->assertEquals(array(), Env::Files());
$this->assertSame('default', Env::Files('file.txt', 'default'));
$this->assertSame(array(), Env::Files());
}
public function testUnsetFiles()
{
unset($_FILES);
$this->assertEquals('default', Env::Files('file.txt', 'default'));
$this->assertSame('default', Env::Files('file.txt', 'default'));
$_FILES['file'] = array('name' => 'files', 'path' => '/');
$this->assertEquals(array('name' => 'files', 'path' => '/'), Env::Files('file', 'default'));
$this->assertEquals('files', Env::Files('file', 'empty', 'name'));
$this->assertSame(array('name' => 'files', 'path' => '/'), Env::Files('file', 'default'));
$this->assertSame('files', Env::Files('file', 'empty', 'name'));
}
public function testParams()
{
Env::setParams(array('name' => 'tony', 'age' => 21));
$this->assertEquals(array('name' => 'tony', 'age' => 21), Env::getParam());
$this->assertSame(array('name' => 'tony', 'age' => 21), Env::getParam());
Env::setParams(array('sex' => 'male'));
$this->assertEquals(array('name' => 'tony', 'age' => 21, 'sex' => 'male'), Env::getParam());
$this->assertEquals('tony', Env::getParam('name'));
$this->assertEquals('default', Env::getParam('height', 'default'));
$this->assertSame(array('name' => 'tony', 'age' => 21, 'sex' => 'male'), Env::getParam());
$this->assertSame('tony', Env::getParam('name'));
$this->assertSame('default', Env::getParam('height', 'default'));
Env::setParam('surname', 'grebnev');
$this->assertEquals('grebnev', Env::getParam('surname'));
$this->assertSame('grebnev', Env::getParam('surname'));
}
public function tearDown()

74
tests/classes/FormatTest.php

@ -20,9 +20,9 @@ class FormatTest extends PHPUnit_Framework_TestCase
public function testCurrency()
{
$this->assertEquals('руб.', Format::getCurrency());
$this->assertSame('руб.', Format::getCurrency());
Format::setCurrencySymbol('usd');
$this->assertEquals('usd', Format::getCurrency());
$this->assertSame('usd', Format::getCurrency());
}
/**
@ -36,40 +36,40 @@ class FormatTest extends PHPUnit_Framework_TestCase
//$this->printStr($a);
//$this->printStr($b);
$this->assertEquals('2' . chr(0xC2) . chr(0xA0) . '000&nbsp;руб.', Format::int2money(200000, true, false));
$this->assertEquals('20 000,00', Format::int2money(2000000, false));
$this->assertSame('2' . chr(0xC2) . chr(0xA0) . '000&nbsp;руб.', Format::int2money(200000, true, false));
$this->assertSame('20 000,00', Format::int2money(2000000, false));
Format::setCurrencySymbol('usd');
$this->assertEquals('200,00&nbsp;usd', Format::int2money(20000, true));
$this->assertSame('200,00&nbsp;usd', Format::int2money(20000, true));
}
public function testMoney2Int()
{
$this->assertEquals(20000, Format::money2int('200,00', false));
$this->assertEquals(20000, Format::money2int('200', false));
$this->assertEquals(2000, Format::money2int('2 000руб.'));
$this->assertSame(20000, Format::money2int('200,00', false));
$this->assertSame(20000, Format::money2int('200', false));
$this->assertSame(2000, Format::money2int('2 000руб.'));
}
public function testInt2Time()
{
$time = 14 * 60 * 60 + 44 * 60 + 24;
$this->assertEquals('14:44:24', Format::int2time($time));
$this->assertEquals('00:00:00', Format::int2time());
$this->assertSame('14:44:24', Format::int2time($time));
$this->assertSame('00:00:00', Format::int2time());
}
public function testInt2Date()
{
$this->assertEquals(date('H:i d.m.Y', 0), Format::int2date());
$this->assertEquals(date('H:i d.m.Y'), Format::int2date(time()));
$this->assertEquals(date('d.m.Y'), Format::int2date(time(), false));
$this->assertEquals('20.04.2011', Format::int2date(strtotime('20 April 2011'), false));
$this->assertEquals('21:10 20.04.2011', Format::int2date(strtotime('21:10:30 20 April 2011')));
$this->assertSame(date('H:i d.m.Y', 0), Format::int2date());
$this->assertSame(date('H:i d.m.Y'), Format::int2date(time()));
$this->assertSame(date('d.m.Y'), Format::int2date(time(), false));
$this->assertSame('20.04.2011', Format::int2date(strtotime('20 April 2011'), false));
$this->assertSame('21:10 20.04.2011', Format::int2date(strtotime('21:10:30 20 April 2011')));
}
public function testInt2rusDate()
{
$this->assertEquals('10 января 1990', Format::int2rusDate(strtotime('10 January 1990')));
$this->assertEquals('19:10 10 января 1990', Format::int2rusDate(strtotime('19:10:59 10 January 1990'), true));
$this->assertSame('10 января 1990', Format::int2rusDate(strtotime('10 January 1990')));
$this->assertSame('19:10 10 января 1990', Format::int2rusDate(strtotime('19:10:59 10 January 1990'), true));
}
public function testSetTimezoneOffset()
@ -78,43 +78,43 @@ class FormatTest extends PHPUnit_Framework_TestCase
$class = new ReflectionClass('Format');
$offset = $class->getProperty('timezone_offset');
$offset->setAccessible(true);
$this->assertEquals(3, $offset->getValue());
$this->assertSame(3, $offset->getValue());
}
public function testSetDateTimeFormat()
{
Format::setDateFormat('H_i d::m::Y', 'd--m--Y');
$this->assertEquals('14_22 20::04::2011', Format::int2date(strtotime('14:22:00 20 April 2011')));
$this->assertEquals('20--04--2011', Format::int2date(strtotime('14:22:00 20 April 2011'), false));
$this->assertSame('14_22 20::04::2011', Format::int2date(strtotime('14:22:00 20 April 2011')));
$this->assertSame('20--04--2011', Format::int2date(strtotime('14:22:00 20 April 2011'), false));
}
public function testSetTodayFormat()
{
Format::setTodayFormat('H_i d::m::Y', 'd--m--Y');
$this->assertEquals(date('H_i d::m::Y', strtotime('+2hours' )), Format::int2date(strtotime('+2 hours')));
$this->assertEquals(date('d--m--Y', strtotime('+2hours' )), Format::int2date(strtotime('+2 hours'), false));
$this->assertSame(date('H_i d::m::Y', strtotime('+2hours' )), Format::int2date(strtotime('+2 hours')));
$this->assertSame(date('d--m--Y', strtotime('+2hours' )), Format::int2date(strtotime('+2 hours'), false));
}
public function testTime2Int()
{
$time = 14 * 60 * 60 + 44 * 60 + 24;
$this->assertEquals($time, Format::time2int('14:44:24'));
$this->assertEquals(14, Format::time2int('14:44'));
$this->assertEquals(14, Format::time2int('14:44:32:53:12'));
$this->assertSame($time, Format::time2int('14:44:24'));
$this->assertSame(14, Format::time2int('14:44'));
$this->assertSame(14, Format::time2int('14:44:32:53:12'));
}
public function testDate2Int()
{
$this->assertEquals(strtotime('2 Jan 2010'), Format::date2int('2 Jan 2010'));
$this->assertSame(strtotime('2 Jan 2010'), Format::date2int('2 Jan 2010'));
}
public function testInt2Phone()
{
$this->assertEquals('777-77-77', Format::int2phone(7777777));
$this->assertEquals('(123) 456-78-90', Format::int2phone(1234567890));
$this->assertEquals('', Format::int2phone(12890));
$this->assertEquals('', Format::int2phone('asdas'));
$this->assertSame('777-77-77', Format::int2phone(7777777));
$this->assertSame('(123) 456-78-90', Format::int2phone(1234567890));
$this->assertSame('', Format::int2phone(12890));
$this->assertSame('', Format::int2phone('asdas'));
}
/**
@ -122,21 +122,21 @@ class FormatTest extends PHPUnit_Framework_TestCase
*/
public function testPhone2Int()
{
$this->assertEquals('4951234567', Format::phone2int('123-45-67'));
$this->assertEquals('9261234567', Format::phone2int('926-123-45-67'));
$this->assertEquals('', Format::phone2int('8-926-123-45-67'));
$this->assertEquals('', Format::phone2int('12-45-67'));
$this->assertEquals('', Format::phone2int('not a phone'));
$this->assertSame('4951234567', Format::phone2int('123-45-67'));
$this->assertSame('9261234567', Format::phone2int('926-123-45-67'));
$this->assertSame('', Format::phone2int('8-926-123-45-67'));
$this->assertSame('', Format::phone2int('12-45-67'));
$this->assertSame('', Format::phone2int('not a phone'));
}
public function testBytes2MB()
{
$this->assertEquals('1МБ', Format::bytes2MB(1048576));
$this->assertSame('1МБ', Format::bytes2MB(1048576));
}
public function testBytes2KB()
{
$this->assertEquals('2КБ', Format::bytes2KB(2048));
$this->assertSame('2КБ', Format::bytes2KB(2048));
}

11
tests/exception/Error404ExceptionTest.php

@ -15,22 +15,15 @@ require_once dirname(__FILE__) . '/../../exception/Error404Exception.php';
class Error404ExceptionTest extends PHPUnit_Framework_TestCase
{
/**
* @expectedException Error404Exception
*/
public function testError404Exception()
{
$this->setExpectedException('Error404Exception');
throw new Error404Exception();
}
/**
* @expectedException Error404Exception
* @expectedExceptionMessage Error404Exception message
* @excpectedExceptionCode 1
*/
public function testError404ExceptionMessage()
{
$this->setExpectedException('Error404Exception', 'Error404Exception message', 10);
throw new Error404Exception('Error404Exception message', 10);
}

13
tests/exception/ErrorHandlerTest.php

@ -30,15 +30,12 @@ class ErrorHandlerTest extends PHPUnit_Framework_TestCase
ErrorHandler::init();
$eh = set_error_handler($my_eh);
$this->assertInternalType('array', $eh);
$this->assertEquals($eh, $my_eh);
$this->assertSame($eh, $my_eh);
}
/**
* @expectedException ErrorException
* @expectedExceptionMessage test error
*/
public function testHandleError()
{
$this->setExpectedException('ErrorException', 'test error');
trigger_error("test error", E_USER_ERROR);
}
@ -68,11 +65,11 @@ class ErrorHandlerTest extends PHPUnit_Framework_TestCase
$method = $class->getMethod('WrapTrace');
$method->setAccessible(true);
$result = $method->invoke(null, "first line\nsecond line");
$this->assertEquals("<code>first line<br />\nsecond line</code>", $result);
$this->assertSame("<code>first line<br />\nsecond line</code>", $result);
$result = $method->invoke(null, "first line\r\nsecond line");
$this->assertEquals("<code>first line<br />\r\nsecond line</code>", $result);
$this->assertSame("<code>first line<br />\r\nsecond line</code>", $result);
$result = $method->invoke(null, "first line\r\n\r\nsecond line");
$this->assertEquals("<code>first line<br />\r\n<br />\r\nsecond line</code>", $result);
$this->assertSame("<code>first line<br />\r\n<br />\r\nsecond line</code>", $result);
}
public function tearDown()

11
tests/exception/GeneralExceptionTest.php

@ -14,22 +14,15 @@ require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
class GeneralExceptionTest extends PHPUnit_Framework_TestCase
{
/**
* @expectedException GeneralException
*/
public function testGeneralException()
{
$this->setExpectedException('GeneralException');
throw new GeneralException();
}
/**
* @expectedException GeneralException
* @expectedExceptionMessage GeneralException message
* @excpectedExceptionCode 1
*/
public function testGeneralExceptionMessage()
{
$this->setExpectedException('GeneralException', 'GeneralException message', 1);
throw new GeneralException('GeneralException message', 1);
}

28
tests/exception/InitializationExceptionTest.php

@ -0,0 +1,28 @@
<?php
/*
* @copyright NetMonsters <team@netmonsters.ru>
* @link http://netmonsters.ru
* @package Majestic
* @subpackage UnitTests
* @since 2011-11-24
*
* Unit tests for InitializationException class
*/
require_once dirname(__FILE__) . '/../../exception/InitializationException.php';
class InitializationExceptionTest extends PHPUnit_Framework_TestCase
{
public function testInitializationException()
{
$this->setExpectedException('InitializationException');
throw new InitializationException();
}
public function testInitializationExceptionMessage()
{
$this->setExpectedException('InitializationException', 'InitializationException message', 1);
throw new InitializationException('InitializationException message', 1);
}
}

11
tests/form/FormFieldTest.php

@ -15,6 +15,7 @@ require_once dirname(__FILE__) . '/../../validator/NotEmptyValidator.php';
require_once dirname(__FILE__) . '/../../validator/RegexValidator.php';
require_once dirname(__FILE__) . '/../../validator/EmailValidator.php';
require_once dirname(__FILE__) . '/../../form/FormField.php';
require_once dirname(__FILE__) . '/../../exception/InitializationException.php';
class FormFieldTest extends PHPUnit_Framework_TestCase
{
@ -100,7 +101,7 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
$validator = true;
$tmp_form_field = new FormField();
// @TODO Fix exception type
$this->setExpectedException('Exception', 'Invalid validator provided to addValidator; must be string or iValidator'); // Text of Exception
$this->setExpectedException('InitializationException', 'Invalid validator provided to addValidator; must be string or iValidator'); // Text of Exception
$tmp_form_field->addValidator($validator);
}
@ -144,7 +145,7 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
$filter = new NotEmptyValidator();
$form_field = new FormField();
// @TODO Fix exception type
$this->setExpectedException('Exception', 'Invalid filter provided to addFilter; must be string or iFilter'); // Text of exception
$this->setExpectedException('InitializationException', 'Invalid filter provided to addFilter; must be string or iFilter'); // Text of exception
$form_field->addFilter($filter);
}
@ -174,7 +175,7 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
$this->assertTrue($form_field->isValid($test_string));
$this->assertAttributeNotInternalType('array', 'value', $form_field);
$this->assertEquals('login', $form_field->getValue());
$this->assertSame('login', $form_field->getValue());
}
public function testGetValueStringIncorrect()
@ -185,7 +186,7 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
$this->assertTrue($form_field->isValid($test_string));
$this->assertAttributeNotInternalType('array', 'value', $form_field);
$this->assertEquals('', $form_field->getValue());
$this->assertSame('', $form_field->getValue());
}
public function testGetMessageDefault()
@ -217,7 +218,7 @@ class FormFieldTest extends PHPUnit_Framework_TestCase
);
$form_field = new FormField();
$form_field->addValidator('NotEmpty');
$this->setExpectedException('Exception', 'Define default message for array fields');
$this->setExpectedException('InitializationException', 'Define default message for array fields');
$form_field->isValid($test_array);
}

6
tests/form/FormTest.php

@ -17,6 +17,7 @@ require_once dirname(__FILE__) . '/../../validator/Validator.php';
require_once dirname(__FILE__) . '/../../validator/RegexValidator.php';
require_once dirname(__FILE__) . '/../../validator/NotEmptyValidator.php';
require_once dirname(__FILE__) . '/../../validator/EmailValidator.php';
require_once dirname(__FILE__) . '/../../exception/InitializationException.php';
class FormTest extends PHPUnit_Framework_TestCase
{
@ -26,7 +27,6 @@ class FormTest extends PHPUnit_Framework_TestCase
$stub = $this->getMockForAbstractClass('Form');
$method = new ReflectionMethod('Form', 'addField');
$method->setAccessible(true);
$return_object = $method->invokeArgs($stub, array('login'));
$this->assertInstanceOf('FormField', $return_object);
@ -40,8 +40,8 @@ class FormTest extends PHPUnit_Framework_TestCase
$stub = $this->getMockForAbstractClass('Form');
$method = new ReflectionMethod('Form', 'addField');
$method->setAccessible(true);
$return_object = $method->invokeArgs($stub, array('login', $message));
$this->assertInstanceOf('FormField', $return_object);
$this->assertEquals($form_field, $return_object);
$this->assertAttributeEquals($message, 'default_message', $return_object);
@ -51,7 +51,7 @@ class FormTest extends PHPUnit_Framework_TestCase
{
$form = new NotEmptyForm();
// @TODO Fix exception type
$this->setExpectedException('Exception', 'Form::Form::isValid expects an array');
$this->setExpectedException('InitializationException', 'Form::Form::isValid expects an array');
$form->isValid('');
}

8
tests/form/FormViewHelperTest.php

@ -14,6 +14,7 @@ require_once dirname(__FILE__) . '/../../view/PHPView.php';
require_once dirname(__FILE__) . '/../../view/helpers/ViewHelper.php';
require_once dirname(__FILE__) . '/../../form/FormViewHelper.php';
require_once dirname(__FILE__) . '/../../session/Session.php';
require_once dirname(__FILE__) . '/../../exception/InitializationException.php';
class FormViewHelperTest extends PHPUnit_Framework_TestCase
{
@ -35,7 +36,7 @@ class FormViewHelperTest extends PHPUnit_Framework_TestCase
public function testFormUnsetFormName()
{
$helper = new FormViewHelper($this->view);
$this->setExpectedException('Exception', 'Form name required for helper init');
$this->setExpectedException('InitializationException', 'Form name required for helper init');
// @TODO Refactor for form name is required param?
$helper->form();
}
@ -43,7 +44,7 @@ class FormViewHelperTest extends PHPUnit_Framework_TestCase
public function testFormEmptyFormName()
{
$helper = new FormViewHelper($this->view);
$this->setExpectedException('Exception', 'Form name required for helper init');
$this->setExpectedException('InitializationException', 'Form name required for helper init');
$helper->form('');
}
@ -80,14 +81,11 @@ class FormViewHelperTest extends PHPUnit_Framework_TestCase
{
$helper = new FormViewHelper($this->view);
$helper->form($this->formname);
$value = $helper->message('field1');
$this->assertSame('<span class="error">' . $this->view->escape('Can\'t serialize "value"') . '</span>', $value);
}
public function testMessageNotSet()
{
$helper = new FormViewHelper($this->view);
$helper->form($this->formname);

22
tests/i18n/I18NTest.php

@ -14,15 +14,17 @@ require_once dirname(__FILE__) . '/../../Registry.php';
require_once dirname(__FILE__) . '/../../Config.php';
require_once dirname(__FILE__) . '/../../classes/Env.class.php';
require_once dirname(__FILE__) . '/../../i18n/I18N.php';
require_once dirname(__FILE__) . '/../../exception/InitializationException.php';
/**
* @runTestsInSeparateProcesses
*/
class I18NTest extends PHPUnit_Framework_TestCase
{
public function run(PHPUnit_Framework_TestResult $result = NULL)
{
$this->setConstants();
$this->setPreserveGlobalState(false);
return parent::run($result);
}
@ -33,18 +35,18 @@ class I18NTest extends PHPUnit_Framework_TestCase
public function testInit()
{
$this->setConstants();
Config::set('I18N', array('locales' => array('ru' => 'ru-ru', 'us' => 'en-us')));
Config::set('I18N', array('locales' => array('ru' => 'ru-ru', 'us' => 'en-us')));
I18N::init();
$this->assertAttributeEquals(array('ru' => 'ru-ru', 'us' => 'en-us'), 'locales', 'I18N');
$this->assertAttributeEquals('ru-ru', 'locale', 'I18N');
}
/**
* @expectedException Exception
*/
public function testInitNoConfig()
{
Config::set('I18N', array('locales' => null));
$this->setExpectedException('InitializationException');
I18N::init();
}
@ -82,10 +84,10 @@ class I18NTest extends PHPUnit_Framework_TestCase
/**
* @runInSeparateProcess
* @expectedException PHPUnit_Framework_Error
*/
public function testInitSetDefaultLangNotInLocales()
{
$this->setExpectedException('PHPUnit_Framework_Error');
$this->setConstants();
Config::set('I18N', array('locales' => array('rus' => 'ru_RU'), 'default' => 'ru'));
@ -142,8 +144,8 @@ class I18NTest extends PHPUnit_Framework_TestCase
Config::set('I18N', array('locales' => array('en' => 'en_US'), 'default' => 'ru'));
I18N::init();
$this->assertEquals('en', I18N::getLang());
$this->assertEquals('ru', I18N::getDefaultLang());
$this->assertSame('en', I18N::getLang());
$this->assertSame('ru', I18N::getDefaultLang());
}
/**
@ -157,7 +159,7 @@ class I18NTest extends PHPUnit_Framework_TestCase
Config::set('I18N', array('locales' => array('ru' => 'ru-ru'), 'default' => 'ru'));
I18N::init();
I18N::setLangs(array('en' => 'en-us', 'fr' => 'fr-fr'));
$this->assertEquals(array('en' => 'en-us', 'fr' => 'fr-fr'), I18N::getLangs());
$this->assertSame(array('en' => 'en-us', 'fr' => 'fr-fr'), I18N::getLangs());
}
/**
@ -171,7 +173,7 @@ class I18NTest extends PHPUnit_Framework_TestCase
Config::set('I18N', array('locales' => array('ru' => 'ru-ru'), 'default' => 'ru'));
I18N::init();
I18N::setLangs(array('ru' => 'ru_ru', 'en' => 'en-us', 'fr' => 'fr-fr'));
$this->assertEquals('ru_ru', I18N::getLangName());
$this->assertSame('ru_ru', I18N::getLangName());
$this->assertFalse(I18N::getLangName('br'));
}

8
tests/layout/LayoutTest.php

@ -92,10 +92,14 @@ class LayoutTest extends PHPUnit_Framework_TestCase
if (!defined('DEBUG')) {
define('DEBUG', false);
}
$layout = $this->getMockForAbstractClass('Layout');
$layout = $this->getMockForAbstractClass('Layout', array('append', 'prepend'), 'LayoutMock');
$action = $this->getMock('Action', array('fetch'));
$class = new ReflectionClass('Layout');
$action->expects($this->exactly(3))
->method('fetch')
->will($this->returnValue(true));
$class = new ReflectionClass('LayoutMock');
$method = $class->getMethod('append');
$method->setAccessible(true);

7
tests/logger/FileLoggerTest.php

@ -50,8 +50,6 @@ class FileLoggerTest extends PHPUnit_Framework_TestCase
/**
* @runInSeparateProcess
* @expectedException GeneralException
* @expectedExceptionMessage Could not open file /log.txt
*/
public function testCannotWrite()
{
@ -60,6 +58,9 @@ class FileLoggerTest extends PHPUnit_Framework_TestCase
}
$conf = array('logger' => 'FileLogger', 'filepath' => '/log.txt');
Config::set('Logger', $conf);
$this->setExpectedException('GeneralException', 'Could not open file /log.txt');
$logger = Logger::getInstance()->log('new msg');
$this->assertFileNotExists('log.txt');
}
@ -102,7 +103,7 @@ class FileLoggerTest extends PHPUnit_Framework_TestCase
$logger->__destruct();
$this->assertAttributeEquals(null, 'handler', $logger);
$fd_count_end = (int) `$fd_command`;
$this->assertEquals($fd_count_start, $fd_count_end);
$this->assertSame($fd_count_start, $fd_count_end);
}
public function tearDown()

3
tests/model/DbExprTest.php

@ -14,11 +14,10 @@ require_once dirname(__FILE__) . '/../../model/DbExpr.php';
class DbExprTest extends PHPUnit_Framework_TestCase
{
public function testExpr()
{
$expr = new DbExpr('THIS IS SQL EXPRESSION');
$str = (string) $expr;
$this->assertEquals('THIS IS SQL EXPRESSION', $str);
$this->assertSame('THIS IS SQL EXPRESSION', $str);
}
}

9
tests/model/DbStatementTest.php

@ -13,6 +13,7 @@
require_once dirname(__FILE__) . '/../../model/Db.php';
require_once dirname(__FILE__) . '/../../model/DbDriver.php';
require_once dirname(__FILE__) . '/../../model/DbStatement.php';
require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
class DbStatementTest extends PHPUnit_Framework_TestCase
{
@ -54,16 +55,16 @@ class DbStatementTest extends PHPUnit_Framework_TestCase
->with($this->anything())
->will($this->returnCallback(array($this, 'dbStatementFetch')));
$this->assertEquals(11, $this->stmt->fetchField('one'));
$this->assertSame(11, $this->stmt->fetchField('one'));
$this->assertFalse($this->stmt->fetchField('zero'));
reset($this->testData);
$this->assertEquals(array(11, 21, 31), $this->stmt->fetchColumn('one'));
$this->assertSame(array(11, 21, 31), $this->stmt->fetchColumn('one'));
reset($this->testData);
$result = $this->stmt->fetchAll();
$this->assertEquals(11, $result[0]->one);
$this->assertEquals(32, $result[2]->two);
$this->assertSame(11, $result[0]->one);
$this->assertSame(32, $result[2]->two);
// reset($this->testData);
// $result = $this->stmt->fetchPairs();

31
tests/model/DbTest.php

@ -14,35 +14,37 @@ require_once dirname(__FILE__) . '/../../Registry.php';
require_once dirname(__FILE__) . '/../../Config.php';
require_once dirname(__FILE__) . '/../../model/DbDriver.php';
require_once dirname(__FILE__) . '/../../model/Db.php';
require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
require_once dirname(__FILE__) . '/../../exception/InitializationException.php';
class DbTest extends PHPUnit_Framework_TestCase
{
/**
* @expectedException Exception
* @expectedExceptionMessage Trying to get property of non-object
*/
public function testConnectNoParams()
{
Db::connect();
$this->setExpectedException('InitializationException', 'Trying to get property of non-object');
Db::connect();
}
/**
* @expectedException Exception
* @expectedExceptionMessage Connection parameters must be an array
*/
public function testConnectConfigNotArray()
{
$this->setExpectedException('InitializationException', 'Connection parameters must be an array');
Db::connect('name', 'config');
}
/**
* @group MySQL
*/
public function testConnectGlobalConfig()
{
$conf = array('hostname' => 'localhost', 'driver' => 'MySQLiDriverGlobalConfMock', 'database' => 'db', 'username' => 'test', 'password' => '1234');
$this->getMockForAbstractClass('DbDriver', array(), 'MySQLiDriverGlobalConfMock', false);
Config::set('Db', array('global' =>$conf));
Db::connect('global');
$driver = Db::connect('global');
$this->assertInstanceOf('DbDriver', $driver);
}
/**
* @group MySQL
*/
public function testConnectWithConfigParam()
{
$conf = array('hostname' => 'localhost', 'driver' => 'MySQLiDriverMock', 'database' => 'db', 'username' => 'test', 'password' => '1234');
@ -50,14 +52,11 @@ class DbTest extends PHPUnit_Framework_TestCase
$driver = Db::connect('mysql', $conf);
$this->assertInstanceOf('DbDriver', $driver);
}
/**
* @expectedException Exception
* @expectedExceptionMessage Database driver must extends DbDriver
*/
public function testConnectWithWrongDriver()
{
$this->getMock('NotDbDriver', array(), array(), 'NoDbDriverMock');
$this->setExpectedException('InitializationException', 'Database driver must extends DbDriver');
$driver = Db::connect('nodb', array('hostname' => 'localhost', 'driver' => 'NoDbDriverMock'));
}
}

60
tests/model/MySQLiDriverTest.php

@ -16,6 +16,7 @@ require_once dirname(__FILE__) . '/../../model/MySQLiStatement.php';
require_once dirname(__FILE__) . '/../../model/DbDriver.php';
require_once dirname(__FILE__) . '/../../model/SqlDbDriver.php';
require_once dirname(__FILE__) . '/../../model/MySQLiDriver.php';
require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
class MySQLiDriverTest extends PHPUnit_Extensions_Database_TestCase
{
@ -25,6 +26,8 @@ class MySQLiDriverTest extends PHPUnit_Extensions_Database_TestCase
private $conf = array();
protected function getConnection()
{
if ($this->conn === null) {
@ -49,7 +52,9 @@ class MySQLiDriverTest extends PHPUnit_Extensions_Database_TestCase
$this->setPreserveGlobalState(false);
return parent::run($result);
}
/**
* @group MySQL
*/
public function testDriver()
{
if (!defined('DEBUG')) {
@ -65,10 +70,12 @@ class MySQLiDriverTest extends PHPUnit_Extensions_Database_TestCase
->getTable("table");
$this->assertTablesEqual($expectedTable, $queryTable);
$this->assertEquals(1, $driver->insert('table', array('id' => 3, 'user' => 'tony', 'content' => 'some test content', 'created' => '2011-11-07 11:35:20')));
$this->assertEquals(3, $this->getConnection()->getRowCount('table'));
$this->assertSame(1, $driver->insert('table', array('id' => 3, 'user' => 'tony', 'content' => 'some test content', 'created' => '2011-11-07 11:35:20')));
$this->assertSame(3, $this->getConnection()->getRowCount('table'));
}
/**
* @group MySQL
*/
public function testGetConnection()
{
if (!defined('DEBUG')) {
@ -79,22 +86,24 @@ class MySQLiDriverTest extends PHPUnit_Extensions_Database_TestCase
$this->assertInstanceOf('mysqli', $driver->getConnection());
$this->assertTrue($driver->isConnected());
}
/**
* @expectedException Exception
* @expectedExceptionMessage Unknown database
* @group MySQL
*/
public function testGetConnectionWrongConfig()
{
if (!defined('DEBUG')) {
define('DEBUG', false);
}
$this->conf['database'] = 'nodb';
$driver = new MySQLiDriver($this->conf);
$this->setExpectedException('GeneralException', 'Unknown database \'nodb\'');
$this->assertNull('mysqli', $driver->getConnection());
}
/**
* @group MySQL
*/
public function testDisconnect()
{
if (!defined('DEBUG')) {
@ -111,7 +120,9 @@ class MySQLiDriverTest extends PHPUnit_Extensions_Database_TestCase
$driver->disconnect();
$this->assertAttributeEquals(null, 'connection', $driver);
}
/**
* @group MySQL
*/
public function testInsert()
{
if (!defined('DEBUG')) {
@ -120,18 +131,19 @@ class MySQLiDriverTest extends PHPUnit_Extensions_Database_TestCase
$driver = new MySQLiDriver($this->conf);
$this->assertEquals(1, $driver->insert('table', array('id' => 3, 'user' => 'tony', 'content' => 'some test content', 'created' => '2011-11-07 11:35:20')));
$this->assertEquals(3, $driver->getInsertId());
$this->assertEquals(1, $driver->insert('table', array('id' => null, 'user' => 'tony', 'content' => 'some test content', 'created' => '2011-11-07 11:35:20')));
$this->assertEquals(4, $driver->getInsertId());
$this->assertEquals(1, $driver->insert('table', array('id' => null, 'user' => true, 'content' => 'some test content', 'created' => '2011-11-07 11:35:20')));
$this->assertEquals(5, $driver->getInsertId());
$this->assertEquals(2, $driver->insert('table', array('id' => '5', 'user' => true, 'content' => 'some test content', 'created' => '2011-11-07 11:35:20'), array('id' => 8)));
$this->assertEquals(8, $driver->getInsertId());
$this->assertSame(1, $driver->insert('table', array('id' => 3, 'user' => 'tony', 'content' => 'some test content', 'created' => '2011-11-07 11:35:20')));
$this->assertSame(3, $driver->getInsertId());
$this->assertSame(1, $driver->insert('table', array('id' => null, 'user' => 'tony', 'content' => 'some test content', 'created' => '2011-11-07 11:35:20')));
$this->assertSame(4, $driver->getInsertId());
$this->assertSame(1, $driver->insert('table', array('id' => null, 'user' => true, 'content' => 'some test content', 'created' => '2011-11-07 11:35:20')));
$this->assertSame(5, $driver->getInsertId());
$this->assertSame(2, $driver->insert('table', array('id' => '5', 'user' => true, 'content' => 'some test content', 'created' => '2011-11-07 11:35:20'), array('id' => 8)));
$this->assertSame(8, $driver->getInsertId());
}
/**
* @TODO: DbDriver::getInsertId($table = null, $key = null) - params not used
* @group MySQL
*/
public function testGetInsertId()
{
@ -141,10 +153,12 @@ class MySQLiDriverTest extends PHPUnit_Extensions_Database_TestCase
$driver = new MySQLiDriver($this->conf);
$this->assertEquals(1, $driver->insert('table', array('id' => 3, 'user' => 'tony', 'content' => 'some test content', 'created' => '2011-11-07 11:35:20')));
$this->assertEquals(3, $driver->getInsertId());
$this->assertSame(1, $driver->insert('table', array('id' => 3, 'user' => 'tony', 'content' => 'some test content', 'created' => '2011-11-07 11:35:20')));
$this->assertSame(3, $driver->getInsertId());
}
/**
* @group MySQL
*/
public function testTransaction()
{
if (!defined('DEBUG')) {
@ -175,7 +189,9 @@ class MySQLiDriverTest extends PHPUnit_Extensions_Database_TestCase
->getTable("table");
$this->assertTablesEqual($expectedTable, $queryTable);
}
/**
* @group MySQL
*/
public function testRollback()
{
if (!defined('DEBUG')) {

40
tests/model/MySQLiStatementTest.php

@ -16,6 +16,7 @@ require_once dirname(__FILE__) . '/../../model/Db.php';
require_once dirname(__FILE__) . '/../../model/DbDriver.php';
require_once dirname(__FILE__) . '/../../model/DbStatement.php';
require_once dirname(__FILE__) . '/../../model/MySQLiStatement.php';
require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
class MySQLiStatementTest extends PHPUnit_Framework_TestCase
{
@ -120,6 +121,7 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
/**
* @runInSeparateProcess
* @group MySQL
*/
public function testFetchNoResult()
{
@ -131,8 +133,7 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
/**
* @runInSeparateProcess
* @expectedException Exception
* @expectedExceptionMessage ERROR
* @group MySQL
*/
public function testDriverExecuteNoResult()
{
@ -140,11 +141,13 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
define('DEBUG', false);
}
$this->setDriverGetConnectionWrongResultMethod();
$this->setExpectedException('GeneralException', 'ERROR');
$this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
}
/**
* @runInSeparateProcess
* @group MySQL
*/
public function testFetch()
{
@ -153,14 +156,15 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
}
$this->setDriverGetConnectionMethod();
$this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
$this->assertEquals('OBJECT', $this->stmt->fetch());
$this->assertEquals('ARRAY', $this->stmt->fetch(Db::FETCH_NUM));
$this->assertEquals('ASSOC', $this->stmt->fetch(Db::FETCH_ASSOC));
$this->assertEquals('ARRAY', $this->stmt->fetch(Db::FETCH_BOTH));
$this->assertSame('OBJECT', $this->stmt->fetch());
$this->assertSame('ARRAY', $this->stmt->fetch(Db::FETCH_NUM));
$this->assertSame('ASSOC', $this->stmt->fetch(Db::FETCH_ASSOC));
$this->assertSame('ARRAY', $this->stmt->fetch(Db::FETCH_BOTH));
}
/**
* @runInSeparateProcess
* @group MySQL
*/
public function testFetchObject()
{
@ -169,11 +173,12 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
}
$this->setDriverGetConnectionMethod();
$this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
$this->assertEquals('OBJECT', $this->stmt->fetchObject());
$this->assertSame('OBJECT', $this->stmt->fetchObject());
}
/**
* @runInSeparateProcess
* @group MySQL
*/
public function testFetchPairs()
{
@ -225,11 +230,12 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
}
$this->setDriverGetConnectionMethod();
$this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
$this->assertEquals('OBJECT', $this->stmt->fetch());
$this->assertSame('OBJECT', $this->stmt->fetch());
}
/**
* @runInSeparateProcess
* @group MySQL
*/
public function testClose()
{
@ -244,6 +250,9 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
$this->assertAttributeEquals(null, 'result', $this->stmt);
}
/**
* @group MySQL
*/
public function testAffectedRows()
{
$mysqliMock = $this->getMockBuilder('MysqliDrvr');
@ -254,9 +263,12 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
->method('getConnection')
->will($this->returnValue($mysqliMock));
$this->assertEquals('AFFECTED_ROWS', $this->stmt->affectedRows());
$this->assertSame('AFFECTED_ROWS', $this->stmt->affectedRows());
}
/**
* @group MySQL
*/
public function testNumRowsNoResult()
{
$this->assertFalse($this->stmt->numRows());
@ -264,24 +276,23 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
/**
* @runInSeparateProcess
* @expectedException Exception
* @TODO: exception just for code coverage - could not mock mysqli properties
* @group MySQL
*/
public function testNumRows()
{
$this->markTestSkipped('Unable to execute a method or access a property of an incomplete object.');
if (!defined('DEBUG')) {
define('DEBUG', false);
}
$this->setDriverGetConnectionMethod();
$this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
$this->assertNull($this->stmt->numRows());
}
/**
* @expectedException Exception
* @expectedExceptionMessage Invalid fetch mode
* @runInSeparateProcess
* @group MySQL
*/
public function testFetchInvalidMode()
{
@ -290,6 +301,9 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
}
$this->setDriverGetConnectionMethod();
$this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
$this->setExpectedException('GeneralException');
$this->stmt->fetch(324);
}

41
tests/model/SqlDbDriverTest.php

@ -14,10 +14,10 @@ require_once dirname(__FILE__) . '/../../model/DbExpr.php';
require_once dirname(__FILE__) . '/../../model/Db.php';
require_once dirname(__FILE__) . '/../../model/DbDriver.php';
require_once dirname(__FILE__) . '/../../model/SqlDbDriver.php';
require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
class SqlDbDriverTest extends PHPUnit_Framework_TestCase
{
private $driver;
public function setUp()
@ -29,16 +29,21 @@ class SqlDbDriverTest extends PHPUnit_Framework_TestCase
public function testConstruct()
{
$conf = array('hostname' => 'localhost', 'database' => 'db', 'username' => 'test', 'password' => '1234');
$this->driver = $this->getMockForAbstractClass('SqlDbDriver', array($conf));
try {
$this->driver = $this->getMockForAbstractClass('SqlDbDriver', array($conf));
}
catch (GeneralException $expected) {
$this->fail($expected->getMessage());
}
$this->assertInstanceOf('DbDriver', $this->driver);
}
/**
* @expectedException Exception
* @expectedExceptionMessage Configuration must have a "username".
*/
public function testConstructWrongConfig()
{
$conf = array('hostname' => 'localhost', 'database' => 'db');
$this->setExpectedException('GeneralException', 'Configuration must have a "username"');
$this->getMockForAbstractClass('SqlDbDriver', array($conf));
}
@ -49,17 +54,17 @@ class SqlDbDriverTest extends PHPUnit_Framework_TestCase
public function testBeginTransaction()
{
$this->assertEquals($this->driver, $this->driver->beginTransaction());
$this->assertSame($this->driver, $this->driver->beginTransaction());
}
public function testCommit()
{
$this->assertEquals($this->driver, $this->driver->commit());
$this->assertSame($this->driver, $this->driver->commit());
}
public function testRollback()
{
$this->assertEquals($this->driver, $this->driver->rollback());
$this->assertSame($this->driver, $this->driver->rollback());
}
public function testQuery()
@ -68,11 +73,11 @@ class SqlDbDriverTest extends PHPUnit_Framework_TestCase
$stmt = $this->driver->query('SELECT * FROM table');
$this->assertInstanceOf('DbStmt', $stmt);
$this->assertEquals('SELECT * FROM table', $stmt->string());
$this->assertSame('SELECT * FROM table', $stmt->string());
$stmt = $this->driver->query('SELECT * FROM table', 'simple');
$this->assertInstanceOf('DbStmt', $stmt);
$this->assertEquals('SELECT * FROM table', $stmt->string());
$this->assertSame('SELECT * FROM table', $stmt->string());
}
public function testInsert()
@ -81,7 +86,7 @@ class SqlDbDriverTest extends PHPUnit_Framework_TestCase
->setDriverQuoteFunction();
$bind = array('table.name' => 'tony', 'chair.age' => 21, 'height' => 185);
$sql = $this->driver->insert('users', $bind);
$this->assertEquals('INSERT INTO `users` (`table`.`name`, `chair`.`age`, `height`) VALUES (tony, 21, 185)', $sql);
$this->assertSame('INSERT INTO `users` (`table`.`name`, `chair`.`age`, `height`) VALUES (tony, 21, 185)', $sql);
}
public function testUpdate()
@ -91,7 +96,7 @@ class SqlDbDriverTest extends PHPUnit_Framework_TestCase
$bind = array('table.name' => 'tony', 'chair.age' => 21, 'height' => 185);
$sql = $this->driver->update('users', $bind);
$this->assertEquals('UPDATE `users` SET `table`.`name`=tony, `chair`.`age`=21, `height`=185', $sql);
$this->assertSame('UPDATE `users` SET `table`.`name`=tony, `chair`.`age`=21, `height`=185', $sql);
}
public function testDeleteNoWHERE()
@ -99,7 +104,7 @@ class SqlDbDriverTest extends PHPUnit_Framework_TestCase
$this->setDriverPrepareFunction();
$sql = $this->driver->delete('users');
$this->assertEquals('DELETE FROM `users`', $sql);
$this->assertSame('DELETE FROM `users`', $sql);
}
public function testDeleteWithWHEREArray()
@ -108,7 +113,7 @@ class SqlDbDriverTest extends PHPUnit_Framework_TestCase
->setDriverQuoteFunction();
$sql = $this->driver->delete('users', array('name?tony' => new DbExpr('='), 'height?185' => '>'));
$this->assertEquals('DELETE FROM `users` WHERE name=tony AND height>185', $sql);
$this->assertSame('DELETE FROM `users` WHERE name=tony AND height>185', $sql);
}
public function testDeleteWithWHERESimpleCond()
@ -116,7 +121,7 @@ class SqlDbDriverTest extends PHPUnit_Framework_TestCase
$this->setDriverPrepareFunction();
$sql = $this->driver->delete('users', 'name=tony');
$this->assertEquals('DELETE FROM `users` WHERE name=tony', $sql);
$this->assertSame('DELETE FROM `users` WHERE name=tony', $sql);
}
public function testDeleteWithWHEREKeyArray()
@ -124,7 +129,7 @@ class SqlDbDriverTest extends PHPUnit_Framework_TestCase
$this->setDriverPrepareFunction();
$sql = $this->driver->delete('users', array('name=tony' => 0));
$this->assertEquals('DELETE FROM `users` WHERE name=tony', $sql);
$this->assertSame('DELETE FROM `users` WHERE name=tony', $sql);
}
public function testDeleteWithWHEREDbExpr()
@ -132,7 +137,7 @@ class SqlDbDriverTest extends PHPUnit_Framework_TestCase
$this->setDriverPrepareFunction();
$sql = $this->driver->delete('users', new DbExpr('name=tony'));
$this->assertEquals('DELETE FROM `users` WHERE name=tony', $sql);
$this->assertSame('DELETE FROM `users` WHERE name=tony', $sql);
}
protected function setDriverPrepareFunction()

23
tests/model/SqlModelTest.php

@ -54,13 +54,13 @@ class SqlModelTest extends PHPUnit_Framework_TestCase
public function testIdentify()
{
$param = 'param';
$this->assertEquals($param, $this->model->identify($param));
$this->assertSame($param, $this->model->identify($param));
}
public function testQuote()
{
$param = 'param';
$this->assertEquals($param, $this->model->quote($param));
$this->assertSame($param, $this->model->quote($param));
}
public function testGet()
@ -75,12 +75,12 @@ class SqlModelTest extends PHPUnit_Framework_TestCase
public function testUpdate()
{
$this->assertEquals('mock', $this->model->update(array('var' => 'val'), 1));
$this->assertSame('mock', $this->model->update(array('var' => 'val'), 1));
}
public function testDelete()
{
$this->assertEquals('mock', $this->model->delete(1));
$this->assertSame('mock', $this->model->delete(1));
}
public function testOrder()
@ -88,14 +88,14 @@ class SqlModelTest extends PHPUnit_Framework_TestCase
$model = new ReflectionClass('SqlModel');
$method = $model->getMethod('order');
$method->setAccessible(true);
$this->assertEquals(' ORDER BY id DESC', $method->invoke($this->model, array('sort' => 'id', 'order' => 'desc')));
$this->assertEquals(' ORDER BY name ASC', $method->invoke($this->model, array('sort' => 'name'), array('id', 'name')));
$this->assertSame(' ORDER BY id DESC', $method->invoke($this->model, array('sort' => 'id', 'order' => 'desc')));
$this->assertSame(' ORDER BY name ASC', $method->invoke($this->model, array('sort' => 'name'), array('id', 'name')));
$this->assertEmpty($method->invoke($this->model, array()));
/**
* @TODO: Model::order - check DESC condition - make case insensitive
*/
$this->assertEquals(' ORDER BY name ASC', $method->invoke($this->model, array('sort' => 'name', 'order' => 'DESC'), array('id', 'name')));
$this->assertSame(' ORDER BY name ASC', $method->invoke($this->model, array('sort' => 'name', 'order' => 'DESC'), array('id', 'name')));
}
public function testSearch()
@ -105,7 +105,7 @@ class SqlModelTest extends PHPUnit_Framework_TestCase
$method->setAccessible(true);
$this->assertEmpty($method->invoke($this->model, array()));
$this->assertEmpty($method->invoke($this->model, array('q' => 'in', 'qt' => 'name')));
$this->assertEquals('test.name LIKE %on%', $method->invoke($this->model, array('qt' => 'name', 'q' => 'on'), array('name'), 'test'));
$this->assertSame('test.name LIKE %on%', $method->invoke($this->model, array('qt' => 'name', 'q' => 'on'), array('name'), 'test'));
}
public function testFetch()
@ -113,9 +113,8 @@ class SqlModelTest extends PHPUnit_Framework_TestCase
$model = new ReflectionClass('SqlModel');
$method = $model->getMethod('fetch');
$method->setAccessible(true);
$key = $this->getCacheKeyMockGetSet();
$this->assertEquals('field', $method->invoke($this->model, 'SELECT', array(), $key));
$this->assertTrue(true, $method->invoke($this->model, 'SELECT', array(), $key));
}
public function testFetchField()
@ -125,7 +124,7 @@ class SqlModelTest extends PHPUnit_Framework_TestCase
$method->setAccessible(true);
$key = $this->getCacheKeyMockGetSet();
$this->assertEquals('field', $method->invoke($this->model, 'SELECT', array(), 'field', $key));
$this->assertSame('field', $method->invoke($this->model, 'SELECT', array(), 'field', $key));
}
public function testFetchAll()
@ -135,7 +134,7 @@ class SqlModelTest extends PHPUnit_Framework_TestCase
$method->setAccessible(true);
$key = $this->getCacheKeyMockGetSet();
$this->assertEquals('field', $method->invoke($this->model, 'SELECT', array(), $key));
$this->assertTrue(true, $method->invoke($this->model, 'SELECT', array(), $key));
}
public function testGetCache()

25
tests/phpunit.xml

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="bootstrap.php"
backupGlobals="true"
backupGlobals="true"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
@ -16,17 +16,18 @@
syntaxCheck="false"
testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader"
strict="true"
verbose="false">
<filter>
<blacklist>
<directory>../util/FirePHPCore-0.3.2</directory>
<directory>.</directory>
</blacklist>
</filter>
verbose="true">
<filter>
<blacklist>
<directory>../util/FirePHPCore-0.3.2</directory>
<directory>.</directory>
<file>../face/cache/autoload.php</file>
</blacklist>
</filter>
<php>
<var name="DB_DSN" value="mysql:dbname=testdb;host=localhost" />
<var name="DB_USER" value="root" />
<var name="DB_PASSWD" value="1234" />
<var name="DB_DBNAME" value="testdb" />
<var name="DB_DSN" value="mysql:dbname=testdb;host=localhost"/>
<var name="DB_USER" value="root"/>
<var name="DB_PASSWD" value="1234"/>
<var name="DB_DBNAME" value="testdb"/>
</php>
</phpunit>

16
tests/redis/RedisDebugTest.php

@ -14,6 +14,7 @@ require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
require_once dirname(__FILE__) . '/../../util/profiler/CommandProfiler.php';
require_once dirname(__FILE__) . '/../../util/profiler/Profiler.php';
require_once dirname(__FILE__) . '/../../redis/RedisDebug.php';
require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
class RedisDebugTest extends PHPUnit_Framework_TestCase
{
@ -21,17 +22,22 @@ class RedisDebugTest extends PHPUnit_Framework_TestCase
public function run(PHPUnit_Framework_TestResult $result = NULL)
{
$this->setPreserveGlobalState(false);
return parent::run($result);
}
/**
* @expectedException GeneralException
* @group Redis
*/
public function testConstructException()
{
$this->setExpectedException('GeneralException');
$redisDebug = new RedisDebug('redis');
}
/**
* @group Redis
*/
public function testConstructGood()
{
$mock = $this->getMock('Redis');
@ -47,6 +53,7 @@ class RedisDebugTest extends PHPUnit_Framework_TestCase
/**
* @runInSeparateProcess
* @group Redis
*/
public function testCallSimpleParams()
{
@ -66,6 +73,7 @@ class RedisDebugTest extends PHPUnit_Framework_TestCase
/**
* @runInSeparateProcess
* @group Redis
*/
public function testCallArrayParam()
{
@ -84,9 +92,8 @@ class RedisDebugTest extends PHPUnit_Framework_TestCase
}
/**
* @expectedException Exception
* @expectedExceptionMessage call_user_func_array() expects parameter 1 to be a valid callback
* @runInSeparateProcess
* @group Redis
*/
public function testCallUndefinedMethod()
{
@ -95,6 +102,9 @@ class RedisDebugTest extends PHPUnit_Framework_TestCase
}
$mock = $this->getMock('Redis', array('connect'));
$redisDebug = new RedisDebug($mock);
$this->setExpectedException('GeneralException');
$this->assertNull($redisDebug->nothing('localhost', 4322));
}
}

31
tests/redis/RedisManagerTest.php

@ -13,13 +13,12 @@
require_once dirname(__FILE__) . '/../../Registry.php';
require_once dirname(__FILE__) . '/../../Config.php';
require_once dirname(__FILE__) . '/../../redis/RedisManager.php';
require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
class RedisManagerTest extends PHPUnit_Framework_TestCase
{
private $connections;
public function run(PHPUnit_Framework_TestResult $result = NULL)
{
$this->setPreserveGlobalState(false);
@ -44,55 +43,57 @@ class RedisManagerTest extends PHPUnit_Framework_TestCase
}
/**
* @expectedException Exception
* @expectedExceptionMessage Trying to get property of non-object
* @TODO: line 34: $config = Config::get('Redis')->$name; - check for Redis config existence
* @group Redis
*/
public function testConnectNoAnyConfig()
{
$this->setExpectedException('GeneralException', 'Redis config no existence');
RedisManager::connect();
}
/**
* @expectedException Exception
* @expectedExceptionMessage Connection parameters must be an array
* @group Redis
*/
public function testConnectWrongPersistantConfig()
{
Config::set('Redis', array('new' => 'some'));
$this->setExpectedException('GeneralException', 'Connection parameters must be an array');
RedisManager::connect('new');
}
/**
* @expectedException Exception
* @expectedExceptionMessage Connection parameters must be an array
* @group Redis
*/
public function testConnectDefaultConfig()
{
Config::set('Redis', array('default' => 'some'));
$this->setExpectedException('GeneralException', 'Connection parameters must be an array');
RedisManager::connect();
}
/**
* @expectedException Exception
* @expectedExceptionMessage Failed to connect to Redis server at
* @group Redis
*/
public function testConnectFailedConnection()
{
Config::set('Redis', array('new' => array('host' => 'error', 'port' => 2023, 'database' => 'some')));
$this->setExpectedException('GeneralException', 'Failed to connect to Redis server at');
RedisManager::connect('new');
}
/**
* @expectedException Exception
* @expectedExceptionMessage Failed to select Redis database with index
* @group Redis
*/
public function testConnectEstablishedConnectionNoDb()
{
Config::set('Redis', array('new' => array('host' => true, 'port' => 2023, 'database' => 'some')));
$this->setExpectedException('GeneralException', 'Failed to select Redis database with index');
RedisManager::connect('new');
}
/**
* @group Redis
*/
public function testConnectionGood()
{
Config::set('Redis', array('new' => array('host' => true, 'port' => 2023, 'database' => true)));
@ -102,6 +103,7 @@ class RedisManagerTest extends PHPUnit_Framework_TestCase
/**
* @runInSeparateProcess
* @group Redis
*/
public function testConnectWithDebug()
{
@ -115,6 +117,9 @@ class RedisManagerTest extends PHPUnit_Framework_TestCase
$this->assertInstanceOf('RedisDebugMock', $redis);
}
/**
* @group Redis
*/
public function testConnectWithConfigArray()
{
$config = array('host' => true, 'port' => 2023, 'database' => true);

22
tests/session/SessionTest.php

@ -43,8 +43,8 @@ class SessionTest extends PHPUnit_Framework_TestCase
Session::set('one', 1);
Session::set('two', 'three');
Session::set(array('first' => '1st', 'second' => '2nd'));
$this->assertEquals('1st', Session::get('first'));
$this->assertEquals('three', Session::get('two'));
$this->assertSame('1st', Session::get('first'));
$this->assertSame('three', Session::get('two'));
$this->assertNotEquals('three', Session::get('thr'));
}
@ -58,21 +58,21 @@ class SessionTest extends PHPUnit_Framework_TestCase
public function testReturnDefaultValue()
{
Session::start();
$this->assertEquals(1, Session::get('key', 1));
$this->assertSame(1, Session::get('key', 1));
}
public function testDestroyedGet()
{
$this->assertFalse($this->started->getValue());
$_COOKIE[session_name()] = session_name();
$this->assertEquals(1, Session::get('key', 1));
$this->assertSame(1, Session::get('key', 1));
}
public function testDel()
{
Session::set('one', 1);
Session::set('two', 'three');
$this->assertEquals('three', Session::get('two'));
$this->assertSame('three', Session::get('two'));
Session::del('two');
$this->assertNull(Session::get('two'));
}
@ -109,10 +109,10 @@ class SessionTest extends PHPUnit_Framework_TestCase
$new_params = session_get_cookie_params();
$this->assertNotEquals($ssid, $new_ssid);
$this->assertNotEquals($params, $new_params);
$this->assertEquals(400, $new_params['lifetime']);
$this->assertSame(400, $new_params['lifetime']);
Session::rememberUntil();
$new_params = session_get_cookie_params();
$this->assertEquals(0, $new_params['lifetime']);
$this->assertSame(0, $new_params['lifetime']);
}
public function testForget()
@ -123,7 +123,7 @@ class SessionTest extends PHPUnit_Framework_TestCase
$new_ssid = Session::getId();
$new_params = session_get_cookie_params();
$this->assertNotEquals($ssid, $new_ssid);
$this->assertEquals(0, $new_params['lifetime']);
$this->assertSame(0, $new_params['lifetime']);
}
public function testRemember()
@ -132,15 +132,15 @@ class SessionTest extends PHPUnit_Framework_TestCase
$ssid = Session::getId();
Session::remember();
$new_params = session_get_cookie_params();
$this->assertEquals(1209600, $new_params['lifetime']);
$this->assertSame(1209600, $new_params['lifetime']);
Session::remember(-30);
$new_params = session_get_cookie_params();
$this->assertEquals(1209600, $new_params['lifetime']);
$this->assertSame(1209600, $new_params['lifetime']);
Session::remember(530);
$new_params = session_get_cookie_params();
$this->assertEquals(530, $new_params['lifetime']);
$this->assertSame(530, $new_params['lifetime']);
}
public function testExpireSessionCookie()

8
tests/util/AutoloadBuilderTest.php

@ -34,8 +34,6 @@ class AutoloadBuilderTest extends PHPUnit_Framework_TestCase
/**
* @TODO: Load->buildAutoload() - uses two paths - PATH . '/' . APP . '/src' and PATH . '/lib' those are not checked. Can couse error.
* @expectedException UnexpectedValueException
* @expectedException PHPUnit_Framework_Error
*/
public static function setUpBeforeClass()
{
@ -58,7 +56,6 @@ class AutoloadBuilderTest extends PHPUnit_Framework_TestCase
/**
* @TODO: AutoloadBuilder - check input params: string for filename, array for dirs
* @expectedException PHPUnit_Framework_Error
* @runInSeparateProcess
*/
public function testBuildParams()
@ -68,6 +65,7 @@ class AutoloadBuilderTest extends PHPUnit_Framework_TestCase
$dirs = 'string';
$builder = new AutoloadBuilder($autoload, $dirs);
$this->setExpectedException('PHPUnit_Framework_Error');
$builder->build();
}
@ -89,12 +87,14 @@ class AutoloadBuilderTest extends PHPUnit_Framework_TestCase
}
/**
* @expectedException PHPUnit_Framework_Error
* @runInSeparateProcess
*/
public function testAccessDenied()
{
$this->setConstants();
$this->setExpectedException('PHPUnit_Framework_Error');
chmod(self::$file, 0400);
$builder = new AutoloadBuilder(self::$file, array(self::$path . '/' . self::$app . '/src', self::$path . '/' . self::$app . '/cache', self::$path . '/lib'));

4
tests/util/AutoloadBuilderTestVFS.php

@ -27,8 +27,6 @@ class AutoloadBuilderTestVFS extends PHPUnit_Framework_TestCase
/**
* @TODO: Load->buildAutoload() - uses two paths - PATH . '/' . APP . '/src' and PATH . '/lib' those are not checked. Can couse error.
* @expectedException UnexpectedValueException
* @expectedException PHPUnit_Framework_Error
*/
public function setUp()
{
@ -99,7 +97,7 @@ class AutoloadBuilderTestVFS extends PHPUnit_Framework_TestCase
$this->assertInternalType('array', $this->array);
$this->assertArrayHasKey('Load', $this->array);
$this->assertArrayNotHasKey('Key', $this->array);
$this->assertEquals(2, count($this->array));
$this->assertSame(2, count($this->array));
}
public function testAutoloadHasNoAccess()

4
tests/util/profiler/CommandProfilerTest.php

@ -30,13 +30,13 @@ class CommandProfilerTest extends PHPUnit_Framework_TestCase
public function testGetType()
{
$this->assertEquals('method', $this->profiler->getType());
$this->assertSame('method', $this->profiler->getType());
$this->assertNotEquals('argument', $this->profiler->getType());
}
public function testGetCommand()
{
$this->assertEquals('exec', $this->profiler->getCommand());
$this->assertSame('exec', $this->profiler->getCommand());
$this->assertNotEquals('grep', $this->profiler->getCommand());
}
}

5
tests/util/profiler/ProfilerTest.php

@ -32,8 +32,6 @@ class ProfilerTest extends PHPUnit_Framework_TestCase
}
/**
* @expectedException GeneralException
* @expectedExceptionMessage Need to turn on DEBUG before use.
* @runInSeparateProcess
*/
public function testGetInstaceNoDebug()
@ -41,6 +39,7 @@ class ProfilerTest extends PHPUnit_Framework_TestCase
if (!defined('DEBUG')) {
define('DEBUG', false);
}
$this->setExpectedException('GeneralException', 'Need to turn on DEBUG before use.');
Profiler::getInstance();
}
@ -88,7 +87,7 @@ class ProfilerTest extends PHPUnit_Framework_TestCase
$this->assertContains('<div style="clear:both; font:12px monospace; margin: 5px; white-space: pre;">', $result);
$this->assertEquals('html', $profiler->end('html'));
$this->assertSame('html', $profiler->end('html'));
}
/**

6
tests/validator/EqualValidatorTest.php

@ -13,6 +13,7 @@
require_once dirname(__FILE__) . '/../../validator/iValidator.php';
require_once dirname(__FILE__) . '/../../validator/Validator.php';
require_once dirname(__FILE__) . '/../../validator/EqualValidator.php';
require_once dirname(__FILE__) . '/../../exception/InitializationException.php';
class EqualValidatorTest extends PHPUnit_Framework_TestCase
{
@ -23,13 +24,10 @@ class EqualValidatorTest extends PHPUnit_Framework_TestCase
$this->assertTrue($validator->isValid('token'));
}
/**
* @expectedException Exception
* @expectedExceptionMessage Token not defined
*/
public function testNullToken()
{
$validator = new EqualValidator(null);
$this->setExpectedException('InitializationException','Token not defined');
$validator->isValid('not token');
}

18
tests/validator/RegexValidatorTest.php

@ -13,6 +13,7 @@
require_once dirname(__FILE__) . '/../../validator/iValidator.php';
require_once dirname(__FILE__) . '/../../validator/Validator.php';
require_once dirname(__FILE__) . '/../../validator/RegexValidator.php';
require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
class RegexValidatorTest extends PHPUnit_Framework_TestCase
{
@ -41,37 +42,34 @@ class RegexValidatorTest extends PHPUnit_Framework_TestCase
$this->assertEmpty($validator->getMessage());
$validator->setMessage('i am ok');
$validator->isValid('2131');
$this->assertEquals('i am ok', $validator->getMessage());
$this->assertSame('i am ok', $validator->getMessage());
}
/**
* @expectedException Exception
* @expectedExceptionMessage Message template "regex_not_match" unknown.
*/
public function testNullMessage()
{
$validator = new RegexValidator('/a/i');
$validator->setMessage(null, null);
$this->setExpectedException('GeneralException', 'Message template "regex_not_match" unknown.');
$validator->isValid('1212');
}
/**
* @TODO: RegexValidator - wrong regex throws an error. Check this.
* @expectedException PHPUnit_Framework_Error
*/
public function testWrongRegexp()
{
$validator = new RegexValidator('/^[a-z][0-9]$*/i');
$this->setExpectedException('PHPUnit_Framework_Error');
$this->assertFalse($validator->isValid('to423$%ny'));
}
/**
* @expectedException Exception
* @expectedExceptionMessage regex
*/
public function testRegexReturnsFalse()
{
$validator = new RegexValidator('/(?:\D+|<\d+>)*[!?]/');
$this->setExpectedException('GeneralException', 'regex');
$this->assertFalse($validator->isValid('foobar foobar foobar'));
}
}

23
tests/view/PHPViewTest.php

@ -16,6 +16,7 @@ require_once dirname(__FILE__) . '/../../view/helpers/ViewHelper.php';
require_once dirname(__FILE__) . '/../../view/helpers/TitleViewHelper.php';
require_once dirname(__FILE__) . '/../../view/PHPView.php';
require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
require_once dirname(__FILE__) . '/../../exception/InitializationException.php';
require_once 'vfsStream/vfsStream.php';
class PHPViewTest extends PHPUnit_Framework_TestCase
@ -41,15 +42,13 @@ class PHPViewTest extends PHPUnit_Framework_TestCase
public function testPHPViewConstructor()
{
$this->assertInstanceOf('PHPView', $this->view);
$this->assertEquals('vfs://root/views/', $this->view->getPath());
$this->assertSame('vfs://root/views/', $this->view->getPath());
}
/**
* @expectedException Exception
* @expectedExceptionMessage Configuration must have a "path" set.
*/
public function testPHPViewNullConstructor()
{
$this->setExpectedException('InitializationException', 'Configuration must have a "path" set.');
$view = new PHPView(null);
}
@ -76,7 +75,7 @@ class PHPViewTest extends PHPUnit_Framework_TestCase
public function testEscape()
{
$result = $this->view->escape('"<>"');
$this->assertEquals('&quot;&lt;&gt;&quot;', $result);
$this->assertSame('&quot;&lt;&gt;&quot;', $result);
}
public function testCall()
@ -85,12 +84,10 @@ class PHPViewTest extends PHPUnit_Framework_TestCase
$this->assertContains('New title', Registry::get('TitleViewHelper'));
}
/**
* @expectedException GeneralException
* @expectedExceptionMessage View helper "WriteViewHelper" not found.
*/
public function testIllegalCall()
{
$this->setExpectedException('GeneralException', 'View helper "WriteViewHelper" not found.');
$this->view->write('tony');
}
@ -137,14 +134,10 @@ class PHPViewTest extends PHPUnit_Framework_TestCase
}
/**
* @expectedException Exception
* @expectedExceptionMessage Template
*/
public function testErrorTemplate()
{
$view = new PHPView(array('path' => 'error_path/'));
$this->setExpectedException('GeneralException', 'Template');
$result = $view->fetch('test');
}

12
tests/view/helpers/GetViewHelperTest.php

@ -28,19 +28,19 @@ class GetViewHelperTest extends PHPUnit_Framework_TestCase
/**
* @TODO: GetViewHelper: initialize GetViewHelper::$get with empty array()
* @expectedException PHPUnit_Framework_Error
*/
public function testGetWithNull()
{
$this->setExpectedException('PHPUnit_Framework_Error');
$this->helper->get(null);
}
/**
* @TODO: GetViewHelper: check $_GET not null
* @expectedException PHPUnit_Framework_Error
*/
public function testGetEmptyGET()
{
$this->setExpectedException('PHPUnit_Framework_Error');
$result = $this->helper->get('param');
}
@ -48,16 +48,16 @@ class GetViewHelperTest extends PHPUnit_Framework_TestCase
{
$_GET['a'] = 'b';
$result = $this->helper->get(null);
$this->assertEquals('?a=b', $result);
$this->assertSame('?a=b', $result);
$this->helper = new GetViewHelper(new PHPView('any'));
$_GET['a'] = 'b';
$_GET['b'] = 'a';
$result = $this->helper->get(array('a' => 'c'));
$this->assertEquals('?a=c&amp;b=a', $result);
$this->assertSame('?a=c&amp;b=a', $result);
$_GET['a'] = 'b';
$_GET['b'] = 'a';
$result = $this->helper->get(array('a'));
$this->assertEquals('?b=a', $result);
$this->assertSame('?b=a', $result);
}
public function testGetWithArray()
@ -66,7 +66,7 @@ class GetViewHelperTest extends PHPUnit_Framework_TestCase
$_GET['b'] = 'a';
$_GET['c'] = array('three' => 'four');
$result = $this->helper->get(array('b' => 'c', 'c' => array('five' => 'six')));
$this->assertEquals('?a[one]=1&amp;a[two]=2&amp;b=c&amp;c[five]=six', $result);
$this->assertSame('?a[one]=1&amp;a[two]=2&amp;b=c&amp;c[five]=six', $result);
}
}

9
tests/view/helpers/MsgViewHelperTest.php

@ -15,6 +15,7 @@ require_once dirname(__FILE__) . '/../../../view/iView.php';
require_once dirname(__FILE__) . '/../../../view/PHPView.php';
require_once dirname(__FILE__) . '/../../../view/helpers/ViewHelper.php';
require_once dirname(__FILE__) . '/../../../view/helpers/MsgViewHelper.php';
require_once dirname(__FILE__) . '/../../../exception/GeneralException.php';
class MsgViewHelperTest extends PHPUnit_Framework_TestCase
{
@ -29,19 +30,19 @@ class MsgViewHelperTest extends PHPUnit_Framework_TestCase
public function testMsg()
{
$this->helper->msg('new message from test', 'success');
$this->assertSame(array('message' => 'new message from test', 'type' => 'success'), Session::get('MsgViewHelper'));
$this->assertSame($this->helper, $this->helper->msg('error message', 'error'));
$this->assertSame(array('message' => 'error message', 'type' => 'error'), Session::get('MsgViewHelper'));
}
/**
* @expectedException Exception
* @expectedExceptionMessage Unknown message type
*/
public function testWrongType()
{
$this->setExpectedException('GeneralException', 'Unknown message type');
$this->helper->msg('some message', 'wrong');
}

2
validator/EqualValidator.php

@ -27,7 +27,7 @@ class EqualValidator extends Validator
{
$this->setValue($value);
if ($this->token === null) {
throw new Exception('Token not defined.');
throw new InitializationException('Token not defined.');
}
if ($value !== $this->token) {

2
validator/RegexValidator.php

@ -30,7 +30,7 @@ class RegexValidator extends Validator
$status = preg_match($this->regex, $value);
if ($status === false) {
throw new Exception('Internal error matching regex "' . $this->regex . ' against value "' . $value . '"');
throw new GeneralException('Internal error matching regex "' . $this->regex . ' against value "' . $value . '"');
}
if (!$status) {
$this->error();

2
validator/Validator.php

@ -51,7 +51,7 @@ abstract class Validator implements iValidator
protected function createMessage($template, $value)
{
if (!isset($this->templates[$template])) {
throw new Exception('Message template "' . $template . '" unknown.');
throw new GeneralException('Message template "' . $template . '" unknown.');
}
$message = $this->templates[$template];

4
view/PHPView.php

@ -24,7 +24,7 @@ class PHPView implements iView
public function __construct($config)
{
if (!isset($config['path'])) {
throw new Exception('Configuration must have a "path" set.');
throw new InitializationException('Configuration must have a "path" set.');
}
$this->setPath($config['path']);
}
@ -92,7 +92,7 @@ class PHPView implements iView
ob_start();
if (!is_readable($this->template)) {
ob_clean();
throw new Exception('Template "' . $this->template .'" not found.');
throw new GeneralException('Template "' . $this->template .'" not found.');
}
include($this->template);
return ob_get_clean();

2
view/helpers/MsgViewHelper.php

@ -21,7 +21,7 @@ class MsgViewHelper extends ViewHelper
{
if ($msg && $type) {
if (!in_array($type, array(self::SUCCESS, self::ERROR))) {
throw new Exception('Unknown message type: "' . $type . '"');
throw new GeneralException('Unknown message type: "' . $type . '"');
}
Session::set(__CLASS__, array('message' => $msg, 'type' => $type));
}

Loading…
Cancel
Save