Example #1
0
 function testCanQueryToRetrieveOneRow()
 {
     $db = $this->getPopulatedDb();
     $result = $db->query('SELECT word FROM words ORDER BY id LIMIT 1');
     $this->assertSame(count($result), 1);
     $this->assertSame($result->fetch(), _first($this->getAllRows()));
 }
Example #2
0
 /**
  * Sets maximum permissable length.
  *
  * @param int $max_len  maximum permissable length
  */
 protected function setMaxLength($max_len)
 {
     /* server side filter always at front of queue: if already exists,
        modify it. Otherwise add server side validation rule */
     $first = _first($this->filters);
     if ($first !== false && $first instanceof T_Validate_MaxLength) {
         $first->setMaxLength($max_len);
     } else {
         array_unshift($this->filters, new T_Validate_MaxLength($max_len));
     }
     return $this;
 }
Example #3
0
 function testCanExecuteSingleRequestInNonBlockingQueue()
 {
     $r = _first($this->getRequests());
     $q = new T_Curl_Queue();
     $this->assertSame($q, $q->queue($r));
     $this->assertFalse(strlen($r->getBody()) > 0);
     $this->assertFalse($q->ping($r));
     // ^ non-blocking so request just started to execute
     $this->assertSame($q, $q->waitFor($r));
     // ^ blocks until curl request completed
     $this->assertTrue($q->ping($r));
     $this->assertTrue(strlen($r->getBody()) > 0);
 }
Example #4
0
 function testGetVersionDependsOnFilesInGroup()
 {
     $names = array('test1', 'test2');
     $ext = '.js';
     foreach ($names as $fn) {
         $p = T_CACHE_DIR . $fn . $ext;
         $expect[] = $p;
         touch($p);
     }
     $files1 = new T_Code_Files(T_CACHE_DIR, $names, $ext);
     $files2 = new T_Code_Files(T_CACHE_DIR, array(_first($names)), $ext);
     $this->assertNotEquals($files2->getVersion(), $files1->getVersion());
     foreach ($expect as $p) {
         @unlink($p);
     }
 }
Example #5
0
     $svn = $v;
 }
 $php = $php->compress();
 // compress code
 // export
 switch ($format) {
     case 'dir':
         $class = $php->getClasses();
         if (count($class) != 1) {
             $class = implode(', ', $class);
             $msg = "All sources must be one class per file to create an autoload tree ({$class}).";
             echo $php->getInline();
             fwrite(STDERR, $msg);
             exit(2);
         }
         $class = _first($class);
         $dir = explode('_', $class);
         $file = array_pop($dir) . T_PHP_EXT;
         $dir = $target . implode(DIRECTORY_SEPARATOR, $dir) . DIRECTORY_SEPARATOR;
         if (!is_dir($dir)) {
             $ok = @mkdir($dir, 0777, true);
             if (!$ok) {
                 $msg = "Could not create dir {$dir}";
                 fwrite(STDERR, $msg);
                 exit(3);
             }
         }
         $content = '<?php // @see http://knotwerk.com' . EOL . '      // @version SVN: ' . $v . EOL . $php->getInline();
         $ok = @file_put_contents($dir . $file, $content, FILE_TEXT);
         if (!$ok) {
             $msg = "Could not write to file {$dir}{$file}";
Example #6
0
 /**
  * Get the template filters.
  *
  * @return T_Template_Helper_Filter[]
  */
 function getFilters()
 {
     $filter = array();
     foreach ($this->_helpers as $h) {
         // a helper can be a filter if it is a closure in itself
         // (via PHP5.3 __invoke()) or an array with first element
         // as an instance of filter.
         if (is_array($h)) {
             $h = _first($h);
         }
         if ($h instanceof T_Template_Helper_Filter) {
             $filter[] = $h;
         }
     }
     return $filter;
 }
Example #7
0
 protected function getBasicName()
 {
     return _first(explode('.', basename($this->basic)));
 }
Example #8
0
 function testFirstArrayMemberShortcut()
 {
     $this->assertSame(false, _first(array()));
     $this->assertSame('test', _first(array('test')));
     $this->assertSame('test', _first(array('test', 'more', 'members')));
 }