Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Pattern to use skipIf in tests.
  • Loading branch information
jrbasso committed May 31, 2011
1 parent ed96936 commit aacb921
Show file tree
Hide file tree
Showing 27 changed files with 92 additions and 156 deletions.
12 changes: 4 additions & 8 deletions lib/Cake/Test/Case/BasicsTest.php
Expand Up @@ -85,7 +85,7 @@ public function testArrayDiffKey() {
* @return void
*/
public function testEnv() {
$this->skipIf(!function_exists('ini_get') || ini_get('safe_mode') === '1', '%s safe mode is on');
$this->skipIf(!function_exists('ini_get') || ini_get('safe_mode') === '1', 'Safe mode is on.');

$__SERVER = $_SERVER;
$__ENV = $_ENV;
Expand Down Expand Up @@ -258,9 +258,7 @@ public function testAm() {
*/
public function testCache() {
$_cacheDisable = Configure::read('Cache.disable');
if ($this->skipIf($_cacheDisable, 'Cache is disabled, skipping cache() tests. %s')) {
return;
}
$this->skipIf($_cacheDisable, 'Cache is disabled, skipping cache() tests.');

Configure::write('Cache.disable', true);
$result = cache('basics_test', 'simple cache write');
Expand Down Expand Up @@ -293,9 +291,7 @@ public function testCache() {
*/
public function testClearCache() {
$cacheOff = Configure::read('Cache.disable');
if ($this->skipIf($cacheOff, 'Cache is disabled, skipping clearCache() tests. %s')) {
return;
}
$this->skipIf($cacheOff, 'Cache is disabled, skipping clearCache() tests.');

cache('views' . DS . 'basics_test.cache', 'simple cache write');
$this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test.cache'));
Expand Down Expand Up @@ -725,7 +721,7 @@ public function testPr() {
* @return void
*/
public function testStripslashesDeep() {
$this->skipIf(ini_get('magic_quotes_sybase') === '1', '%s magic_quotes_sybase is on');
$this->skipIf(ini_get('magic_quotes_sybase') === '1', 'magic_quotes_sybase is on.');

$this->assertEqual(stripslashes_deep("tes\'t"), "tes't");
$this->assertEqual(stripslashes_deep('tes\\' . chr(0) .'t'), 'tes' . chr(0) .'t');
Expand Down
13 changes: 6 additions & 7 deletions lib/Cake/Test/Case/Cache/Engine/ApcEngineTest.php
Expand Up @@ -33,7 +33,8 @@ class ApcEngineTest extends CakeTestCase {
* @return void
*/
public function setUp() {
$this->skipIf(!function_exists('apc_store'), '%s Apc is not installed or configured properly');
$this->skipIf(!function_exists('apc_store'), 'Apc is not installed or configured properly.');

$this->_cacheDisable = Configure::read('Cache.disable');
Configure::write('Cache.disable', false);
Cache::config('apc', array('engine' => 'Apc', 'prefix' => 'cake_'));
Expand Down Expand Up @@ -132,9 +133,8 @@ public function testDeleteCache() {
* @return void
*/
public function testDecrement() {
if ($this->skipIf(!function_exists('apc_dec'), 'No apc_dec() function, cannot test decrement() %s')) {
return;
}
$this->skipIf(!function_exists('apc_dec'), 'No apc_dec() function, cannot test decrement().');

$result = Cache::write('test_decrement', 5, 'apc');
$this->assertTrue($result);

Expand All @@ -159,9 +159,8 @@ public function testDecrement() {
* @return void
*/
public function testIncrement() {
if ($this->skipIf(!function_exists('apc_inc'), 'No apc_inc() function, cannot test increment() %s')) {
return;
}
$this->skipIf(!function_exists('apc_inc'), 'No apc_inc() function, cannot test increment().');

$result = Cache::write('test_increment', 5, 'apc');
$this->assertTrue($result);

Expand Down
5 changes: 2 additions & 3 deletions lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php
Expand Up @@ -332,9 +332,8 @@ public function testWriteQuotedString() {
* @return void
*/
public function testErrorWhenPathDoesNotExist() {
if ($this->skipIf(is_dir(TMP . 'tests' . DS . 'file_failure'), 'Cannot run test directory exists. %s')) {
return;
}
$this->skipIf(is_dir(TMP . 'tests' . DS . 'file_failure'), 'Cannot run test directory exists.');

$this->expectError();
Cache::config('failure', array(
'engine' => 'File',
Expand Down
8 changes: 4 additions & 4 deletions lib/Cake/Test/Case/Cache/Engine/MemcacheTest.php
Expand Up @@ -50,7 +50,8 @@ class MemcacheEngineTest extends CakeTestCase {
* @return void
*/
public function setUp() {
$this->skipIf(!class_exists('Memcache'), '%s Memcache is not installed or configured properly');
$this->skipIf(!class_exists('Memcache'), 'Memcache is not installed or configured properly.');

$this->_cacheDisable = Configure::read('Cache.disable');
Configure::write('Cache.disable', false);
Cache::config('memcache', array(
Expand Down Expand Up @@ -111,9 +112,8 @@ public function testMultipleServers() {
}
}

if ($this->skipIf(!$available, '%s Need memcache servers at ' . implode(', ', $servers) . ' to run this test')) {
return;
}
$this->skipIf(!$available, 'Need memcache servers at ' . implode(', ', $servers) . ' to run this test.');

$Memcache = new MemcacheEngine();
$Memcache->init(array('engine' => 'Memcache', 'servers' => $servers));

Expand Down
5 changes: 2 additions & 3 deletions lib/Cake/Test/Case/Console/Command/BakeShellTest.php
Expand Up @@ -77,9 +77,8 @@ public function tearDown() {
public function testAllWithModelName() {
App::uses('User', 'Model');
$userExists = class_exists('User');
if ($this->skipIf($userExists, 'User class exists, cannot test `bake all [param]`. %s')) {
return;
}
$this->skipIf($userExists, 'User class exists, cannot test `bake all [param]`.');

$this->Shell->Model = $this->getMock('ModelTask', array(), array(&$this->Dispatcher));
$this->Shell->Controller = $this->getMock('ControllerTask', array(), array(&$this->Dispatcher));
$this->Shell->View = $this->getMock('ModelTask', array(), array(&$this->Dispatcher));
Expand Down
8 changes: 4 additions & 4 deletions lib/Cake/Test/Case/Console/Command/ShellTest.php
Expand Up @@ -507,7 +507,7 @@ public function testShortPath() {
* @return void
*/
public function testCreateFileNonInteractive() {
$this->skipIf(DIRECTORY_SEPARATOR === '\\', '%s Not supported on Windows');
$this->skipIf(DIRECTORY_SEPARATOR === '\\', 'Not supported on Windows.');

$path = TMP . 'shell_test';
$file = $path . DS . 'file1.php';
Expand Down Expand Up @@ -537,7 +537,7 @@ public function testCreateFileNonInteractive() {
* @return void
*/
public function testCreateFileInteractive() {
$this->skipIf(DIRECTORY_SEPARATOR === '\\', '%s Not supported on Windows');
$this->skipIf(DIRECTORY_SEPARATOR === '\\', 'Not supported on Windows.');

$path = TMP . 'shell_test';
$file = $path . DS . 'file1.php';
Expand Down Expand Up @@ -583,7 +583,7 @@ public function testCreateFileInteractive() {
* @return void
*/
public function testCreateFileWindowsNonInteractive() {
$this->skipIf(DIRECTORY_SEPARATOR === '/', 'testCreateFileWindows supported on Windows only');
$this->skipIf(DIRECTORY_SEPARATOR === '/', 'testCreateFileWindowsNonInteractive supported on Windows only.');

$path = TMP . 'shell_test';
$file = $path . DS . 'file1.php';
Expand Down Expand Up @@ -614,7 +614,7 @@ public function testCreateFileWindowsNonInteractive() {
* @return void
*/
public function testCreateFileWindowsInteractive() {
$this->skipIf(DIRECTORY_SEPARATOR === '/', 'testCreateFileWindowsInteractive supported on Windows only');
$this->skipIf(DIRECTORY_SEPARATOR === '/', 'testCreateFileWindowsInteractive supported on Windows only.');

$path = TMP . 'shell_test';
$file = $path . DS . 'file1.php';
Expand Down
14 changes: 4 additions & 10 deletions lib/Cake/Test/Case/Console/Command/Task/ControllerTaskTest.php
Expand Up @@ -329,11 +329,8 @@ public function testBakeWithPlugin() {
* @return void
*/
public function testBakeActionsUsingSessions() {
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
'Testing bakeActions requires Article, Comment & Tag Model to be undefined. %s');
if ($skip) {
return;
}
$this->skipIf(!defined('ARTICLE_MODEL_CREATED'), 'Testing bakeActions requires Article, Comment & Tag Model to be undefined.');

$result = $this->Task->bakeActions('BakeArticles', null, true);

$this->assertContains('function index() {', $result);
Expand Down Expand Up @@ -371,11 +368,8 @@ public function testBakeActionsUsingSessions() {
* @return void
*/
public function testBakeActionsWithNoSessions() {
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
'Testing bakeActions requires Article, Tag, Comment Models to be undefined. %s');
if ($skip) {
return;
}
$this->skipIf(!defined('ARTICLE_MODEL_CREATED'), 'Testing bakeActions requires Article, Tag, Comment Models to be undefined.');

$result = $this->Task->bakeActions('BakeArticles', null, false);

$this->assertContains('function index() {', $result);
Expand Down
6 changes: 2 additions & 4 deletions lib/Cake/Test/Case/Console/Command/Task/TestTaskTest.php
Expand Up @@ -374,10 +374,8 @@ public function testRegistryClearWhenBuildingTestObjects() {
*/
public function testGetClassName() {
$objects = App::objects('model');
$skip = $this->skipIf(empty($objects), 'No models in app, this test will fail.');
if ($skip) {
return;
}
$this->skipIf(empty($objects), 'No models in app.');

$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('MyCustomClass'));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(1));

Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Test/Case/Console/ShellDispatcherTest.php
Expand Up @@ -392,8 +392,8 @@ public function testParseParams() {
* @return void
*/
public function testGetShell() {
$this->skipIf(class_exists('SampleShell'), '%s SampleShell Class already loaded');
$this->skipIf(class_exists('ExampleShell'), '%s ExampleShell Class already loaded');
$this->skipIf(class_exists('SampleShell'), 'SampleShell Class already loaded.');
$this->skipIf(class_exists('ExampleShell'), 'ExampleShell Class already loaded.');

$Dispatcher = new TestShellDispatcher();

Expand Down
Expand Up @@ -602,10 +602,8 @@ public function testContentStripping() {
* @return void
*/
public function test_encodeSettingInternalCharset() {
$skip = !function_exists('mb_internal_encoding');
if ($this->skipIf($skip, 'Missing mb_* functions, cannot run test.')) {
return;
}
$this->skipIf(!function_exists('mb_internal_encoding'), 'Missing mb_* functions, cannot run test.');

$restore = mb_internal_encoding();
mb_internal_encoding('ISO-8859-1');

Expand Down
9 changes: 3 additions & 6 deletions lib/Cake/Test/Case/Error/ErrorHandlerTest.php
Expand Up @@ -186,9 +186,7 @@ public function testHandleErrorLoggingTrace() {
* @return void
*/
public function testHandleException() {
if ($this->skipIf(file_exists(APP . 'app_error.php'), 'App error exists cannot run.')) {
return;
}
$this->skipIf(file_exists(APP . 'app_error.php'), 'App error exists cannot run.');

$error = new NotFoundException('Kaboom!');
ob_start();
Expand All @@ -203,9 +201,8 @@ public function testHandleException() {
* @return void
*/
public function testHandleExceptionLog() {
if ($this->skipIf(file_exists(APP . 'app_error.php'), 'App error exists cannot run.')) {
return;
}
$this->skipIf(file_exists(APP . 'app_error.php'), 'App error exists cannot run.');

if (file_exists(LOGS . 'error.log')) {
unlink(LOGS . 'error.log');
}
Expand Down
6 changes: 2 additions & 4 deletions lib/Cake/Test/Case/I18n/MultibyteTest.php
Expand Up @@ -4794,10 +4794,8 @@ public function testMultibyteStrripos() {
* @return void
*/
public function testUsingMbStrrpos() {
$skip = extension_loaded('mbstring') && version_compare(PHP_VERSION, '5.2.0', '<');
if ($this->skipIf($skip, '%s PHP version does not support $offset parameter in mb_strrpos().')) {
return;
}
$this->skipIf(extension_loaded('mbstring') && version_compare(PHP_VERSION, '5.2.0', '<'), 'PHP version does not support $offset parameter in mb_strrpos().');

$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$find = 'F';
$result = mb_strrpos($string, $find);
Expand Down
10 changes: 3 additions & 7 deletions lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php
Expand Up @@ -3500,15 +3500,11 @@ public function testResetMultipleHabtmAssociations() {
public function testAutoFieldsWithMultipleDatabases() {
$config = new DATABASE_CONFIG();

$skip = $this->skipIf(
$this->skipIf(
!isset($config->test) || !isset($config->test2),
'%s Primary and secondary test databases not configured, skipping cross-database '
.'join tests.'
.' To run these tests, you must define $test and $test2 in your database configuration.'
'Primary and secondary test databases not configured, skipping cross-database join tests.'
. ' To run these tests, you must define $test and $test2 in your database configuration.'
);
if ($skip) {
return;
}

$db = ConnectionManager::getDataSource('test2');
$this->fixtureManager->loadSingle('User', $db);
Expand Down
15 changes: 6 additions & 9 deletions lib/Cake/Test/Case/Model/CakeSchemaTest.php
Expand Up @@ -610,7 +610,8 @@ public function testSchemaRead() {
*/
public function testSchemaReadWithOddTablePrefix() {
$config = ConnectionManager::getDataSource('test')->config;
$this->skipIf(!empty($config['prefix']), 'This test can not be executed with datasource prefix set');
$this->skipIf(!empty($config['prefix']), 'This test can not be executed with datasource prefix set.');

$SchemaPost = ClassRegistry::init('SchemaPost');
$SchemaPost->tablePrefix = 'po';
$SchemaPost->useTable = 'sts';
Expand All @@ -630,7 +631,7 @@ public function testSchemaReadWithOddTablePrefix() {
*/
public function testSchemaReadWithTablePrefix() {
$config = ConnectionManager::getDataSource('test')->config;
$this->skipIf(!empty($config['prefix']), 'This test can not be executed with datasource prefix set');
$this->skipIf(!empty($config['prefix']), 'This test can not be executed with datasource prefix set.');

$model = new SchemaPrefixAuthUser();

Expand Down Expand Up @@ -695,15 +696,11 @@ public function testSchemaReadWithPlugins() {
*/
public function testSchemaReadWithCrossDatabase() {
$config = new DATABASE_CONFIG();
$skip = $this->skipIf(
$this->skipIf(
!isset($config->test) || !isset($config->test2),
'%s Primary and secondary test databases not configured, skipping cross-database '
.'join tests.'
.' To run these tests, you must define $test and $test2 in your database configuration.'
'Primary and secondary test databases not configured, skipping cross-database join tests.'
. ' To run these tests, you must define $test and $test2 in your database configuration.'
);
if ($skip) {
return;
}

$db2 = ConnectionManager::getDataSource('test2');
$fixture = new SchemaCrossDatabaseFixture();
Expand Down
1 change: 1 addition & 0 deletions lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php
Expand Up @@ -820,6 +820,7 @@ public function testFieldsUsingMethodCache() {
*/
public function testStatements() {
$this->skipIf(!$this->testDb instanceof DboMysql);

$this->loadFixtures('Article', 'User', 'Comment', 'Tag', 'Attachment', 'ArticlesTag');
$Article = new Article();

Expand Down
29 changes: 10 additions & 19 deletions lib/Cake/Test/Case/Model/ModelReadTest.php
Expand Up @@ -82,9 +82,7 @@ public function testGroupBy() {
$isStrictGroupBy = $this->db instanceof Postgres || $this->db instanceof Sqlite || $this->db instanceof Oracle || $this->db instanceof Sqlserver;
$message = 'Postgres, Oracle, SQLite and SQL Server have strict GROUP BY and are incompatible with this test.';

if ($this->skipIf($isStrictGroupBy, $message )) {
return;
}
$this->skipIf($isStrictGroupBy, $message);

$this->loadFixtures('Project', 'Product', 'Thread', 'Message', 'Bid');
$Thread = new Thread();
Expand Down Expand Up @@ -390,9 +388,7 @@ public function testVeryStrangeUseCase() {
* @return void
*/
public function testRecursiveUnbind() {
if ($this->skipIf($this->db instanceof Sqlserver, 'The test of testRecursiveUnbind test is not compatible with SQL Server, because it check for time columns.')) {
return;
}
$this->skipIf($this->db instanceof Sqlserver, 'The test of testRecursiveUnbind test is not compatible with SQL Server, because it check for time columns.');

$this->loadFixtures('Apple', 'Sample');
$TestModel = new Apple();
Expand Down Expand Up @@ -3648,9 +3644,7 @@ public function testFindNeighbors() {
* @return void
*/
public function testFindCombinedRelations() {
if ($this->skipIf($this->db instanceof Sqlserver, 'The test of testRecursiveUnbind test is not compatible with SQL Server, because it check for time columns.')) {
return;
}
$this->skipIf($this->db instanceof Sqlserver, 'The test of testRecursiveUnbind test is not compatible with SQL Server, because it check for time columns.');

$this->loadFixtures('Apple', 'Sample');
$TestModel = new Apple();
Expand Down Expand Up @@ -4020,9 +4014,8 @@ public function testFindAllWithConditionsHavingMixedDataTypes() {
$result = $TestModel->find('all', compact('conditions', 'recursive', 'order'));
$this->assertEqual($expected, $result);

if ($this->skipIf($this->db instanceof Postgres, 'The rest of testFindAllWithConditionsHavingMixedDataTypes test is not compatible with Postgres')) {
return;
}
$this->skipIf($this->db instanceof Postgres, 'The rest of testFindAllWithConditionsHavingMixedDataTypes test is not compatible with Postgres.');

$conditions = array('id' => array('1', 2, '3.0'));
$order = 'Article.id ASC';
$result = $TestModel->find('all', compact('recursive', 'conditions', 'order'));
Expand Down Expand Up @@ -6622,7 +6615,7 @@ public function testFindFirstNoIdUsed() {
* @return void
*/
public function testFindCountDistinct() {
$this->skipIf($this->db instanceof Sqlite, 'SELECT COUNT(DISTINCT field) is not compatible with SQLite');
$this->skipIf($this->db instanceof Sqlite, 'SELECT COUNT(DISTINCT field) is not compatible with SQLite.');
$this->skipIf($this->db instanceof Sqlserver, 'This test is not compatible with SQL Server.');

$this->loadFixtures('Project');
Expand All @@ -6642,9 +6635,8 @@ public function testFindCountDistinct() {
* @return void
*/
public function testFindCountWithDbExpressions() {
if ($this->skipIf($this->db instanceof Postgres, 'testFindCountWithExpressions is not compatible with Postgres')) {
return;
}
$this->skipIf($this->db instanceof Postgres, 'testFindCountWithDbExpressions is not compatible with Postgres.');

$this->loadFixtures('Project');
$db = ConnectionManager::getDataSource('test');
$TestModel = new Project();
Expand Down Expand Up @@ -7470,9 +7462,8 @@ public function testVirtualFields() {
*
*/
public function testVirtualFieldsMysql() {
if ($this->skipIf(!($this->db instanceof Mysql), 'The rest of virtualFieds test only compatible with Mysql')) {
return;
}
$this->skipIf(!($this->db instanceof Mysql), 'The rest of virtualFieds test only compatible with Mysql.');

$this->loadFixtures('Post', 'Author');
$Post = ClassRegistry::init('Post');

Expand Down

0 comments on commit aacb921

Please sign in to comment.