Browse Source

Moving setExpectedException

master
Vyacheslav Agafonov 13 years ago
parent
commit
0fda3de8b5
  1. 4
      tests/ConfigTest.php
  2. 2
      tests/LoadTest.php
  3. 5
      tests/RegistryTest.php
  4. 2
      tests/app/router/RouteTest.php
  5. 4
      tests/logger/FileLoggerTest.php
  6. 4
      tests/model/DbDriverTest.php
  7. 2
      tests/model/DbStatementTest.php
  8. 3
      tests/model/DbTest.php
  9. 5
      tests/model/MySQLiDriverTest.php
  10. 6
      tests/model/MySQLiStatementTest.php
  11. 3
      tests/redis/RedisDebugTest.php
  12. 8
      tests/redis/RedisManagerTest.php
  13. 6
      tests/util/AutoloadBuilderTest.php
  14. 2
      tests/validator/EqualValidatorTest.php
  15. 8
      tests/validator/RegexValidatorTest.php
  16. 3
      tests/view/PHPViewTest.php

4
tests/ConfigTest.php

@ -42,14 +42,14 @@ class ConfigTest extends PHPUnit_Framework_TestCase
'three' => 3, 'three' => 3,
4 => 'four' 4 => 'four'
); );
$this->setExpectedException('GeneralException', 'Configuration variable');
Config::set(0, $arr); Config::set(0, $arr);
$new_arr = Config::get(0); $new_arr = Config::get(0);
$this->assertEquals('ConfigArray', get_class($new_arr)); $this->assertEquals('ConfigArray', get_class($new_arr));
$this->assertEquals('four', $new_arr->offsetGet(4)); $this->assertEquals('four', $new_arr->offsetGet(4));
$this->assertEquals(1, $new_arr->one); $this->assertEquals(1, $new_arr->one);
$this->assertNotEquals(1, $new_arr->offsetGet('two')); $this->assertNotEquals(1, $new_arr->offsetGet('two'));
$this->setExpectedException('GeneralException', 'Configuration variable');
$new_arr->some; $new_arr->some;
} }

2
tests/LoadTest.php

@ -144,10 +144,10 @@ class LoadTest extends PHPUnit_Framework_TestCase
*/ */
public function testAutoloadGetFilePathNullIndex() public function testAutoloadGetFilePathNullIndex()
{ {
$this->setExpectedException('PHPUnit_Framework_Error');
$this->setConstants(); $this->setConstants();
Load::setAutoloadFrom(self::$file); Load::setAutoloadFrom(self::$file);
$autoload = require(self::$file); $autoload = require(self::$file);
$this->setExpectedException('PHPUnit_Framework_Error');
$this->assertNotEmpty(Load::getFilePath('anton')); $this->assertNotEmpty(Load::getFilePath('anton'));
} }

5
tests/RegistryTest.php

@ -61,11 +61,12 @@ class RegistryTest extends PHPUnit_Framework_TestCase
*/ */
public function testIsRegistered() public function testIsRegistered()
{ {
$this->setExpectedException('PHPUnit_Framework_Error');
$this->assertFalse(Registry::isRegistered(43)); $this->assertFalse(Registry::isRegistered(43));
$this->_registry->set(3, 'three'); $this->_registry->set(3, 'three');
$this->assertTrue(Registry::isRegistered(3)); $this->assertTrue(Registry::isRegistered(3));
$this->setExpectedException('PHPUnit_Framework_Error');
$this->assertFalse(Registry::isRegistered(null)); $this->assertFalse(Registry::isRegistered(null));
} }
} }

2
tests/app/router/RouteTest.php

@ -73,8 +73,8 @@ class RouteTest extends PHPUnit_Framework_TestCase
*/ */
public function testMatchEmptyRequest() public function testMatchEmptyRequest()
{ {
$this->setExpectedException('PHPUnit_Framework_Error');
$route = new Route('', 'user', array('name' => 'tony', 'role' => 'user')); $route = new Route('', 'user', array('name' => 'tony', 'role' => 'user'));
$this->setExpectedException('PHPUnit_Framework_Error');
$route->match(''); $route->match('');
} }
} }

4
tests/logger/FileLoggerTest.php

@ -54,8 +54,10 @@ class FileLoggerTest extends PHPUnit_Framework_TestCase
define('DEBUG', true); define('DEBUG', true);
} }
$conf = array('logger' => 'FileLogger', 'filepath' => '/log.txt'); $conf = array('logger' => 'FileLogger', 'filepath' => '/log.txt');
$this->setExpectedException('GeneralException', 'Could not open file /log.txt');
Config::set('Logger', $conf); Config::set('Logger', $conf);
$this->setExpectedException('GeneralException', 'Could not open file /log.txt');
$logger = Logger::getInstance()->log('new msg'); $logger = Logger::getInstance()->log('new msg');
$this->assertFileNotExists('log.txt'); $this->assertFileNotExists('log.txt');
} }

4
tests/model/DbDriverTest.php

