From e5f2f6a2366587168423336a80b71cd23dfbbb98 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 29 May 2011 02:38:22 +0530 Subject: [PATCH] Fixing test cases --- lib/Cake/Test/Case/Core/ObjectTest.php | 5 +++-- lib/Cake/Test/Case/Log/CakeLogTest.php | 8 ++++++-- lib/Cake/Test/Case/Log/Engine/FileLog.php | 16 ++++++++++++---- lib/Cake/Test/Case/Model/CakeSchemaTest.php | 4 +++- lib/Cake/Test/Case/Utility/FolderTest.php | 3 ++- lib/Cake/Test/Case/View/HelperTest.php | 1 + lib/Cake/Test/Case/View/ViewTest.php | 4 +++- 7 files changed, 30 insertions(+), 11 deletions(-) diff --git a/lib/Cake/Test/Case/Core/ObjectTest.php b/lib/Cake/Test/Case/Core/ObjectTest.php index f15f4a07ad1..d3e867d0a54 100644 --- a/lib/Cake/Test/Case/Core/ObjectTest.php +++ b/lib/Cake/Test/Case/Core/ObjectTest.php @@ -368,7 +368,9 @@ function tearDown() { * @return void */ function testLog() { - @unlink(LOGS . 'error.log'); + if (file_exists(LOGS . 'error.log')) { + unlink(LOGS . 'error.log'); + } $this->assertTrue($this->object->log('Test warning 1')); $this->assertTrue($this->object->log(array('Test' => 'warning 2'))); $result = file(LOGS . 'error.log'); @@ -379,7 +381,6 @@ function testLog() { $this->assertPattern('/^\)$/', $result[4]); unlink(LOGS . 'error.log'); - @unlink(LOGS . 'error.log'); $this->assertTrue($this->object->log('Test warning 1', LOG_WARNING)); $this->assertTrue($this->object->log(array('Test' => 'warning 2'), LOG_WARNING)); $result = file(LOGS . 'error.log'); diff --git a/lib/Cake/Test/Case/Log/CakeLogTest.php b/lib/Cake/Test/Case/Log/CakeLogTest.php index f20af387339..d57695ef361 100644 --- a/lib/Cake/Test/Case/Log/CakeLogTest.php +++ b/lib/Cake/Test/Case/Log/CakeLogTest.php @@ -95,7 +95,9 @@ function testNotImplementingInterface() { * @return void */ function testAutoConfig() { - @unlink(LOGS . 'error.log'); + if (file_exists(LOGS . 'error.log')) { + unlink(LOGS . 'error.log'); + } CakeLog::write(LOG_WARNING, 'Test warning'); $this->assertTrue(file_exists(LOGS . 'error.log')); @@ -153,7 +155,9 @@ function testDrop() { * @return void */ function testLogFileWriting() { - @unlink(LOGS . 'error.log'); + if (file_exists(LOGS . 'error.log')) { + unlink(LOGS . 'error.log'); + } $result = CakeLog::write(LOG_WARNING, 'Test warning'); $this->assertTrue($result); $this->assertTrue(file_exists(LOGS . 'error.log')); diff --git a/lib/Cake/Test/Case/Log/Engine/FileLog.php b/lib/Cake/Test/Case/Log/Engine/FileLog.php index 9dab415eacb..75cfc9b5f62 100644 --- a/lib/Cake/Test/Case/Log/Engine/FileLog.php +++ b/lib/Cake/Test/Case/Log/Engine/FileLog.php @@ -32,7 +32,9 @@ class FileLogTest extends CakeTestCase { * @return void */ function testLogFileWriting() { - @unlink(LOGS . 'error.log'); + if (file_exists(LOGS . 'error.log')) { + unlink(LOGS . 'error.log'); + } $log = new FileLog(); $log->write('warning', 'Test warning'); $this->assertTrue(file_exists(LOGS . 'error.log')); @@ -41,7 +43,9 @@ function testLogFileWriting() { $this->assertPattern('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Warning: Test warning/', $result); unlink(LOGS . 'error.log'); - @unlink(LOGS . 'debug.log'); + if (file_exists(LOGS . 'debug.log')) { + unlink(LOGS . 'debug.log'); + } $log->write('debug', 'Test warning'); $this->assertTrue(file_exists(LOGS . 'debug.log')); @@ -49,7 +53,9 @@ function testLogFileWriting() { $this->assertPattern('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Debug: Test warning/', $result); unlink(LOGS . 'debug.log'); - @unlink(LOGS . 'random.log'); + if (file_exists(LOGS . 'random.log')) { + unlink(LOGS . 'random.log'); + } $log->write('random', 'Test warning'); $this->assertTrue(file_exists(LOGS . 'random.log')); @@ -65,7 +71,9 @@ function testLogFileWriting() { */ function testPathSetting() { $path = TMP . 'tests' . DS; - @unlink($path . 'error.log'); + if (file_exists(LOGS . 'error.log')) { + unlink(LOGS . 'error.log'); + } $log = new FileLog(compact('path')); $log->write('warning', 'Test warning'); diff --git a/lib/Cake/Test/Case/Model/CakeSchemaTest.php b/lib/Cake/Test/Case/Model/CakeSchemaTest.php index 953fada0fe8..b592f11eb97 100644 --- a/lib/Cake/Test/Case/Model/CakeSchemaTest.php +++ b/lib/Cake/Test/Case/Model/CakeSchemaTest.php @@ -526,7 +526,9 @@ function setUp() { */ function tearDown() { parent::tearDown(); - @unlink(TMP . 'tests' . DS .'schema.php'); + if (file_exists(TMP . 'tests' . DS .'schema.php')) { + unlink(TMP . 'tests' . DS .'schema.php'); + } unset($this->Schema); CakePlugin::unload(); } diff --git a/lib/Cake/Test/Case/Utility/FolderTest.php b/lib/Cake/Test/Case/Utility/FolderTest.php index fc85fd31169..ee88742e405 100644 --- a/lib/Cake/Test/Case/Utility/FolderTest.php +++ b/lib/Cake/Test/Case/Utility/FolderTest.php @@ -300,8 +300,9 @@ function testFolderRead() { $result = $Folder->read(true, true); $this->assertEqual($result[0], $expected); - $Folder->path = TMP . DS . 'non-existent'; + $Folder->path = TMP . 'non-existent'; $expected = array(array(), array()); + $this->setExpectedException('PHPUnit_Framework_Error_Warning'); $result = $Folder->read(true, true); $this->assertEqual($expected, $result); } diff --git a/lib/Cake/Test/Case/View/HelperTest.php b/lib/Cake/Test/Case/View/HelperTest.php index 6bdc30678d8..55cfbdde40c 100644 --- a/lib/Cake/Test/Case/View/HelperTest.php +++ b/lib/Cake/Test/Case/View/HelperTest.php @@ -526,6 +526,7 @@ function testAssetTimestampPluginsAndThemes() { $result = $this->Helper->assetTimestamp('/test_plugin/css/test_plugin_asset.css'); $this->assertPattern('#/test_plugin/css/test_plugin_asset.css\?[0-9]+$#', $result, 'Missing timestamp plugin'); + $this->setExpectedException('PHPUnit_Framework_Error_Warning'); $result = $this->Helper->assetTimestamp('/test_plugin/css/i_dont_exist.css'); $this->assertPattern('#/test_plugin/css/i_dont_exist.css\?$#', $result, 'No error on missing file'); diff --git a/lib/Cake/Test/Case/View/ViewTest.php b/lib/Cake/Test/Case/View/ViewTest.php index ab6306596de..7e830afed39 100644 --- a/lib/Cake/Test/Case/View/ViewTest.php +++ b/lib/Cake/Test/Case/View/ViewTest.php @@ -790,7 +790,9 @@ function testRenderCache() { $result = $View->renderCache($path, '+1 second'); $this->assertFalse($result); - @unlink($path); + if (file_exists($path)) { + unlink($path); + } $cacheText = 'some cacheText'; $f = fopen($path, 'w+');