Skip to content

Commit

Permalink
Fixed test cases for successful being built on travis.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Ploch committed Mar 24, 2012
1 parent d748fc7 commit fda0651
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 33 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: php

php:
- 5.2
- 5.3
- 5.4

Expand Down
7 changes: 4 additions & 3 deletions lib/Cake/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,12 @@ public static function set($settings = array(), $value = null, $config = 'defaul
*
* Permanently remove all expired and deleted data
*
* @param string $config The config name you wish to have garbage collected. Defaults to 'default'
* @param string $config [optional] The config name you wish to have garbage collected. Defaults to 'default'
* @param integer $expires [optional] An expires timestamp. Defaults to NULL
* @return void
*/
public static function gc($config = 'default') {
self::$_engines[$config]->gc();
public static function gc($config = 'default', $expires = null) {
self::$_engines[$config]->gc($expires);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion lib/Cake/Cache/CacheEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ public function init($settings = array()) {
* Garbage collection
*
* Permanently remove all expired and deleted data
*
* @param integer $expires [optional] An expires timestamp, invalidataing all data before.
* @return void
*/
public function gc() {
public function gc($expires = null) {
}

/**
Expand Down
5 changes: 3 additions & 2 deletions lib/Cake/Cache/Engine/FileEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ public function init($settings = array()) {

/**
* Garbage collection. Permanently remove all expired and deleted data
*
*
* @param integer $expires [optional] An expires timestamp, invalidataing all data before.
* @return boolean True if garbage collection was successful, false on failure
*/
public function gc() {
public function gc($expires = null) {
return $this->clear(true);
}

Expand Down
4 changes: 1 addition & 3 deletions lib/Cake/Model/Datasource/CakeSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public static function start() {
if (self::started()) {
return true;
}
CakeSession::init();
self::init();
$id = self::id();
session_write_close();
self::_configureSession();
Expand Down Expand Up @@ -601,8 +601,6 @@ protected static function _startSession() {
if (empty($_SESSION)) {
$_SESSION = array();
}
} elseif (!isset($_SESSION)) {
session_start();
} else {
session_start();
}
Expand Down
21 changes: 13 additions & 8 deletions lib/Cake/Model/Datasource/Session/CacheSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ public function open() {
* @return boolean Success
*/
public function close() {
$probability = mt_rand(1, 150);
if ($probability <= 3) {
Cache::gc();
}
return true;
}

Expand Down Expand Up @@ -74,21 +70,30 @@ public function write($id, $data) {
/**
* Method called on the destruction of a database session.
*
* @param integer $id ID that uniquely identifies session in database
* @param integer $id ID that uniquely identifies session in cache
* @return boolean True for successful delete, false otherwise.
*/
public function destroy($id) {
return Cache::delete($id, Configure::read('Session.handler.config'));
}

/**
* Helper function called on gc for database sessions.
* Helper function called on gc for cache sessions.
*
* @param integer $expires Timestamp (defaults to current time)
* @return boolean Success
*/
public function gc($expires = null) {
return Cache::gc();
return Cache::gc(Configure::read('Session.handler.config'), $expires);
}

/**
* Writes and closes a session
*
* @return void
*/
protected function _writeSession() {
session_write_close();
}

/**
Expand All @@ -97,7 +102,7 @@ public function gc($expires = null) {
* @return void
*/
public function __destruct() {
session_write_close();
$this->_writeSession();
}

}
18 changes: 10 additions & 8 deletions lib/Cake/Model/Datasource/Session/DatabaseSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ public function open() {
* @return boolean Success
*/
public function close() {
$probability = mt_rand(1, 150);
if ($probability <= 3) {
$this->gc();
}
return true;
}

Expand Down Expand Up @@ -144,16 +140,22 @@ public function gc($expires = null) {
return $this->_model->deleteAll(array($this->_model->alias . ".expires <" => $expires), false, false);
}

/**
* Writes and closes a session
*
* @return void
*/
protected function _writeSession() {
session_write_close();
}

/**
* Closes the session before the objects handling it become unavailable
*
* @return void
*/
public function __destruct() {
try {
session_write_close();
} catch (Exception $e) {
}
$this->_writeSession();
}

}
26 changes: 23 additions & 3 deletions lib/Cake/Test/Case/Model/Datasource/CakeSessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/

App::uses('CakeSession', 'Model/Datasource');
App::uses('DatabaseSession', 'Model/Datasource/Session');
App::uses('CacheSession', 'Model/Datasource/Session');

class TestCakeSession extends CakeSession {

Expand All @@ -31,6 +33,20 @@ public static function setHost($host) {

}

class TestCacheSession extends CacheSession {

protected function _writeSession() {
return true;
}
}

class TestDatabaseSession extends DatabaseSession {

protected function _writeSession() {
return true;
}
}

/**
* CakeSessionTest class
*
Expand Down Expand Up @@ -92,7 +108,7 @@ public function setUp() {
*/
public function teardown() {
if (TestCakeSession::started()) {
TestCakeSession::clear();
session_write_close();
}
unset($_SESSION);
parent::teardown();
Expand Down Expand Up @@ -550,6 +566,7 @@ public function testUsingPluginHandler() {
*/
public function testReadAndWriteWithCacheStorage() {
Configure::write('Session.defaults', 'cache');
Configure::write('Session.handler.engine', 'TestCacheSession');

TestCakeSession::init();
TestCakeSession::destroy();
Expand Down Expand Up @@ -585,6 +602,7 @@ public function testReadAndWriteWithCacheStorage() {
*/
public function testReadAndWriteWithCustomCacheConfig() {
Configure::write('Session.defaults', 'cache');
Configure::write('Session.handler.engine', 'TestCacheSession');
Configure::write('Session.handler.config', 'session_test');

Cache::config('session_test', array(
Expand All @@ -609,6 +627,7 @@ public function testReadAndWriteWithCustomCacheConfig() {
*/
public function testReadAndWriteWithDatabaseStorage() {
Configure::write('Session.defaults', 'database');
Configure::write('Session.handler.engine', 'TestDatabaseSession');
Configure::write('Session.handler.table', 'sessions');
Configure::write('Session.handler.model', 'Session');
Configure::write('Session.handler.database', 'test');
Expand Down Expand Up @@ -651,6 +670,7 @@ public function testReadAndWriteWithDatabaseStorage() {
*/
public function testSessionTimeout() {
Configure::write('debug', 2);
Configure::write('Session.defaults', 'cake');
Configure::write('Session.autoRegenerate', false);

$timeoutSeconds = Configure::read('Session.timeout') * 60;
Expand Down Expand Up @@ -683,7 +703,7 @@ public function testSessionTimeout() {
public function testCookieTimeoutFallback() {
$_SESSION = null;
Configure::write('Session', array(
'defaults' => 'php',
'defaults' => 'cake',
'timeout' => 400,
));
TestCakeSession::start();
Expand All @@ -692,7 +712,7 @@ public function testCookieTimeoutFallback() {

$_SESSION = null;
Configure::write('Session', array(
'defaults' => 'php',
'defaults' => 'cake',
'timeout' => 400,
'cookieTimeout' => 600
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public function testDescribeWithUuidPrimaryKey() {
public function testVirtualFieldWithFunction() {
$this->loadFixtures('User');
$User = ClassRegistry::init('User');
$User->virtualFields = array('name' => 'SUBSTR(User.user, 5)');
$User->virtualFields = array('name' => 'SUBSTR(User.user, 5, LENGTH(User.user) - 4)');

$result = $User->find('first', array(
'conditions' => array('User.user' => 'garrett')
Expand Down
9 changes: 7 additions & 2 deletions lib/Cake/Test/Case/Utility/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public function testBasic() {
'filesize' => filesize($file),
'mime' => 'text/x-php'
);
if (!function_exists('finfo_open') && !function_exists('mime_content_type')) {
if (!function_exists('finfo_open') && (!function_exists('mime_content_type') ||
function_exists('mime_content_type') && false === mime_content_type($this->File->pwd()))) {
$expecting['mime'] = false;
}

Expand Down Expand Up @@ -480,7 +481,11 @@ public function testMime() {
$this->skipIf(!function_exists('finfo_open') && !function_exists('mime_content_type'), 'Not able to read mime type');
$path = CAKE . 'Test' . DS . 'test_app' . DS . 'webroot' . DS . 'img' . DS . 'cake.power.gif';
$file = new File($path);
$this->assertEquals('image/gif', $file->mime());
$expected = 'image/gif';
if (function_exists('mime_content_type') && false === mime_content_type($file->pwd())) {
$expected = false;
}
$this->assertEquals($expected, $file->mime());
}

/**
Expand Down
15 changes: 13 additions & 2 deletions lib/Cake/Test/Case/View/Helper/RssHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,12 @@ public function testItemEnclosureLength() {
$File = new File($tmpFile, true);

$this->assertTrue($File->write('123'), 'Could not write to ' . $tmpFile);
clearstatcache(true, $tmpFile);

if (50300 <= PHP_VERSION_ID) {
clearstatcache(true, $tmpFile);
} else {
clearstatcache();
}

$item = array(
'title' => array(
Expand Down Expand Up @@ -637,6 +642,12 @@ public function testItemEnclosureLength() {
)
);
$result = $this->Rss->item(null, $item);
if (!function_exists('finfo_open') &&
(function_exists('mime_content_type') && false === mime_content_type($tmpFile))) {
$type = false;
} else {
$type = 'text/plain';
}
$expected = array(
'<item',
'<title',
Expand All @@ -651,7 +662,7 @@ public function testItemEnclosureLength() {
'enclosure' => array(
'url' => $this->Rss->url('/tests/cakephp.file.test.tmp', true),
'length' => filesize($tmpFile),
'type' => 'text/plain'
'type' => $type
),
'<pubDate',
date('r', strtotime('2008-05-31 12:00:00')),
Expand Down

0 comments on commit fda0651

Please sign in to comment.