Example #1
0
 /**
  * Get the cache object
  * 
  * Cache object defined by Configuration::SetCacheClass()
  * @return Cache
  */
 private static function _Cache()
 {
     if (is_null(self::$_cache)) {
         self::$_cache = \ORM\Utilities\Configuration::GetCache();
     }
     return self::$_cache;
 }
<?php

/**
 * Tests for ORM_Model class
 * @file
 * @author jarrod.swift
 * @todo Fix the autoloader
 */
namespace FlexibleORMTests;

use ORM\Utilities\Configuration;
require_once 'ORMTest.php';
// Delete existing SQLite file
$dsn = Configuration::sqliteDB('dsn');
$sqlDBLocation = str_replace("sqlite:", "", $dsn);
if (file_exists($sqlDBLocation)) {
    unlink($sqlDBLocation);
}
// Create sqlite database
$db = new \PDO($dsn);
$db->exec('CREATE TABLE cars(id integer primary key asc, brand varchar(255), colour varchar(32));');
$db = null;
/**
 * Test class for ORM_Model using multiple databases
 */
class ORMSqliteDatabaseTest extends ORMDatabaseTypeTest
{
    protected $carClass = '\\FlexibleORMTests\\Mock\\AlternateCarSqlite';
    protected $databaseConfig = 'sqliteDB';
}
Example #3
0
 /**
  * Get array containing the public and private keys for accessing AmazonSDB
  * 
  * \note These can be retrieved through the Accounts panel of the AWS website.
  * 
  * Looks for ini settings below, or the constants AWS_KEY and AWS_SECRET_KEY
  * @code
  * [AWS]
  * key = "aaaa"
  * secret_key = "aaaaa"
  * @endcode
  * 
  * @return array
  *      2 elements to the array: [0] => public, [1] => private
  */
 private static function _GetAWSKeys()
 {
     $aws = Configuration::AWS();
     $key = $aws->key ?: self::_GetAWSKeyID();
     $secret_key = $aws->secret_key ?: self::_GetAWSSecretKey();
     return array($key, $secret_key);
 }
Example #4
0
 /**
  * Connect to the database when creating the PDOFactory instance
  *
  * Sets the PDO connection to return ORM_PDOStatement objects when preparing
  * SQL.
  *
  * Uses configuration settings from the Configuration class. An example setup:
  *
  * <i>Ini File (test.ini):</i>
  * @code
  * [database]
  * name = "test_db"
  * host = "localhost"  #This is optional [default='localhost']
  * user = "******"
  * pass = "******"
  * prefix = "pgsql" # optional DSN prefix (default='mysql')
  * @endcode
  * 
  * <i>Alternative Method:</i>
  * @code
  * [database]
  * dsn  = "sqlite:/opt/databases/mydb.sq3"
  * user = "******"
  * pass = "******"
  * @endcode
  *
  * \n\n
  * <i>PHP:</i>
  * @code
  * Configuration::Load('test.ini');
  *
  * // Note database is not specified as this uses the default "database"
  * $query = PDOFactory::Get("SELECT * FROM rabbits");
  * @endcode
  *
  * @throws ORMPDOInvalidDatabaseConfigurationException if
  *      configuration details are not present or invalid
  * 
  * @param string $databaseConfig
  *      Name of the group to load from the Configuration (normally this would
  *      be "database").
  * @return PDOFactory
  */
 private function __construct($databaseConfig)
 {
     if (!Configuration::GroupExists($databaseConfig)) {
         throw new ORMPDOInvalidDatabaseConfigurationException("No database configuration details for {$databaseConfig}");
     }
     $db_name = Configuration::$databaseConfig()->name;
     $db_host = Configuration::$databaseConfig()->host ?: 'localhost';
     $db_user = Configuration::$databaseConfig()->user;
     $db_pswd = Configuration::$databaseConfig()->pass;
     $db_prefix = Configuration::$databaseConfig()->prefix ?: 'mysql';
     $dsn = Configuration::$databaseConfig()->dsn;
     $dsn = $dsn ?: "{$db_prefix}:host={$db_host};dbname={$db_name};";
     $this->_setDatabaseType($dsn);
     try {
         $this->_db = new \PDO($dsn, $db_user, $db_pswd);
         $this->_db->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
         $this->_db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
         $this->_db->setAttribute(\PDO::ATTR_STATEMENT_CLASS, array(__NAMESPACE__ . '\\ORM_PDOStatement'));
     } catch (\PDOException $e) {
         throw new \ORM\Exceptions\ORMPDOInvalidDatabaseConfigurationException("[{$databaseConfig}] " . $e->getMessage());
     }
 }
Example #5
0
 function setUp()
 {
     $this->autoloader = new AutoLoader(Configuration::packages()->toArray());
 }
 public function testCallOONull()
 {
     $this->assertNull(Configuration::test()->non_existant);
 }
Example #7
0
 * PHPUnit tests for flexible-orm
 */
namespace FlexibleORMTests;

use ORM\AutoLoader;
use ORM\Utilities\Cache\APCCache;
use ORM\Utilities\Configuration;
use PHPUnit_Framework_TestCase;
error_reporting(E_ALL);
require_once __DIR__ . '/../src/AutoLoader.php';
require_once 'AWSSDKforPHP/sdk.class.php';
$loader = new AutoLoader();
$loader->register(AutoLoader::AUTOLOAD_STYLE_FORM);
$loader->setPackageLocations(array('FlexibleORMTests' => __DIR__));
Configuration::Load(__DIR__ . '/test.ini');
Configuration::SetCacheClass('\\ORM\\Utilities\\Cache\\APCCache');
if (function_exists('apc_clear_cache')) {
    $cache = new APCCache();
    $cache->flush();
}
/**
 * Description of ORMTestClass
 *
 */
class ORMTest extends PHPUnit_Framework_TestCase
{
    public function testTruth()
    {
        $this->assertTrue(1 == 1);
    }
}
<?php

/**
 * Tests for ORM_Model class
 * @file
 * @author jarrod.swift
 * @todo Fix the autoloader
 */
namespace FlexibleORMTests;

use ORM\Utilities\Configuration;
use PDO;
require_once 'ORMTest.php';
$conf = Configuration::postgresDB();
$db = new PDO("pgsql:dbname={$conf->name};host=localhost", $conf->user, $conf->pass);
$db->exec('EMPTY TABLE cars IF EXISTS;');
$db = null;
/**
 * Test class for ORM_Model using multiple databases
 */
class ORMPGDatabaseTest extends ORMDatabaseTypeTest
{
    protected $carClass = '\\FlexibleORMTests\\Mock\\CarPostgres';
    protected $databaseConfig = 'postgresDB';
}