diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index c6a6bbd..517b378 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -42,14 +42,14 @@ class ConfigTest extends PHPUnit_Framework_TestCase 'three' => 3, 4 => 'four' ); - $this->setExpectedException('GeneralException', 'Configuration variable'); 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->assertNotEquals(1, $new_arr->offsetGet('two')); - + + $this->setExpectedException('GeneralException', 'Configuration variable'); $new_arr->some; } diff --git a/tests/LoadTest.php b/tests/LoadTest.php index bad796f..e8562df 100644 --- a/tests/LoadTest.php +++ b/tests/LoadTest.php @@ -144,10 +144,10 @@ class LoadTest extends PHPUnit_Framework_TestCase */ public function testAutoloadGetFilePathNullIndex() { - $this->setExpectedException('PHPUnit_Framework_Error'); $this->setConstants(); Load::setAutoloadFrom(self::$file); $autoload = require(self::$file); + $this->setExpectedException('PHPUnit_Framework_Error'); $this->assertNotEmpty(Load::getFilePath('anton')); } diff --git a/tests/RegistryTest.php b/tests/RegistryTest.php index c5c17b3..3ec4f8c 100644 --- a/tests/RegistryTest.php +++ b/tests/RegistryTest.php @@ -61,11 +61,12 @@ class RegistryTest extends PHPUnit_Framework_TestCase */ public function testIsRegistered() { - $this->setExpectedException('PHPUnit_Framework_Error'); $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)); } } \ No newline at end of file diff --git a/tests/app/router/RouteTest.php b/tests/app/router/RouteTest.php index 242bd6b..c84234d 100644 --- a/tests/app/router/RouteTest.php +++ b/tests/app/router/RouteTest.php @@ -73,8 +73,8 @@ class RouteTest extends PHPUnit_Framework_TestCase */ public function testMatchEmptyRequest() { - $this->setExpectedException('PHPUnit_Framework_Error'); $route = new Route('', 'user', array('name' => 'tony', 'role' => 'user')); + $this->setExpectedException('PHPUnit_Framework_Error'); $route->match(''); } } \ No newline at end of file diff --git a/tests/logger/FileLoggerTest.php b/tests/logger/FileLoggerTest.php index a5b1401..e05f0be 100644 --- a/tests/logger/FileLoggerTest.php +++ b/tests/logger/FileLoggerTest.php @@ -54,8 +54,10 @@ class FileLoggerTest extends PHPUnit_Framework_TestCase define('DEBUG', true); } $conf = array('logger' => 'FileLogger', 'filepath' => '/log.txt'); - $this->setExpectedException('GeneralException', 'Could not open file /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'); } diff --git a/tests/model/DbDriverTest.php b/tests/model/DbDriverTest.php index c093735..8ec4f48 100644 --- a/tests/model/DbDriverTest.php +++ b/tests/model/DbDriverTest.php @@ -39,8 +39,10 @@ class DbDriverTest extends PHPUnit_Framework_TestCase public function testConstructWrongConfig() { - $this->setExpectedException('GeneralException', 'Configuration must have a "username"'); $conf = array('hostname' => 'localhost', 'database' => 'db'); + + $this->setExpectedException('GeneralException', 'Configuration must have a "username"'); + $this->getMockForAbstractClass('DbDriver', array($conf)); } diff --git a/tests/model/DbStatementTest.php b/tests/model/DbStatementTest.php index 22b34d2..ee3bacf 100644 --- a/tests/model/DbStatementTest.php +++ b/tests/model/DbStatementTest.php @@ -69,8 +69,8 @@ class DbStatementTest extends PHPUnit_Framework_TestCase public function testBindParamExceptionWrongObject() { - $this->setExpectedException('GeneralException', 'Objects excepts DbExpr not allowed.'); $val = $this->getMock('NotDbExpr'); + $this->setExpectedException('GeneralException', 'Objects excepts DbExpr not allowed.'); $this->stmt->bindParam('paa', $val); } diff --git a/tests/model/DbTest.php b/tests/model/DbTest.php index f0cda28..cb44679 100644 --- a/tests/model/DbTest.php +++ b/tests/model/DbTest.php @@ -49,9 +49,8 @@ class DbTest extends PHPUnit_Framework_TestCase public function testConnectWithWrongDriver() { - $this->setExpectedException('InitializationException', 'Database driver must extends DbDriver'); $this->getMock('NotDbDriver', array(), array(), 'NoDbDriverMock'); + $this->setExpectedException('InitializationException', 'Database driver must extends DbDriver'); $driver = Db::connect('nodb', array('hostname' => 'localhost', 'driver' => 'NoDbDriverMock')); } - } \ No newline at end of file diff --git a/tests/model/MySQLiDriverTest.php b/tests/model/MySQLiDriverTest.php index 86c1799..ee77957 100644 --- a/tests/model/MySQLiDriverTest.php +++ b/tests/model/MySQLiDriverTest.php @@ -85,10 +85,11 @@ class MySQLiDriverTest extends PHPUnit_Extensions_Database_TestCase if (!defined('DEBUG')) { define('DEBUG', false); } - - $this->setExpectedException('GeneralException', 'Unknown database \'nodb\''); $this->conf['database'] = 'nodb'; $driver = new MySQLiDriver($this->conf); + + $this->setExpectedException('GeneralException', 'Unknown database \'nodb\''); + $this->assertNull('mysqli', $driver->getConnection()); } diff --git a/tests/model/MySQLiStatementTest.php b/tests/model/MySQLiStatementTest.php index 1c94078..1d3f056 100644 --- a/tests/model/MySQLiStatementTest.php +++ b/tests/model/MySQLiStatementTest.php @@ -70,8 +70,8 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase if (!defined('DEBUG')) { define('DEBUG', false); } - $this->setExpectedException('GeneralException', 'ERROR'); $this->setDriverGetConnectionWrongResultMethod(); + $this->setExpectedException('GeneralException', 'ERROR'); $this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val')); } @@ -174,9 +174,11 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase if (!defined('DEBUG')) { define('DEBUG', false); } - $this->setExpectedException('GeneralException'); $this->setDriverGetConnectionMethod(); $this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val')); + + $this->setExpectedException('GeneralException'); + $this->stmt->fetch(324); } diff --git a/tests/redis/RedisDebugTest.php b/tests/redis/RedisDebugTest.php index 4380820..3f72882 100644 --- a/tests/redis/RedisDebugTest.php +++ b/tests/redis/RedisDebugTest.php @@ -91,10 +91,9 @@ class RedisDebugTest extends PHPUnit_Framework_TestCase if (!defined('DEBUG')) { define('DEBUG', true); } - - $this->setExpectedException('GeneralException', 'call_user_func_array() expects parameter 1 to be a valid callback'); $mock = $this->getMock('Redis', array('connect')); $redisDebug = new RedisDebug($mock); + $this->setExpectedException('GeneralException'); $this->assertNull($redisDebug->nothing('localhost', 4322)); diff --git a/tests/redis/RedisManagerTest.php b/tests/redis/RedisManagerTest.php index f80f2e6..8c159f6 100644 --- a/tests/redis/RedisManagerTest.php +++ b/tests/redis/RedisManagerTest.php @@ -50,29 +50,29 @@ class RedisManagerTest extends PHPUnit_Framework_TestCase public function testConnectWrongPersistantConfig() { - $this->setExpectedException('GeneralException', 'Connection parameters must be an array'); Config::set('Redis', array('new' => 'some')); + $this->setExpectedException('GeneralException', 'Connection parameters must be an array'); RedisManager::connect('new'); } public function testConnectDefaultConfig() { - $this->setExpectedException('GeneralException', 'Connection parameters must be an array'); Config::set('Redis', array('default' => 'some')); + $this->setExpectedException('GeneralException', 'Connection parameters must be an array'); RedisManager::connect(); } public function testConnectFailedConnection() { - $this->setExpectedException('GeneralException', 'Failed to connect to Redis server at'); 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'); } public function testConnectEstablishedConnectionNoDb() { - $this->setExpectedException('GeneralException', 'Failed to select Redis database with index'); 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'); } diff --git a/tests/util/AutoloadBuilderTest.php b/tests/util/AutoloadBuilderTest.php index 8ec568c..a3aaff9 100644 --- a/tests/util/AutoloadBuilderTest.php +++ b/tests/util/AutoloadBuilderTest.php @@ -60,12 +60,12 @@ class AutoloadBuilderTest extends PHPUnit_Framework_TestCase */ public function testBuildParams() { - $this->setExpectedException('PHPUnit_Framework_Error'); $this->setConstants(); $autoload = self::$file; $dirs = 'string'; $builder = new AutoloadBuilder($autoload, $dirs); + $this->setExpectedException('PHPUnit_Framework_Error'); $builder->build(); } @@ -91,8 +91,10 @@ class AutoloadBuilderTest extends PHPUnit_Framework_TestCase */ public function testAccessDenied() { - $this->setExpectedException('PHPUnit_Framework_Error'); $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')); diff --git a/tests/validator/EqualValidatorTest.php b/tests/validator/EqualValidatorTest.php index 2aa158c..4b86cdc 100644 --- a/tests/validator/EqualValidatorTest.php +++ b/tests/validator/EqualValidatorTest.php @@ -26,8 +26,8 @@ class EqualValidatorTest extends PHPUnit_Framework_TestCase public function testNullToken() { - $this->setExpectedException('InitializationException','Token not defined'); $validator = new EqualValidator(null); + $this->setExpectedException('InitializationException','Token not defined'); $validator->isValid('not token'); } diff --git a/tests/validator/RegexValidatorTest.php b/tests/validator/RegexValidatorTest.php index 95a9479..0a7e64d 100644 --- a/tests/validator/RegexValidatorTest.php +++ b/tests/validator/RegexValidatorTest.php @@ -48,9 +48,11 @@ class RegexValidatorTest extends PHPUnit_Framework_TestCase public function testNullMessage() { - $this->setExpectedException('GeneralException', 'Message template "regex_not_match" unknown.'); $validator = new RegexValidator('/a/i'); $validator->setMessage(null, null); + + $this->setExpectedException('GeneralException', 'Message template "regex_not_match" unknown.'); + $validator->isValid('1212'); } @@ -59,15 +61,15 @@ class RegexValidatorTest extends PHPUnit_Framework_TestCase */ public function testWrongRegexp() { - $this->setExpectedException('PHPUnit_Framework_Error'); $validator = new RegexValidator('/^[a-z][0-9]$*/i'); + $this->setExpectedException('PHPUnit_Framework_Error'); $this->assertFalse($validator->isValid('to423$%ny')); } public function testRegexReturnsFalse() { - $this->setExpectedException('GeneralException', 'regex'); $validator = new RegexValidator('/(?:\D+|<\d+>)*[!?]/'); + $this->setExpectedException('GeneralException', 'regex'); $this->assertFalse($validator->isValid('foobar foobar foobar')); } } \ No newline at end of file diff --git a/tests/view/PHPViewTest.php b/tests/view/PHPViewTest.php index 1236202..2914699 100644 --- a/tests/view/PHPViewTest.php +++ b/tests/view/PHPViewTest.php @@ -136,9 +136,8 @@ class PHPViewTest extends PHPUnit_Framework_TestCase public function testErrorTemplate() { - $this->setExpectedException('GeneralException', 'Template'); $view = new PHPView(array('path' => 'error_path/')); - + $this->setExpectedException('GeneralException', 'Template'); $result = $view->fetch('test'); }