Inheritance: extends BaseDbTestCase
 protected function mockYiiApplication($config = [])
 {
     $this->initAppFileSystem();
     //
     // create user's config file, as it will override apps config for database connection in bootstrap
     //TODO: remove duplicates
     $env_db = getenv('DB_TYPE');
     $db = $GLOBALS['db'][$env_db];
     /* @var $mycfg \app\components\Configuration  faking class */
     $mycfg = json_decode(file_get_contents(self::$baseTestDir . '/data/default_config.json'));
     $mycfg->system->version = '1.1';
     //to avoid migration install
     $mycfg->database->dbname = @$db['dbname'];
     $mycfg->database->filename = @$db['filename'];
     $mycfg->database->format = $env_db;
     $mycfg->database->host = @$db['host'];
     $mycfg->database->login = @$db['username'];
     $mycfg->database->password = @$db['password'];
     file_put_contents($this->getConfigFilename(), json_encode($mycfg));
     //
     //work cfg
     $cfg = (require dirname(self::$baseTestDir) . '/config/config.php');
     // make work cfg testable
     unset($cfg['id'], $cfg['basePath'], $cfg['vendorPath'], $cfg['components']['db']);
     parent::mockYiiApplication(\yii\helpers\ArrayHelper::merge($cfg, $config));
     //var_dump(\Yii::$app->mycfg); die;
 }
 /**
  * Special override to set up the app with controllers that have a dynamic middleware. This is better suited to
  * testing Middleware so that the developer can pass in the middleware and subsequently perform tests on it
  *
  * @param array $env
  * @param array $middlewares
  */
 public function setUpApp($env = array(), $middlewares = array())
 {
     parent::setUpApp($env);
     $this->app->setModelLoaders(array(new \MABI\DirectoryModelLoader(__DIR__ . '/../TestApp/TestModelDir', $this->app, 'mabiTesting')));
     $dirControllerLoader = new \MABI\DirectoryControllerLoader(__DIR__ . '/../TestApp/TestControllerDir', $this->app, 'mabiTesting');
     foreach ($dirControllerLoader->getControllers() as $controller) {
         if (get_class($controller) == 'mabiTesting\\JustAController') {
             $this->controller = $controller;
             if (!empty($middlewares)) {
                 foreach ($middlewares as $middleware) {
                     $this->controller->addMiddleware($middleware);
                 }
                 $this->controller->addMiddleware(new \MABI\Middleware\AnonymousIdentifier());
             }
         }
         if (get_class($controller) == 'mabiTesting\\ModelBController') {
             $this->restController = $controller;
             if (!empty($middlewares)) {
                 foreach ($middlewares as $middleware) {
                     $this->restController->addMiddleware($middleware);
                 }
                 $this->restController->addMiddleware(new \MABI\Middleware\AnonymousIdentifier());
             }
         }
     }
     $this->app->setControllerLoaders(array($dirControllerLoader));
 }
 function endTest($method)
 {
     parent::endTest($method);
     foreach ($this->multiPackage as $file) {
         unlink($file);
     }
 }
Example #4
0
 function _isTest($method)
 {
     if ($isTest = parent::_isTest($method)) {
         if ($this->runOnly !== null) {
             $candidates = (array) $this->runOnly;
         }
         if ($this->excludeCase !== null) {
             $excludes = (array) $this->excludeCase;
         }
         switch (true) {
             case isset($candidates, $excludes):
                 return in_array($method, array_diff($candidates, $excludes));
             case isset($candidates):
                 return in_array($method, $candidates);
             case isset($excludes):
                 return !in_array($method, $excludes);
         }
     }
     return $isTest;
 }
 /**
  * End Test callback
  *
  * @param string $method
  * @return void
  * @access public
  */
 public function endTest($method)
 {
     parent::endTest($method);
     unset($this->Translations);
     ClassRegistry::flush();
 }
 public function setUpApp($env = array(), $withCache = false)
 {
     parent::setUpApp($env, $withCache);
     $this->app->setModelLoaders(array(new \MABI\DirectoryModelLoader('TestApp/TestModelDir', $this->app, 'mabiTesting')));
 }
Example #7
0
 /**
  * @covers \Phix\AppTestCase::getApp
  */
 public function testGetAppReturnsDefaultInstanceIfNoneAssigned()
 {
     $testCase = new AppTestCase();
     $this->assertEquals($testCase->getApp(), new App());
 }