Exemplo n.º 1
0
 function testCollectionClear()
 {
     $collection = new qtil\Collection();
     $collection->insert('foo', 'bar');
     $collection->clear();
     $count = count($collection);
     $this->assertEquals(0, $count);
 }
Exemplo n.º 2
0
 /**
  * executes all rules, enabling them
  * @param array $rules
  * @return Base
  */
 public function applyRules(array $rules = [])
 {
     if (!empty($rules)) {
         $this->rules->fromArray($rules);
     }
     if (count($rules) > 0) {
         foreach ($rules as $rule) {
             if (is_callable($rule)) {
                 $rule($this);
             }
         }
     }
     return $this;
 }
Exemplo n.º 3
0
 /**
  * Default mapping constructor
  * @param array $mapping
  * @param \Closure $namingCallback
  */
 function __construct()
 {
     $args = func_get_args();
     $data = [];
     if (func_num_args()) {
         foreach ($args as $a) {
             if (qtil\ArrayUtil::isIterable($a)) {
                 $data = $a;
             } elseif (is_callable($a)) {
                 $this->setNamingCallback($a);
             }
         }
     }
     parent::__construct($data);
 }
Exemplo n.º 4
0
 /**
  * Helper method to create blank model if none found
  * @param string $className
  * @return persistr\Model\Blank
  */
 private static function createBlankPersistor($className)
 {
     $datasource = new qtil\Collection();
     $persistenceModel = new PersistenceModel($datasource);
     $persistor = new Persistor($className, $persistenceModel);
     self::register($persistor);
     $model = new Model\Blank($className);
     $datasource->insert($className, $model);
     return $persistor;
 }
Exemplo n.º 5
0
 function testCollectionFromCollection()
 {
     $data = range(0, 3);
     $collection = new qtil\Collection();
     $collection->merge($data);
     $collection2 = new qtil\Collection();
     $collection2->fromCollection($collection);
     $this->assertEquals($collection->toArray(), $collection2->toArray());
 }