Moving setExpectedException
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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'));
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
@ -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('');
|
||||
}
|
||||
}
|
@ -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');
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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'));
|
||||
}
|
||||
|
||||
}
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
|
@ -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');
|
||||
}
|
||||
|
||||
|
@ -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'));
|
||||
|
||||
|
@ -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');
|
||||
}
|
||||
|
||||
|
@ -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'));
|
||||
}
|
||||
}
|
@ -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');
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user