示例#1
0
 /**
  * Returns the current application context.
  *
  * @param  bool $forceReload  true to force context reload, false otherwise
  *
  * @return sfContext
  */
 public function getContext($forceReload = false)
 {
     if (null === $this->context || $forceReload) {
         $isContextEmpty = null === $this->context;
         $context = $isContextEmpty ? sfContext::getInstance() : $this->context;
         // create configuration
         $currentConfiguration = $context->getConfiguration();
         $configuration = ProjectConfiguration::getApplicationConfiguration($currentConfiguration->getApplication(), $currentConfiguration->getEnvironment(), $currentConfiguration->isDebug());
         // connect listeners
         $configuration->getEventDispatcher()->connect('application.throw_exception', array($this, 'listenToException'));
         foreach ($this->listeners as $name => $listener) {
             $configuration->getEventDispatcher()->connect($name, $listener);
         }
         // create context
         $this->context = sfContext::createInstance($configuration);
         unset($currentConfiguration);
         if (!$isContextEmpty) {
             sfConfig::clear();
             sfConfig::add($this->rawConfiguration);
         } else {
             $this->rawConfiguration = sfConfig::getAll();
         }
     }
     return $this->context;
 }
 protected function _restoreSfConfig()
 {
     if (!empty($this->_backupSfConfig)) {
         sfConfig::clear();
         sfConfig::add($this->_backupSfConfig);
     }
 }
 /**
  * Removes a key from symfony config
  */
 public function remove($key)
 {
     $all = sfConfig::getAll();
     unset($all[$key]);
     sfConfig::clear();
     sfConfig::add($all);
     return $this;
 }
 /** Restores all sfConfig values to their state before the current test was
  *   run.
  *
  * @return static
  */
 public function flushConfigs()
 {
     if (isset(self::$_configs)) {
         sfConfig::clear();
         sfConfig::add(self::$_configs);
     } else {
         self::$_configs = sfConfig::getAll();
     }
     return $this;
 }
 /**
  * Executes the filter chain.
  *
  * @param sfFilterChain $filterChain
  */
 public function execute($filterChain)
 {
     $config = sfConfig::getAll();
     $host = sfContext::getInstance()->getRequest()->getHost();
     foreach ($config as $key => $value) {
         if ($key == 'dm_' . $host) {
             foreach ($value as $subkey => $subval) {
                 $config['dm_' . $subkey] = $subval;
             }
         }
     }
     sfConfig::clear();
     sfConfig::add($config);
     $filterChain->execute();
 }
示例#6
0
 /**
  * Returns the current application context.
  *
  * @param  bool $forceReload  true to force context reload, false otherwise
  *
  * @return sfContext
  */
 public function getContext($forceReload = false)
 {
     if (is_null($this->context) || $forceReload) {
         if (!is_null($this->context)) {
             $currentConfiguration = $this->context->getConfiguration();
             $configuration = ProjectConfiguration::getApplicationConfiguration($currentConfiguration->getApplication(), $currentConfiguration->getEnvironment(), $currentConfiguration->isDebug());
             $this->context = sfContext::createInstance($configuration);
             unset($currentConfiguration);
             sfConfig::clear();
             sfConfig::add($this->rawConfiguration);
         } else {
             $this->context = sfContext::getInstance();
             $this->context->initialize($this->context->getConfiguration());
             $this->rawConfiguration = sfConfig::getAll();
         }
         $this->context->getEventDispatcher()->connect('application.throw_exception', array($this, 'ListenToException'));
         foreach ($this->listeners as $name => $listener) {
             $this->context->getEventDispatcher()->connect($name, $listener);
         }
     }
     return $this->context;
 }
示例#7
0
// ::get() ::set()
$t->diag('::get() ::set()');
sfConfig::clear();
sfConfig::set('foo', 'bar');
$t->is(sfConfig::get('foo'), 'bar', '::get() returns the value of key config');
$t->is(sfConfig::get('foo1', 'default_value'), 'default_value', '::get() takes a default value as its second argument');
// ::has()
$t->diag('::has()');
sfConfig::clear();
$t->is(sfConfig::has('foo'), false, '::has() returns false if the key config does not exist');
sfConfig::set('foo', 'bar');
$t->is(sfConfig::has('foo'), true, '::has() returns true if the key config exists');
// ::add()
$t->diag('::add()');
sfConfig::clear();
sfConfig::set('foo', 'bar');
sfConfig::set('foo1', 'foo1');
sfConfig::add(array('foo' => 'foo', 'bar' => 'bar'));
$t->is(sfConfig::get('foo'), 'foo', '::add() adds an array of config parameters');
$t->is(sfConfig::get('bar'), 'bar', '::add() adds an array of config parameters');
$t->is(sfConfig::get('foo1'), 'foo1', '::add() adds an array of config parameters');
// ::getAll()
$t->diag('::getAll()');
sfConfig::clear();
sfConfig::set('foo', 'bar');
sfConfig::set('foo1', 'foo1');
$t->is(sfConfig::getAll(), array('foo' => 'bar', 'foo1' => 'foo1'), '::getAll() returns all config parameters');
// ::clear()
$t->diag('::clear()');
sfConfig::clear();
$t->is(sfConfig::get('foo1'), null, '::clear() removes all config parameters');
 public function activate()
 {
     sfConfig::clear();
     sfConfig::add($this->config);
 }
 /**
  * TearDown
  */
 public function tearDown()
 {
     sfConfig::clear();
     Replica::removeAll();
     Replica::setCacheManager(null);
 }
 /**
  * setUp method for PHPUnit
  */
 protected function setUp()
 {
     // Init concrete test config && autoload
     sfConfig::clear();
     ProjectConfiguration::getApplicationConfiguration($this->getApplication(), $this->getEnvironment(), $this->isDebug());
     // Object helper
     $this->helper = $this->makeHelper();
     // Custom init
     $this->_initialize();
     // Begin transaction
     if ($conn = $this->getConnection()) {
         $conn->beginTransaction();
     }
     $this->_start();
 }
