protected function setUp() { parent::setUp(); $this->object = new DriverStub(Config::get('db')); $this->object->connect(); $this->table = new User(); }
protected function setUp() { parent::setUp(); $db = Config::get('db'); $db['user'] = '******'; $db['pass'] = '******'; Database::registry()->addDriver('default', new PgsqlDriver($db)); }
function config($key, $value = null) { if ($value !== null) { Config::set($key, $value); return true; } return Config::get($key); }
/** * Setup the DB once, not before every test. */ public static function setUpBeforeClass() { Database::registry()->addDriver('default', new MongoDriver(Config::get('db'))); // Remove singletons User::flushInstances(); Book::flushInstances(); Series::flushInstances(); Profile::flushInstances(); }
/** * Set code and config. * * @param string $code * @param array $config */ public function __construct($code, array $config = []) { parent::__construct(['initialize' => false] + $config); $this->_code = $code; $this->_localeBundle = new LocaleBundle(); $this->_messageBundle = new MessageBundle(); // Add default resource paths if ($paths = Config::get('titon.path.resources')) { $this->addResourcePaths('core', $paths); } }
/** * {@inheritdoc} * * @uses Titon\Common\Registry * @uses Titon\Utility\String */ public function bindDomains($domain, $catalog) { bind_textdomain_codeset($catalog, Config::encoding()); return $this->cache([__METHOD__, $domain, $catalog], function () use($domain, $catalog) { $locations = G11n::registry()->current()->getMessageBundle()->getPaths(); foreach ($locations as $location) { bindtextdomain($catalog, $location); } return true; }); }
/** * Set the locale using PHPs built in setlocale(). * * @link http://php.net/setlocale * @link http://php.net/manual/locale.setdefault.php * * @uses Titon\Common\Config * * @param string $key * @return \Titon\G11n\Locale * @throws \Titon\G11n\Exception\MissingLocaleException */ public function useLocale($key) { $key = self::canonicalize($key); if (!isset($this->_locales[$key])) { throw new MissingLocaleException(sprintf('Locale %s does not exist', $key)); } $locale = $this->_locales[$key]; $locales = [$locale]; $options = []; if ($this->getFallback()->getCode() != $locale->getCode()) { $locales[] = $this->getFallback(); } /** @type \Titon\G11n\Locale $loc */ foreach ($locales as $loc) { $config = $loc->allConfig(); $options[] = $config['code'] . '.UTF8'; $options[] = $config['code'] . '.UTF-8'; $options[] = $config['code']; if (!empty($config['iso3'])) { foreach ((array) $config['iso3'] as $iso3) { $options[] = $iso3 . '.UTF8'; $options[] = $iso3 . '.UTF-8'; $options[] = $iso3; } } if (!empty($config['iso2'])) { $options[] = $config['iso2'] . '.UTF8'; $options[] = $config['iso2'] . '.UTF-8'; $options[] = $config['iso2']; } } // Set environment $code = $locale->getCode(); putenv('LC_ALL=' . $code); setlocale(LC_ALL, $options); \Locale::setDefault($code); $this->_current = $locale; Config::set('titon.locale.current', $code); Config::set('titon.locale.cascade', $this->cascade()); $this->emit('g11n.onUse', [$this, $locale]); // Store via cookie if ($this->getConfig('storeCookie')) { $_COOKIE['locale'] = $key; } return $locale; }
/** * @copyright 2010-2014, The Titon Project * @license http://opensource.org/licenses/bsd-license.php * @link http://titon.io */ use Titon\Cache\Storage\FileSystemStorage; use Titon\Common\Config; use Titon\Debug\Debugger; use Titon\Mvc\Application; /** * -------------------------------------------------------------- * Development * -------------------------------------------------------------- * * Configuration pertaining to development environments should * be defined here. It will be bootstrapped automatically. */ $app = Application::getInstance(); /** * Update caching to use the file system. */ $app->get('cache')->addStorage('default', new FileSystemStorage(['directory' => TEMP_DIR . 'cache/'])); /** * Enable error reporting. */ Debugger::enable(true); /** * Define database login credentials. */ Config::set('db.default', ['host' => 'localhost', 'port' => 3306, 'user' => 'root', 'pass' => '', 'database' => '', 'encoding' => 'utf8']);
protected function setUp() { parent::setUp(); Database::registry()->addDriver('default', new SqliteDriver(Config::get('db'))); }
protected function setUp() { parent::setUp(); $this->object = new DriverStub(Config::get('db')); }
<?php /** * @copyright 2010-2013, The Titon Project * @license http://opensource.org/licenses/bsd-license.php * @link http://titon.io */ error_reporting(E_ALL | E_STRICT); define('TEST_DIR', __DIR__); define('TEMP_DIR', __DIR__ . '/tmp'); define('VENDOR_DIR', dirname(TEST_DIR) . '/vendor'); if (!file_exists(VENDOR_DIR . '/autoload.php')) { exit('Please install Composer in the root folder before running tests!'); } $loader = (require VENDOR_DIR . '/autoload.php'); $loader->add('Titon\\G11n', TEST_DIR); // Set resource paths use Titon\Common\Config; Config::add('titon.path.resources', TEMP_DIR); Config::add('titon.path.resources', dirname(TEST_DIR) . '/src/resources/');
<?php /** * @copyright 2010-2013, The Titon Project * @license http://opensource.org/licenses/bsd-license.php * @link http://titon.io */ use Titon\Common\Config; use Titon\G11n\G11n; /** * Add G11n resources if VENDOR_DIR constant exists. */ if (defined('VENDOR_DIR')) { Config::add('titon.path.resources', VENDOR_DIR . '/titon/g11n/src/resources/'); } /** * Convenience function for fetching a localized string. * Uses a single combination key. * * @uses Titon\Common\Registry * * @param string $key * @param array $params * @return string */ if (!function_exists('msg')) { function msg($key, array $params = []) { return G11n::registry()->translate($key, $params); } }
/** * Test that set() correctly sets values at the correct depths. */ public function testSet() { Config::set('Set.level1', 1); $this->assertEquals(Config::get('Set.level1'), 1); Config::set('Set.level2.level2', 2); $this->assertEquals(Config::get('Set.level2.level2'), 2); Config::set('Set.level3.level3.level3', 3); $this->assertEquals(Config::get('Set.level3.level3.level3'), 3); Config::set('Set.level4.level4.level4.level4', 4); $this->assertEquals(Config::get('Set.level4.level4.level4.level4'), 4); $this->assertTrue(is_array(Config::get('Set.level4.level4.level4'))); $this->assertFalse(Config::get('Set.level4.level4') === 'falsey'); Config::set('Set.level4.array', ['key' => 'value']); $this->assertEquals(Config::get('Set.level4.array'), ['key' => 'value']); $this->assertEquals(Config::get('Set.level4.array.key'), 'value'); Config::set('Set.level4', 'Flattened!'); $this->assertEquals(Config::get('Set.level4'), 'Flattened!'); $this->assertEquals(Config::get('Set.level4.level4.level4.level4'), null); }
* -------------------------------------------------------------- * Error Handling * -------------------------------------------------------------- * * A custom error handler can be defined that can output error * pages for uncaught exceptions. By default, the Application * object handles errors by initializing an ErrorController * and rendering a template with the View. */ Debugger::setHandler([$app, 'handleError']); /** * -------------------------------------------------------------- * Configuration * -------------------------------------------------------------- * * Define the primary configurations used within the application. * These values can be conveniently accessed via methods on * the Config class -- Config::salt(). */ Config::set('app', ['name' => 'Titon', 'salt' => 'AN3sk8ANjsSl1Hwx910APs7lq8nmsP5LQmKC', 'encoding' => 'UTF-8']); /** * -------------------------------------------------------------- * Resource Mapping * -------------------------------------------------------------- * * Define an array lookup paths for specific types of resources. * These paths will automatically be injected into classes that * make use of them -- for example, G11n and View. */ Config::set('titon.path', ['resources' => [RESOURCES_DIR, VENDOR_DIR . 'titon/g11n/src/resources'], 'views' => [VIEWS_DIR]]);