Skip to content
This repository
Browse code

Fixed test cases for successful being built on travis.

  • Loading branch information...
commit fda065101ba3414fcc82eecc521295fa9ac41e6a 1 parent d748fc7
Thomas Ploch authored March 24, 2012
1  .travis.yml
... ...
@@ -1,6 +1,7 @@
1 1
 language: php
2 2
 
3 3
 php:
  4
+  - 5.2
4 5
   - 5.3
5 6
   - 5.4
6 7
 
7  lib/Cake/Cache/Cache.php
@@ -250,11 +250,12 @@ public static function set($settings = array(), $value = null, $config = 'defaul
250 250
  *
251 251
  * Permanently remove all expired and deleted data
252 252
  *
253  
- * @param string $config The config name you wish to have garbage collected. Defaults to 'default'
  253
+ * @param string $config [optional] The config name you wish to have garbage collected. Defaults to 'default'
  254
+ * @param integer $expires [optional] An expires timestamp. Defaults to NULL
254 255
  * @return void
255 256
  */
256  
-	public static function gc($config = 'default') {
257  
-		self::$_engines[$config]->gc();
  257
+	public static function gc($config = 'default', $expires = null) {
  258
+		self::$_engines[$config]->gc($expires);
258 259
 	}
259 260
 
260 261
 /**
4  lib/Cake/Cache/CacheEngine.php
@@ -51,9 +51,11 @@ public function init($settings = array()) {
51 51
  * Garbage collection
52 52
  *
53 53
  * Permanently remove all expired and deleted data
  54
+ * 
  55
+ * @param integer $expires [optional] An expires timestamp, invalidataing all data before.
54 56
  * @return void
55 57
  */
56  
-	public function gc() {
  58
+	public function gc($expires = null) {
57 59
 	}
58 60
 
59 61
 /**
5  lib/Cake/Cache/Engine/FileEngine.php
@@ -87,10 +87,11 @@ public function init($settings = array()) {
87 87
 
88 88
 /**
89 89
  * Garbage collection. Permanently remove all expired and deleted data
90  
- *
  90
+ * 
  91
+ * @param integer $expires [optional] An expires timestamp, invalidataing all data before.
91 92
  * @return boolean True if garbage collection was successful, false on failure
92 93
  */
93  
-	public function gc() {
  94
+	public function gc($expires = null) {
94 95
 		return $this->clear(true);
95 96
 	}
96 97
 
4  lib/Cake/Model/Datasource/CakeSession.php
@@ -180,7 +180,7 @@ public static function start() {
180 180
 		if (self::started()) {
181 181
 			return true;
182 182
 		}
183  
-		CakeSession::init();
  183
+		self::init();
184 184
 		$id = self::id();
185 185
 		session_write_close();
186 186
 		self::_configureSession();
@@ -601,8 +601,6 @@ protected static function _startSession() {
601 601
 			if (empty($_SESSION)) {
602 602
 				$_SESSION = array();
603 603
 			}
604  
-		} elseif (!isset($_SESSION)) {
605  
-			session_start();
606 604
 		} else {
607 605
 			session_start();
608 606
 		}
21  lib/Cake/Model/Datasource/Session/CacheSession.php
@@ -43,10 +43,6 @@ public function open() {
43 43
  * @return boolean Success
44 44
  */
45 45
 	public function close() {
46  
-		$probability = mt_rand(1, 150);
47  
-		if ($probability <= 3) {
48  
-			Cache::gc();
49  
-		}
50 46
 		return true;
51 47
 	}
52 48
 
@@ -74,7 +70,7 @@ public function write($id, $data) {
74 70
 /**
75 71
  * Method called on the destruction of a database session.
76 72
  *
77  
- * @param integer $id ID that uniquely identifies session in database
  73
+ * @param integer $id ID that uniquely identifies session in cache
78 74
  * @return boolean True for successful delete, false otherwise.
79 75
  */
80 76
 	public function destroy($id) {
@@ -82,13 +78,22 @@ public function destroy($id) {
82 78
 	}
83 79
 
84 80
 /**
85  
- * Helper function called on gc for database sessions.
  81
+ * Helper function called on gc for cache sessions.
86 82
  *
87 83
  * @param integer $expires Timestamp (defaults to current time)
88 84
  * @return boolean Success
89 85
  */
90 86
 	public function gc($expires = null) {
91  
-		return Cache::gc();
  87
+		return Cache::gc(Configure::read('Session.handler.config'), $expires);
  88
+	}
  89
+
  90
+/**
  91
+ * Writes and closes a session
  92
+ * 
  93
+ * @return void 
  94
+ */
  95
+	protected function _writeSession() {
  96
+		session_write_close();
92 97
 	}
93 98
 
94 99
 /**
@@ -97,7 +102,7 @@ public function gc($expires = null) {
97 102
  * @return void
98 103
  */
99 104
 	public function __destruct() {
100  
-		session_write_close();
  105
+		$this->_writeSession();
101 106
 	}
102 107
 
103 108
 }
18  lib/Cake/Model/Datasource/Session/DatabaseSession.php
@@ -79,10 +79,6 @@ public function open() {
79 79
  * @return boolean Success
80 80
  */
81 81
 	public function close() {
82  
-		$probability = mt_rand(1, 150);
83  
-		if ($probability <= 3) {
84  
-			$this->gc();
85  
-		}
86 82
 		return true;
87 83
 	}
88 84
 
@@ -145,15 +141,21 @@ public function gc($expires = null) {
145 141
 	}
146 142
 
147 143
 /**
  144
+ * Writes and closes a session
  145
+ * 
  146
+ * @return void 
  147
+ */
  148
+	protected function _writeSession() {
  149
+		session_write_close();
  150
+	}
  151
+
  152
+/**
148 153
  * Closes the session before the objects handling it become unavailable
149 154
  *
150 155
  * @return void
151 156
  */
152 157
 	public function __destruct() {
153  
-		try {
154  
-			session_write_close();
155  
-		} catch (Exception $e) {
156  
-		}
  158
+		$this->_writeSession();
157 159
 	}
158 160
 
159 161
 }
26  lib/Cake/Test/Case/Model/Datasource/CakeSessionTest.php
@@ -18,6 +18,8 @@
18 18
  */
19 19
 
20 20
 App::uses('CakeSession', 'Model/Datasource');
  21
+App::uses('DatabaseSession', 'Model/Datasource/Session');
  22
+App::uses('CacheSession', 'Model/Datasource/Session');
21 23
 
22 24
 class TestCakeSession extends CakeSession {
23 25
 
@@ -31,6 +33,20 @@ public static function setHost($host) {
31 33
 
32 34
 }
33 35
 
  36
+class TestCacheSession extends CacheSession {
  37
+
  38
+	protected function _writeSession() {
  39
+		return true;
  40
+	}
  41
+}
  42
+
  43
+class TestDatabaseSession extends DatabaseSession {
  44
+
  45
+	protected function _writeSession() {
  46
+		return true;
  47
+	}
  48
+}
  49
+
34 50
 /**
35 51
  * CakeSessionTest class
36 52
  *
@@ -92,7 +108,7 @@ public function setUp() {
92 108
  */
93 109
 	public function teardown() {
94 110
 		if (TestCakeSession::started()) {
95  
-			TestCakeSession::clear();
  111
+			session_write_close();
96 112
 		}
97 113
 		unset($_SESSION);
98 114
 		parent::teardown();
@@ -550,6 +566,7 @@ public function testUsingPluginHandler() {
550 566
  */
551 567
 	public function testReadAndWriteWithCacheStorage() {
552 568
 		Configure::write('Session.defaults', 'cache');
  569
+		Configure::write('Session.handler.engine', 'TestCacheSession');
553 570
 
554 571
 		TestCakeSession::init();
555 572
 		TestCakeSession::destroy();
@@ -585,6 +602,7 @@ public function testReadAndWriteWithCacheStorage() {
585 602
  */
586 603
 	public function testReadAndWriteWithCustomCacheConfig() {
587 604
 		Configure::write('Session.defaults', 'cache');
  605
+		Configure::write('Session.handler.engine', 'TestCacheSession');
588 606
 		Configure::write('Session.handler.config', 'session_test');
589 607
 
590 608
 		Cache::config('session_test', array(
@@ -609,6 +627,7 @@ public function testReadAndWriteWithCustomCacheConfig() {
609 627
  */
610 628
 	public function testReadAndWriteWithDatabaseStorage() {
611 629
 		Configure::write('Session.defaults', 'database');
  630
+		Configure::write('Session.handler.engine', 'TestDatabaseSession');
612 631
 		Configure::write('Session.handler.table', 'sessions');
613 632
 		Configure::write('Session.handler.model', 'Session');
614 633
 		Configure::write('Session.handler.database', 'test');
@@ -651,6 +670,7 @@ public function testReadAndWriteWithDatabaseStorage() {
651 670
  */
652 671
 	public function testSessionTimeout() {
653 672
 		Configure::write('debug', 2);
  673
+		Configure::write('Session.defaults', 'cake');
654 674
 		Configure::write('Session.autoRegenerate', false);
655 675
 
656 676
 		$timeoutSeconds = Configure::read('Session.timeout') * 60;
@@ -683,7 +703,7 @@ public function testSessionTimeout() {
683 703
 	public function testCookieTimeoutFallback() {
684 704
 		$_SESSION = null;
685 705
 		Configure::write('Session', array(
686  
-			'defaults' => 'php',
  706
+			'defaults' => 'cake',
687 707
 			'timeout' => 400,
688 708
 		));
689 709
 		TestCakeSession::start();
@@ -692,7 +712,7 @@ public function testCookieTimeoutFallback() {
692 712
 
693 713
 		$_SESSION = null;
694 714
 		Configure::write('Session', array(
695  
-			'defaults' => 'php',
  715
+			'defaults' => 'cake',
696 716
 			'timeout' => 400,
697 717
 			'cookieTimeout' => 600
698 718
 		));
2  lib/Cake/Test/Case/Model/Datasource/Database/SqliteTest.php
@@ -353,7 +353,7 @@ public function testDescribeWithUuidPrimaryKey() {
353 353
 	public function testVirtualFieldWithFunction() {
354 354
 		$this->loadFixtures('User');
355 355
 		$User = ClassRegistry::init('User');
356  
-		$User->virtualFields = array('name' => 'SUBSTR(User.user, 5)');
  356
+		$User->virtualFields = array('name' => 'SUBSTR(User.user, 5, LENGTH(User.user) - 4)');
357 357
 
358 358
 		$result = $User->find('first', array(
359 359
 			'conditions' => array('User.user' => 'garrett')
9  lib/Cake/Test/Case/Utility/FileTest.php
@@ -80,7 +80,8 @@ public function testBasic() {
80 80
 			'filesize' => filesize($file),
81 81
 			'mime' => 'text/x-php'
82 82
 		);
83  
-		if (!function_exists('finfo_open') && !function_exists('mime_content_type')) {
  83
+		if (!function_exists('finfo_open') && (!function_exists('mime_content_type') ||
  84
+				function_exists('mime_content_type') && false === mime_content_type($this->File->pwd()))) {
84 85
 			$expecting['mime'] = false;
85 86
 		}
86 87
 
@@ -480,7 +481,11 @@ public function testMime() {
480 481
 		$this->skipIf(!function_exists('finfo_open') && !function_exists('mime_content_type'), 'Not able to read mime type');
481 482
 		$path = CAKE . 'Test' . DS . 'test_app' . DS . 'webroot' . DS . 'img' . DS . 'cake.power.gif';
482 483
 		$file = new File($path);
483  
-		$this->assertEquals('image/gif', $file->mime());
  484
+		$expected = 'image/gif';
  485
+		if (function_exists('mime_content_type') && false === mime_content_type($file->pwd())) {
  486
+			$expected = false;
  487
+		}
  488
+		$this->assertEquals($expected, $file->mime());
484 489
 	}
485 490
 
486 491
 /**
15  lib/Cake/Test/Case/View/Helper/RssHelperTest.php
@@ -607,7 +607,12 @@ public function testItemEnclosureLength() {
607 607
 		$File = new File($tmpFile, true);
608 608
 
609 609
 		$this->assertTrue($File->write('123'), 'Could not write to ' . $tmpFile);
610  
-		clearstatcache(true, $tmpFile);
  610
+
  611
+		if (50300 <= PHP_VERSION_ID) {
  612
+			clearstatcache(true, $tmpFile);
  613
+		} else {
  614
+			clearstatcache();
  615
+		}
611 616
 
612 617
 		$item = array(
613 618
 			'title' => array(
@@ -637,6 +642,12 @@ public function testItemEnclosureLength() {
637 642
 			)
638 643
 		);
639 644
 		$result = $this->Rss->item(null, $item);
  645
+		if (!function_exists('finfo_open') && 
  646
+				(function_exists('mime_content_type') && false === mime_content_type($tmpFile))) {
  647
+			$type = false;
  648
+		} else {
  649
+			$type = 'text/plain';
  650
+		}
640 651
 		$expected = array(
641 652
 			'<item',
642 653
 			'<title',
@@ -651,7 +662,7 @@ public function testItemEnclosureLength() {
651 662
 			'enclosure' => array(
652 663
 				'url' => $this->Rss->url('/tests/cakephp.file.test.tmp', true),
653 664
 				'length' => filesize($tmpFile),
654  
-				'type' => 'text/plain'
  665
+				'type' => $type
655 666
 			),
656 667
 			'<pubDate',
657 668
 			date('r', strtotime('2008-05-31 12:00:00')),

0 notes on commit fda0651

Please sign in to comment.
Something went wrong with that request. Please try again.