コード例 #1
0
ファイル: TestCase.php プロジェクト: guitarpoet/clips-tool
 public function setUp()
 {
     $mute = getenv('MUTE_PHPUNIT');
     $ref = new \ReflectionClass($this);
     $func = $this->getName();
     if (!$mute && $func != 'testStub') {
         echo "\n----------" . $ref->name . " | " . $func . "----------\n";
     }
     $this->tool =& get_clips_tool();
     $this->tool->helper('fake');
     $this->clips = new Engine();
     $re = new \Addendum\ReflectionAnnotatedClass($this);
     foreach (array($re, $re->getMethod($func)) as $m) {
         foreach ($m->getAnnotations() as $a) {
             switch (get_class($a)) {
                 case "Clips\\Rules":
                     // We need to load the rules before test execution
                     $this->clips->clear();
                     // We should clear the clips every time
                     $rules = get_default($a, 'rules', array());
                     $templates = get_default($a, 'templates', array());
                     // Load the templates
                     foreach ($templates as $t) {
                         $this->clips->template($t);
                     }
                     // Load the rules
                     foreach ($rules as $r) {
                         $this->clips->load($r);
                     }
                     break;
                 case "Clips\\FakeModel":
                     $ds = $this->tool->library('dataSource');
                     $fake = $this->tool->library('fakeDataSource');
                     $ds->fake = $fake;
                     if (valid_obj($this, 'Clips\\Interfaces\\FakeDataSourceHandler')) {
                         $fake->handler = $this;
                     } else {
                         if (!$a->value) {
                             $a->value = 'expectFakeDataSourceHandler';
                         }
                         $fake->handler = $this->tool->library($a->value);
                         $this->fake_handler = $fake->handler;
                     }
                     $ds->_datasources = array('fake');
                     break;
                 case "Clips\\TestData":
                 case "Clips\\DataGenerator":
                     $this->data = $this->tool->enhance($a);
                     break;
                 case "Clips\\TestValue":
                     if (isset($a->json)) {
                         $a->file = $a->json;
                     }
                     if (isset($a->file)) {
                         $test_config_dir = clips_config('test_data_dir');
                         if (!$test_config_dir) {
                             $test_config_dir = clips_config('test_dir');
                             $test_config_dir = path_join($test_config_dir[0], 'data');
                         } else {
                             $test_config_dir = $test_config_dir[0];
                         }
                         $p = path_join($test_config_dir, $a->file);
                         if (\file_exists($p)) {
                             $this->value = \file_get_contents($p);
                             if (isset($a->json)) {
                                 $this->value = parse_json($this->value);
                             }
                         }
                     } else {
                         if (isset($a->context)) {
                             $this->value = clips_context($a->context);
                         } else {
                             if (isset($a->value)) {
                                 $this->value = $a->value;
                             }
                         }
                     }
                     break;
                 default:
                     $this->tool->annotationEnhance($a, $this);
             }
         }
     }
     $this->doSetUp();
 }
コード例 #2
0
ファイル: core_helper.php プロジェクト: guitarpoet/clips-tool
function clips_context($key = null, $value = null, $append = false)
{
    if (is_object($key) || is_array($key)) {
        foreach ($key as $k => $v) {
            clips_context($k, $v, $append);
        }
        return true;
    }
    $tool =& get_clips_tool();
    if (is_numeric($append)) {
        $arr = $tool->context($key);
        if ($arr == null) {
            $arr = array();
        }
        $index = $append;
        if ($index >= 0 && $index < count($arr)) {
            return $tool->context($key, array_splice($arr, $index, 0, $value));
        }
        $append = true;
    }
    return $tool->context($key, $value, $append);
}
コード例 #3
0
ファイル: web_helper.php プロジェクト: guitarpoet/clips-tool
/**
 * Get default form's configuration name(pagination use this too).
 *
 * The default name is controller's name and the method's name.
 *
 * For example:
 *
 * Controller => Demo\Controllers\AdminController
 * Method => index
 *
 * will get the default name as
 *
 * AdminController/index
 *
 * @author Jack
 * @date Sat Feb 21 11:55:36 2015
 */
function default_form_name()
{
    $controller = clips_context('controller_class');
    $method = clips_context('conroller_method');
    $name = explode('Controllers', $controller);
    // Get the name after controllers namespace, and get the last basename as the controller name
    $name = basename($name[count($name) - 1]);
    return $controller . '/' . $method;
}