@ -39,8 +39,10 @@ class DbDriverTest extends PHPUnit_Framework_TestCase
public function testConstructWrongConfig() public function testConstructWrongConfig()
{ {
$this->setExpectedException('GeneralException', 'Configuration must have a "username"');
$conf = array('hostname' => 'localhost', 'database' => 'db'); $conf = array('hostname' => 'localhost', 'database' => 'db');
$this->setExpectedException('GeneralException', 'Configuration must have a "username"');
$this->getMockForAbstractClass('DbDriver', array($conf)); $this->getMockForAbstractClass('DbDriver', array($conf));
} }

2
tests/model/DbStatementTest.php

@ -69,8 +69,8 @@ class DbStatementTest extends PHPUnit_Framework_TestCase
public function testBindParamExceptionWrongObject() public function testBindParamExceptionWrongObject()
{ {
$this->setExpectedException('GeneralException', 'Objects excepts DbExpr not allowed.');
$val = $this->getMock('NotDbExpr'); $val = $this->getMock('NotDbExpr');
$this->setExpectedException('GeneralException', 'Objects excepts DbExpr not allowed.');
$this->stmt->bindParam('paa', $val); $this->stmt->bindParam('paa', $val);
} }

3
tests/model/DbTest.php

@ -49,9 +49,8 @@ class DbTest extends PHPUnit_Framework_TestCase
public function testConnectWithWrongDriver() public function testConnectWithWrongDriver()
{ {
$this->setExpectedException('InitializationException', 'Database driver must extends DbDriver');
$this->getMock('NotDbDriver', array(), array(), 'NoDbDriverMock'); $this->getMock('NotDbDriver', array(), array(), 'NoDbDriverMock');
$this->setExpectedException('InitializationException', 'Database driver must extends DbDriver');
$driver = Db::connect('nodb', array('hostname' => 'localhost', 'driver' => 'NoDbDriverMock')); $driver = Db::connect('nodb', array('hostname' => 'localhost', 'driver' => 'NoDbDriverMock'));
} }
} }

5
tests/model/MySQLiDriverTest.php

@ -85,10 +85,11 @@ class MySQLiDriverTest extends PHPUnit_Extensions_Database_TestCase
if (!defined('DEBUG')) { if (!defined('DEBUG')) {
define('DEBUG', false); define('DEBUG', false);
} }
$this->setExpectedException('GeneralException', 'Unknown database \'nodb\'');
$this->conf['database'] = 'nodb'; $this->conf['database'] = 'nodb';
$driver = new MySQLiDriver($this->conf); $driver = new MySQLiDriver($this->conf);
$this->setExpectedException('GeneralException', 'Unknown database \'nodb\'');
$this->assertNull('mysqli', $driver->getConnection()); $this->assertNull('mysqli', $driver->getConnection());
} }

6
tests/model/MySQLiStatementTest.php

@ -70,8 +70,8 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
if (!defined('DEBUG')) { if (!defined('DEBUG')) {
define('DEBUG', false); define('DEBUG', false);
} }
$this->setExpectedException('GeneralException', 'ERROR');
$this->setDriverGetConnectionWrongResultMethod(); $this->setDriverGetConnectionWrongResultMethod();
$this->setExpectedException('GeneralException', 'ERROR');
$this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val')); $this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
} }
@ -174,9 +174,11 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
if (!defined('DEBUG')) { if (!defined('DEBUG')) {
define('DEBUG', false); define('DEBUG', false);
} }
$this->setExpectedException('GeneralException');
$this->setDriverGetConnectionMethod(); $this->setDriverGetConnectionMethod();
$this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val')); $this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
$this->setExpectedException('GeneralException');
$this->stmt->fetch(324); $this->stmt->fetch(324);
} }

3
tests/redis/RedisDebugTest.php

@ -91,10 +91,9 @@ class RedisDebugTest extends PHPUnit_Framework_TestCase
if (!defined('DEBUG')) { if (!defined('DEBUG')) {
define('DEBUG', true); define('DEBUG', true);
} }
$this->setExpectedException('GeneralException', 'call_user_func_array() expects parameter 1 to be a valid callback');
$mock = $this->getMock('Redis', array('connect')); $mock = $this->getMock('Redis', array('connect'));
$redisDebug = new RedisDebug($mock); $redisDebug = new RedisDebug($mock);
$this->setExpectedException('GeneralException'); $this->setExpectedException('GeneralException');
$this->assertNull($redisDebug->nothing('localhost', 4322)); $this->assertNull($redisDebug->nothing('localhost', 4322));

8
tests/redis/RedisManagerTest.php

