Skip to content

Commit aacb921

Browse files
committed
Pattern to use skipIf in tests.
1 parent ed96936 commit aacb921

27 files changed

+92
-156
lines changed

lib/Cake/Test/Case/BasicsTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function testArrayDiffKey() {
8585
* @return void
8686
*/
8787
public function testEnv() {
88-
$this->skipIf(!function_exists('ini_get') || ini_get('safe_mode') === '1', '%s safe mode is on');
88+
$this->skipIf(!function_exists('ini_get') || ini_get('safe_mode') === '1', 'Safe mode is on.');
8989

9090
$__SERVER = $_SERVER;
9191
$__ENV = $_ENV;
@@ -258,9 +258,7 @@ public function testAm() {
258258
*/
259259
public function testCache() {
260260
$_cacheDisable = Configure::read('Cache.disable');
261-
if ($this->skipIf($_cacheDisable, 'Cache is disabled, skipping cache() tests. %s')) {
262-
return;
263-
}
261+
$this->skipIf($_cacheDisable, 'Cache is disabled, skipping cache() tests.');
264262

265263
Configure::write('Cache.disable', true);
266264
$result = cache('basics_test', 'simple cache write');
@@ -293,9 +291,7 @@ public function testCache() {
293291
*/
294292
public function testClearCache() {
295293
$cacheOff = Configure::read('Cache.disable');
296-
if ($this->skipIf($cacheOff, 'Cache is disabled, skipping clearCache() tests. %s')) {
297-
return;
298-
}
294+
$this->skipIf($cacheOff, 'Cache is disabled, skipping clearCache() tests.');
299295

300296
cache('views' . DS . 'basics_test.cache', 'simple cache write');
301297
$this->assertTrue(file_exists(CACHE . 'views' . DS . 'basics_test.cache'));
@@ -725,7 +721,7 @@ public function testPr() {
725721
* @return void
726722
*/
727723
public function testStripslashesDeep() {
728-
$this->skipIf(ini_get('magic_quotes_sybase') === '1', '%s magic_quotes_sybase is on');
724+
$this->skipIf(ini_get('magic_quotes_sybase') === '1', 'magic_quotes_sybase is on.');
729725

730726
$this->assertEqual(stripslashes_deep("tes\'t"), "tes't");
731727
$this->assertEqual(stripslashes_deep('tes\\' . chr(0) .'t'), 'tes' . chr(0) .'t');

lib/Cake/Test/Case/Cache/Engine/ApcEngineTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ class ApcEngineTest extends CakeTestCase {
3333
* @return void
3434
*/
3535
public function setUp() {
36-
$this->skipIf(!function_exists('apc_store'), '%s Apc is not installed or configured properly');
36+
$this->skipIf(!function_exists('apc_store'), 'Apc is not installed or configured properly.');
37+
3738
$this->_cacheDisable = Configure::read('Cache.disable');
3839
Configure::write('Cache.disable', false);
3940
Cache::config('apc', array('engine' => 'Apc', 'prefix' => 'cake_'));
@@ -132,9 +133,8 @@ public function testDeleteCache() {
132133
* @return void
133134
*/
134135
public function testDecrement() {
135-
if ($this->skipIf(!function_exists('apc_dec'), 'No apc_dec() function, cannot test decrement() %s')) {
136-
return;
137-
}
136+
$this->skipIf(!function_exists('apc_dec'), 'No apc_dec() function, cannot test decrement().');
137+
138138
$result = Cache::write('test_decrement', 5, 'apc');
139139
$this->assertTrue($result);
140140

@@ -159,9 +159,8 @@ public function testDecrement() {
159159
* @return void
160160
*/
161161
public function testIncrement() {
162-
if ($this->skipIf(!function_exists('apc_inc'), 'No apc_inc() function, cannot test increment() %s')) {
163-
return;
164-
}
162+
$this->skipIf(!function_exists('apc_inc'), 'No apc_inc() function, cannot test increment().');
163+
165164
$result = Cache::write('test_increment', 5, 'apc');
166165
$this->assertTrue($result);
167166

lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,8 @@ public function testWriteQuotedString() {
332332
* @return void
333333
*/
334334
public function testErrorWhenPathDoesNotExist() {
335-
if ($this->skipIf(is_dir(TMP . 'tests' . DS . 'file_failure'), 'Cannot run test directory exists. %s')) {
336-
return;
337-
}
335+
$this->skipIf(is_dir(TMP . 'tests' . DS . 'file_failure'), 'Cannot run test directory exists.');
336+
338337
$this->expectError();
339338
Cache::config('failure', array(
340339
'engine' => 'File',

lib/Cake/Test/Case/Cache/Engine/MemcacheTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ class MemcacheEngineTest extends CakeTestCase {
5050
* @return void
5151
*/
5252
public function setUp() {
53-
$this->skipIf(!class_exists('Memcache'), '%s Memcache is not installed or configured properly');
53+
$this->skipIf(!class_exists('Memcache'), 'Memcache is not installed or configured properly.');
54+
5455
$this->_cacheDisable = Configure::read('Cache.disable');
5556
Configure::write('Cache.disable', false);
5657
Cache::config('memcache', array(
@@ -111,9 +112,8 @@ public function testMultipleServers() {
111112
}
112113
}
113114

114-
if ($this->skipIf(!$available, '%s Need memcache servers at ' . implode(', ', $servers) . ' to run this test')) {
115-
return;
116-
}
115+
$this->skipIf(!$available, 'Need memcache servers at ' . implode(', ', $servers) . ' to run this test.');
116+
117117
$Memcache = new MemcacheEngine();
118118
$Memcache->init(array('engine' => 'Memcache', 'servers' => $servers));
119119

lib/Cake/Test/Case/Console/Command/BakeShellTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,8 @@ public function tearDown() {
7777
public function testAllWithModelName() {
7878
App::uses('User', 'Model');
7979
$userExists = class_exists('User');
80-
if ($this->skipIf($userExists, 'User class exists, cannot test `bake all [param]`. %s')) {
81-
return;
82-
}
80+
$this->skipIf($userExists, 'User class exists, cannot test `bake all [param]`.');
81+
8382
$this->Shell->Model = $this->getMock('ModelTask', array(), array(&$this->Dispatcher));
8483
$this->Shell->Controller = $this->getMock('ControllerTask', array(), array(&$this->Dispatcher));
8584
$this->Shell->View = $this->getMock('ModelTask', array(), array(&$this->Dispatcher));

lib/Cake/Test/Case/Console/Command/ShellTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ public function testShortPath() {
507507
* @return void
508508
*/
509509
public function testCreateFileNonInteractive() {
510-
$this->skipIf(DIRECTORY_SEPARATOR === '\\', '%s Not supported on Windows');
510+
$this->skipIf(DIRECTORY_SEPARATOR === '\\', 'Not supported on Windows.');
511511

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

542542
$path = TMP . 'shell_test';
543543
$file = $path . DS . 'file1.php';
@@ -583,7 +583,7 @@ public function testCreateFileInteractive() {
583583
* @return void
584584
*/
585585
public function testCreateFileWindowsNonInteractive() {
586-
$this->skipIf(DIRECTORY_SEPARATOR === '/', 'testCreateFileWindows supported on Windows only');
586+
$this->skipIf(DIRECTORY_SEPARATOR === '/', 'testCreateFileWindowsNonInteractive supported on Windows only.');
587587

588588
$path = TMP . 'shell_test';
589589
$file = $path . DS . 'file1.php';
@@ -614,7 +614,7 @@ public function testCreateFileWindowsNonInteractive() {
614614
* @return void
615615
*/
616616
public function testCreateFileWindowsInteractive() {
617-
$this->skipIf(DIRECTORY_SEPARATOR === '/', 'testCreateFileWindowsInteractive supported on Windows only');
617+
$this->skipIf(DIRECTORY_SEPARATOR === '/', 'testCreateFileWindowsInteractive supported on Windows only.');
618618

619619
$path = TMP . 'shell_test';
620620
$file = $path . DS . 'file1.php';

lib/Cake/Test/Case/Console/Command/Task/ControllerTaskTest.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,8 @@ public function testBakeWithPlugin() {
329329
* @return void
330330
*/
331331
public function testBakeActionsUsingSessions() {
332-
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
333-
'Testing bakeActions requires Article, Comment & Tag Model to be undefined. %s');
334-
if ($skip) {
335-
return;
336-
}
332+
$this->skipIf(!defined('ARTICLE_MODEL_CREATED'), 'Testing bakeActions requires Article, Comment & Tag Model to be undefined.');
333+
337334
$result = $this->Task->bakeActions('BakeArticles', null, true);
338335

339336
$this->assertContains('function index() {', $result);
@@ -371,11 +368,8 @@ public function testBakeActionsUsingSessions() {
371368
* @return void
372369
*/
373370
public function testBakeActionsWithNoSessions() {
374-
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
375-
'Testing bakeActions requires Article, Tag, Comment Models to be undefined. %s');
376-
if ($skip) {
377-
return;
378-
}
371+
$this->skipIf(!defined('ARTICLE_MODEL_CREATED'), 'Testing bakeActions requires Article, Tag, Comment Models to be undefined.');
372+
379373
$result = $this->Task->bakeActions('BakeArticles', null, false);
380374

381375
$this->assertContains('function index() {', $result);

lib/Cake/Test/Case/Console/Command/Task/TestTaskTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,8 @@ public function testRegistryClearWhenBuildingTestObjects() {
374374
*/
375375
public function testGetClassName() {
376376
$objects = App::objects('model');
377-
$skip = $this->skipIf(empty($objects), 'No models in app, this test will fail.');
378-
if ($skip) {
379-
return;
380-
}
377+
$this->skipIf(empty($objects), 'No models in app.');
378+
381379
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('MyCustomClass'));
382380
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(1));
383381

lib/Cake/Test/Case/Console/ShellDispatcherTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ public function testParseParams() {
392392
* @return void
393393
*/
394394
public function testGetShell() {
395-
$this->skipIf(class_exists('SampleShell'), '%s SampleShell Class already loaded');
396-
$this->skipIf(class_exists('ExampleShell'), '%s ExampleShell Class already loaded');
395+
$this->skipIf(class_exists('SampleShell'), 'SampleShell Class already loaded.');
396+
$this->skipIf(class_exists('ExampleShell'), 'ExampleShell Class already loaded.');
397397

398398
$Dispatcher = new TestShellDispatcher();
399399

lib/Cake/Test/Case/Controller/Component/EmailComponentTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,10 +602,8 @@ public function testContentStripping() {
602602
* @return void
603603
*/
604604
public function test_encodeSettingInternalCharset() {
605-
$skip = !function_exists('mb_internal_encoding');
606-
if ($this->skipIf($skip, 'Missing mb_* functions, cannot run test.')) {
607-
return;
608-
}
605+
$this->skipIf(!function_exists('mb_internal_encoding'), 'Missing mb_* functions, cannot run test.');
606+
609607
$restore = mb_internal_encoding();
610608
mb_internal_encoding('ISO-8859-1');
611609

lib/Cake/Test/Case/Error/ErrorHandlerTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,7 @@ public function testHandleErrorLoggingTrace() {
186186
* @return void
187187
*/
188188
public function testHandleException() {
189-
if ($this->skipIf(file_exists(APP . 'app_error.php'), 'App error exists cannot run.')) {
190-
return;
191-
}
189+
$this->skipIf(file_exists(APP . 'app_error.php'), 'App error exists cannot run.');
192190

193191
$error = new NotFoundException('Kaboom!');
194192
ob_start();
@@ -203,9 +201,8 @@ public function testHandleException() {
203201
* @return void
204202
*/
205203
public function testHandleExceptionLog() {
206-
if ($this->skipIf(file_exists(APP . 'app_error.php'), 'App error exists cannot run.')) {
207-
return;
208-
}
204+
$this->skipIf(file_exists(APP . 'app_error.php'), 'App error exists cannot run.');
205+
209206
if (file_exists(LOGS . 'error.log')) {
210207
unlink(LOGS . 'error.log');
211208
}

lib/Cake/Test/Case/I18n/MultibyteTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4794,10 +4794,8 @@ public function testMultibyteStrripos() {
47944794
* @return void
47954795
*/
47964796
public function testUsingMbStrrpos() {
4797-
$skip = extension_loaded('mbstring') && version_compare(PHP_VERSION, '5.2.0', '<');
4798-
if ($this->skipIf($skip, '%s PHP version does not support $offset parameter in mb_strrpos().')) {
4799-
return;
4800-
}
4797+
$this->skipIf(extension_loaded('mbstring') && version_compare(PHP_VERSION, '5.2.0', '<'), 'PHP version does not support $offset parameter in mb_strrpos().');
4798+
48014799
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
48024800
$find = 'F';
48034801
$result = mb_strrpos($string, $find);

lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3500,15 +3500,11 @@ public function testResetMultipleHabtmAssociations() {
35003500
public function testAutoFieldsWithMultipleDatabases() {
35013501
$config = new DATABASE_CONFIG();
35023502

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

35133509
$db = ConnectionManager::getDataSource('test2');
35143510
$this->fixtureManager->loadSingle('User', $db);

lib/Cake/Test/Case/Model/CakeSchemaTest.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,8 @@ public function testSchemaRead() {
610610
*/
611611
public function testSchemaReadWithOddTablePrefix() {
612612
$config = ConnectionManager::getDataSource('test')->config;
613-
$this->skipIf(!empty($config['prefix']), 'This test can not be executed with datasource prefix set');
613+
$this->skipIf(!empty($config['prefix']), 'This test can not be executed with datasource prefix set.');
614+
614615
$SchemaPost = ClassRegistry::init('SchemaPost');
615616
$SchemaPost->tablePrefix = 'po';
616617
$SchemaPost->useTable = 'sts';
@@ -630,7 +631,7 @@ public function testSchemaReadWithOddTablePrefix() {
630631
*/
631632
public function testSchemaReadWithTablePrefix() {
632633
$config = ConnectionManager::getDataSource('test')->config;
633-
$this->skipIf(!empty($config['prefix']), 'This test can not be executed with datasource prefix set');
634+
$this->skipIf(!empty($config['prefix']), 'This test can not be executed with datasource prefix set.');
634635

635636
$model = new SchemaPrefixAuthUser();
636637

@@ -695,15 +696,11 @@ public function testSchemaReadWithPlugins() {
695696
*/
696697
public function testSchemaReadWithCrossDatabase() {
697698
$config = new DATABASE_CONFIG();
698-
$skip = $this->skipIf(
699+
$this->skipIf(
699700
!isset($config->test) || !isset($config->test2),
700-
'%s Primary and secondary test databases not configured, skipping cross-database '
701-
.'join tests.'
702-
.' To run these tests, you must define $test and $test2 in your database configuration.'
701+
'Primary and secondary test databases not configured, skipping cross-database join tests.'
702+
. ' To run these tests, you must define $test and $test2 in your database configuration.'
703703
);
704-
if ($skip) {
705-
return;
706-
}
707704

708705
$db2 = ConnectionManager::getDataSource('test2');
709706
$fixture = new SchemaCrossDatabaseFixture();

lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,7 @@ public function testFieldsUsingMethodCache() {
820820
*/
821821
public function testStatements() {
822822
$this->skipIf(!$this->testDb instanceof DboMysql);
823+
823824
$this->loadFixtures('Article', 'User', 'Comment', 'Tag', 'Attachment', 'ArticlesTag');
824825
$Article = new Article();
825826

lib/Cake/Test/Case/Model/ModelReadTest.php

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ public function testGroupBy() {
8282
$isStrictGroupBy = $this->db instanceof Postgres || $this->db instanceof Sqlite || $this->db instanceof Oracle || $this->db instanceof Sqlserver;
8383
$message = 'Postgres, Oracle, SQLite and SQL Server have strict GROUP BY and are incompatible with this test.';
8484

85-
if ($this->skipIf($isStrictGroupBy, $message )) {
86-
return;
87-
}
85+
$this->skipIf($isStrictGroupBy, $message);
8886

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

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

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

4023-
if ($this->skipIf($this->db instanceof Postgres, 'The rest of testFindAllWithConditionsHavingMixedDataTypes test is not compatible with Postgres')) {
4024-
return;
4025-
}
4017+
$this->skipIf($this->db instanceof Postgres, 'The rest of testFindAllWithConditionsHavingMixedDataTypes test is not compatible with Postgres.');
4018+
40264019
$conditions = array('id' => array('1', 2, '3.0'));
40274020
$order = 'Article.id ASC';
40284021
$result = $TestModel->find('all', compact('recursive', 'conditions', 'order'));
@@ -6622,7 +6615,7 @@ public function testFindFirstNoIdUsed() {
66226615
* @return void
66236616
*/
66246617
public function testFindCountDistinct() {
6625-
$this->skipIf($this->db instanceof Sqlite, 'SELECT COUNT(DISTINCT field) is not compatible with SQLite');
6618+
$this->skipIf($this->db instanceof Sqlite, 'SELECT COUNT(DISTINCT field) is not compatible with SQLite.');
66266619
$this->skipIf($this->db instanceof Sqlserver, 'This test is not compatible with SQL Server.');
66276620

66286621
$this->loadFixtures('Project');
@@ -6642,9 +6635,8 @@ public function testFindCountDistinct() {
66426635
* @return void
66436636
*/
66446637
public function testFindCountWithDbExpressions() {
6645-
if ($this->skipIf($this->db instanceof Postgres, 'testFindCountWithExpressions is not compatible with Postgres')) {
6646-
return;
6647-
}
6638+
$this->skipIf($this->db instanceof Postgres, 'testFindCountWithDbExpressions is not compatible with Postgres.');
6639+
66486640
$this->loadFixtures('Project');
66496641
$db = ConnectionManager::getDataSource('test');
66506642
$TestModel = new Project();
@@ -7470,9 +7462,8 @@ public function testVirtualFields() {
74707462
*
74717463
*/
74727464
public function testVirtualFieldsMysql() {
7473-
if ($this->skipIf(!($this->db instanceof Mysql), 'The rest of virtualFieds test only compatible with Mysql')) {
7474-
return;
7475-
}
7465+
$this->skipIf(!($this->db instanceof Mysql), 'The rest of virtualFieds test only compatible with Mysql.');
7466+
74767467
$this->loadFixtures('Post', 'Author');
74777468
$Post = ClassRegistry::init('Post');
74787469

0 commit comments

Comments
 (0)