示例#11
0
 /**
  * Génération brute de l'url cross app, passer par la fonction genUrl de préference (gestion du cache)
  *
  * @static
  * @throws Exception
  * @param string $app
  * @param string $url
  * @param bool $absolute
  * @param string $env
  * @param string $initialInstanceName for test purpose
  * @return mixed
  */
 public static function buildUrl($app, $url, $absolute = false, $env = null, $initialInstanceName = null)
 {
     $initialApp = sfConfig::get('sf_app');
     if ($initialInstanceName == null) {
         $initialInstanceName = $initialApp;
     }
     $initialScriptName = $_SERVER['SCRIPT_NAME'];
     $initialFrontController = basename($initialScriptName);
     $initialConfig = sfConfig::getAll();
     $debug = sfConfig::get('sf_debug');
     //environnement par défaut
     if ($env == null) {
         $env = $initialConfig['sf_environment'];
     }
     //création du contexte
     if (!sfContext::hasInstance($app)) {
         sfConfig::set('sf_factory_storage', 'sfNoStorage');
         // la config de base est restaurée à la fin de la fonction
         sfConfig::set('sf_use_database', false);
         $configuration = ProjectConfiguration::getApplicationConfiguration($app, $env, $debug);
         $context = sfContext::createInstance($configuration, $app);
         unset($configuration);
     } else {
         $context = sfContext::getInstance($app);
     }
     //détermination du front controller
     $finalFrontController = $app;
     if ($env != 'prod') {
         $finalFrontController .= '_' . $env;
     }
     $finalFrontController .= '.php';
     $crossUrl = $context->getController()->genUrl($url, $absolute);
     unset($context);
     //vérrification de l'existence du front controller
     if (!file_exists(sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . $finalFrontController)) {
         throw new Exception('Le front controller ' . $finalFrontController . ' est introuvable.');
     }
     $crossUrl = str_replace($initialFrontController, $finalFrontController, $crossUrl);
     //retour au context initial
     if ($app !== $initialInstanceName) {
         sfContext::switchTo($initialInstanceName);
         sfConfig::clear();
         sfConfig::add($initialConfig);
     }
     return $crossUrl;
 }
示例#12
0
// ->generate()
$t->diag('->generate()');
$g = newChart(array('user_id' => $ut->getUserId('user_gb_noCars'), 'full_history' => false));
$t->cmp_ok($g->generate(), '===', false, 'If the User has no cars, the chart cannot be generated.');
$g = newChart();
$t->ok($g->generate(), '->generate() Returns data required to build the chart.');
// ->display()
$t->diag('->display()');
$g = newChart(array('user_id' => $ut->getUserId('user_gb_noCars')));
$t->like($g->display(), '/Not enough data/', 'If the User has no cars, a message id displayed instead of the chart.');
$g = newChart();
$t->like($g->display(), '/This function cannot/', 'Even if the User has cars, nothing is generated by ChartBuilder. This task is left to childrens.');
// ->doForceGenerate()
$t->diag('->doForceGenerate()');
$g = newChart();
sfConfig::clear('app_charts_force_generate');
$t->cmp_ok($g->doForceGenerate(), '===', false, '->doForceGenerate() returns false by default');
sfConfig::set('app_charts_force_generate', true);
$t->cmp_ok($g->doForceGenerate(), '===', true, '->doForceGenerate() returns the value set in app_charts_force_generate');
function getData($data = array())
{
    $fields = Doctrine_Core::getTable('Chart')->getFieldNames();
    $defaults = array_combine($fields, array_fill(0, count($fields), null));
    unset($defaults['created_at'], $defaults['updated_at'], $defaults['slug'], $defaults['id']);
    $foreign = array('vehicles_list' => null, 'categories_list' => null);
    $defaults = array_merge($defaults, $foreign);
    return array_merge($defaults, $data);
}
function newChart($data = array(), $options = array(), $attributes = array())
{
    $ut = new otokouTestFunctional(new sfBrowser());