Skip to content

Commit

Permalink
Implemented check for required extensions via ::enabled() for mysql a…
Browse files Browse the repository at this point in the history
…nd mongodb datasources/adapters
  • Loading branch information
daetal-us authored and gwoo committed Mar 30, 2010
1 parent 7fa2e13 commit c4a4d0d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions libraries/lithium/data/source/MongoDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ public function __destruct() {
}
}

/**
* Check for required PHP extension
*
* @return boolean
*/
public static function enabled() {
return extension_loaded('mongo');
}

/**
* Configures a model class by overriding the default dependencies for `'recordSet'` and
* `'record'` , and sets the primary key to `'_id'`, in keeping with Mongo's conventions.
Expand Down
9 changes: 9 additions & 0 deletions libraries/lithium/data/source/database/adapter/MySql.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ public function __construct(array $config = array()) {
parent::__construct($config + $defaults);
}

/**
* Check for required PHP extension
*
* @return boolean
*/
public static function enabled() {
return extension_loaded('mysql');
}

/**
* Connects to the database using the options provided to the class constructor.
*
Expand Down
9 changes: 9 additions & 0 deletions libraries/lithium/tests/cases/data/source/MongoDbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@

namespace lithium\tests\cases\data\source;

use \lithium\data\Connections;
use \lithium\data\source\MongoDb;

class MongoDbTest extends \lithium\test\Unit {

public function skip() {
$message = 'MongoDb Extension is not loaded';
$this->skipIf(!MongoDb::enabled(), $message);
}

}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class MySqlTest extends \lithium\test\Unit {
* @todo Tie into the Environment class to ensure that the test database is being used.
*/
public function skip() {
$message = 'MySql Extension is not loaded';
$this->skipIf(!MySql::enabled(), $message);

$this->_dbConfig = Connections::get('test', array('config' => true));
$hasDb = (isset($this->_dbConfig['adapter']) && $this->_dbConfig['adapter'] == 'MySql');
$message = 'Test database is either unavailable, or not using a MySQL adapter';
Expand Down

0 comments on commit c4a4d0d

Please sign in to comment.