Browse Source

Fixing test cases

ADmad 15 years ago
parent
commit
e5f2f6a236

+ 3 - 2
lib/Cake/Test/Case/Core/ObjectTest.php

@@ -368,7 +368,9 @@ class ObjectTest extends CakeTestCase {
  * @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 @@ class ObjectTest extends CakeTestCase {
 		$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');

+ 6 - 2
lib/Cake/Test/Case/Log/CakeLogTest.php

@@ -95,7 +95,9 @@ class CakeLogTest extends CakeTestCase {
  * @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 @@ class CakeLogTest extends CakeTestCase {
  * @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'));

+ 12 - 4
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 @@ class FileLogTest extends CakeTestCase {
 		$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 @@ class FileLogTest extends CakeTestCase {
 		$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 @@ class FileLogTest extends CakeTestCase {
  */
 	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');

+ 3 - 1
lib/Cake/Test/Case/Model/CakeSchemaTest.php

@@ -526,7 +526,9 @@ class CakeSchemaTest extends CakeTestCase {
  */
 	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();
 	}

+ 2 - 1
lib/Cake/Test/Case/Utility/FolderTest.php

@@ -300,8 +300,9 @@ class FolderTest extends CakeTestCase {
 		$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);
 	}

+ 1 - 0
lib/Cake/Test/Case/View/HelperTest.php

@@ -526,6 +526,7 @@ class HelperTest extends CakeTestCase {
 		$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');
 

+ 3 - 1
lib/Cake/Test/Case/View/ViewTest.php

@@ -790,7 +790,9 @@ class ViewTest extends CakeTestCase {
 
 		$result = $View->renderCache($path, '+1 second');
 		$this->assertFalse($result);
-		@unlink($path);
+		if (file_exists($path)) {
+			unlink($path);
+		}
 
 		$cacheText = '<!--cachetime:' . (time() + 10) . '-->some cacheText';
 		$f = fopen($path, 'w+');