@ -50,29 +50,29 @@ class RedisManagerTest extends PHPUnit_Framework_TestCase
public function testConnectWrongPersistantConfig() public function testConnectWrongPersistantConfig()
{ {
$this->setExpectedException('GeneralException', 'Connection parameters must be an array');
Config::set('Redis', array('new' => 'some')); Config::set('Redis', array('new' => 'some'));
$this->setExpectedException('GeneralException', 'Connection parameters must be an array');
RedisManager::connect('new'); RedisManager::connect('new');
} }
public function testConnectDefaultConfig() public function testConnectDefaultConfig()
{ {
$this->setExpectedException('GeneralException', 'Connection parameters must be an array');
Config::set('Redis', array('default' => 'some')); Config::set('Redis', array('default' => 'some'));
$this->setExpectedException('GeneralException', 'Connection parameters must be an array');
RedisManager::connect(); RedisManager::connect();
} }
public function testConnectFailedConnection() 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'))); 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'); RedisManager::connect('new');
} }
public function testConnectEstablishedConnectionNoDb() 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'))); 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'); RedisManager::connect('new');
} }

6
tests/util/AutoloadBuilderTest.php

@ -60,12 +60,12 @@ class AutoloadBuilderTest extends PHPUnit_Framework_TestCase
*/ */
public function testBuildParams() public function testBuildParams()
{ {
$this->setExpectedException('PHPUnit_Framework_Error');
$this->setConstants(); $this->setConstants();
$autoload = self::$file; $autoload = self::$file;
$dirs = 'string'; $dirs = 'string';
$builder = new AutoloadBuilder($autoload, $dirs); $builder = new AutoloadBuilder($autoload, $dirs);
$this->setExpectedException('PHPUnit_Framework_Error');
$builder->build(); $builder->build();
} }
@ -91,8 +91,10 @@ class AutoloadBuilderTest extends PHPUnit_Framework_TestCase
*/ */
public function testAccessDenied() public function testAccessDenied()
{ {
$this->setExpectedException('PHPUnit_Framework_Error');
$this->setConstants(); $this->setConstants();
$this->setExpectedException('PHPUnit_Framework_Error');
chmod(self::$file, 0400); chmod(self::$file, 0400);
$builder = new AutoloadBuilder(self::$file, array(self::$path . '/' . self::$app . '/src', self::$path . '/' . self::$app . '/cache', self::$path . '/lib')); $builder = new AutoloadBuilder(self::$file, array(self::$path . '/' . self::$app . '/src', self::$path . '/' . self::$app . '/cache', self::$path . '/lib'));

2
tests/validator/EqualValidatorTest.php

@ -26,8 +26,8 @@ class EqualValidatorTest extends PHPUnit_Framework_TestCase
public function testNullToken() public function testNullToken()
{ {
$this->setExpectedException('InitializationException','Token not defined');
$validator = new EqualValidator(null); $validator = new EqualValidator(null);
$this->setExpectedException('InitializationException','Token not defined');
$validator->isValid('not token'); $validator->isValid('not token');
} }

8
tests/validator/RegexValidatorTest.php

@ -48,9 +48,11 @@ class RegexValidatorTest extends PHPUnit_Framework_TestCase
public function testNullMessage() public function testNullMessage()
{ {
$this->setExpectedException('GeneralException', 'Message template "regex_not_match" unknown.');
$validator = new RegexValidator('/a/i'); $validator = new RegexValidator('/a/i');
$validator->setMessage(null, null); $validator->setMessage(null, null);
$this->setExpectedException('GeneralException', 'Message template "regex_not_match" unknown.');
$validator->isValid('1212'); $validator->isValid('1212');
} }
@ -59,15 +61,15 @@ class RegexValidatorTest extends PHPUnit_Framework_TestCase
*/ */
public function testWrongRegexp() public function testWrongRegexp()
{ {
$this->setExpectedException('PHPUnit_Framework_Error');
$validator = new RegexValidator('/^[a-z][0-9]$*/i'); $validator = new RegexValidator('/^[a-z][0-9]$*/i');
$this->setExpectedException('PHPUnit_Framework_Error');
$this->assertFalse($validator->isValid('to423$%ny')); $this->assertFalse($validator->isValid('to423$%ny'));
} }
public function testRegexReturnsFalse() public function testRegexReturnsFalse()
{ {
$this->setExpectedException('GeneralException', 'regex');
$validator = new RegexValidator('/(?:\D+|<\d+>)*[!?]/'); $validator = new RegexValidator('/(?:\D+|<\d+>)*[!?]/');
$this->setExpectedException('GeneralException', 'regex');
$this->assertFalse($validator->isValid('foobar foobar foobar')); $this->assertFalse($validator->isValid('foobar foobar foobar'));
} }
} }

3
tests/view/PHPViewTest.php

@ -136,9 +136,8 @@ class PHPViewTest extends PHPUnit_Framework_TestCase
public function testErrorTemplate() public function testErrorTemplate()
{ {
$this->setExpectedException('GeneralException', 'Template');
$view = new PHPView(array('path' => 'error_path/')); $view = new PHPView(array('path' => 'error_path/'));
$this->setExpectedException('GeneralException', 'Template');
$result = $view->fetch('test'); $result = $view->fetch('test');
} }
Loading…
Cancel
Save