Beispiel #1
0
 /**
  * Add a measurable class
  *
  * @param  lang.XPClass $class
  * @param  lang.reflect.Method $method
  * @param  var $source
  * @return util.data.Sequence
  */
 private function permutationOf($class, $method, $source)
 {
     if (is_array($source)) {
         $seq = Sequence::of($source);
     } else {
         $seq = Sequence::of($class->getMethod($source)->setAccessible(true)->invoke(null));
     }
     return $seq->map(function ($args) use($class, $method) {
         return $class->newInstance($method, (array) $args);
     });
 }
Beispiel #2
0
 /**
  * Shuts down server
  *
  * @param  lang.XPClass $c
  * @return void
  */
 public function afterTestClass(\lang\XPClass $c)
 {
     // Tell the server to shut down
     try {
         $c->getMethod($this->shutdown)->invoke(null, []);
     } catch (\lang\Throwable $ignored) {
         // Fall through, below should terminate the process anyway
     }
     $status = $this->serverProcess->out->readLine();
     if (!strlen($status) || '+' != $status[0]) {
         while ($l = $this->serverProcess->out->readLine()) {
             $status .= $l;
         }
         while ($l = $this->serverProcess->err->readLine()) {
             $status .= $l;
         }
         $this->serverProcess->close();
         throw new IllegalStateException($status);
     }
     $this->serverProcess->close();
 }
 /**
  * Entry point: Invoke staticTarget method
  *
  * @param   lang.XPClass
  * @return  string
  */
 public static function invokeStatic(\lang\XPClass $class)
 {
     return $class->getMethod('staticTarget')->invoke(null);
 }
 /**
  * Returns values
  *
  * @param  unittest.TestCase test
  * @param  var annotation
  * @return var values a traversable structure
  */
 protected function valuesFor($test, $annotation)
 {
     if (!is_array($annotation)) {
         // values("source")
         $source = $annotation;
         $args = [];
     } else {
         if (isset($annotation['source'])) {
             // values(source= "src" [, args= ...])
             $source = $annotation['source'];
             $args = isset($annotation['args']) ? $annotation['args'] : [];
         } else {
             // values([1, 2, 3])
             return $annotation;
         }
     }
     // Route "ClassName::methodName" -> static method of the given class,
     // "self::method" -> static method of the test class, and "method"
     // -> the run test's instance method
     if (false === ($p = strpos($source, '::'))) {
         return $test->getClass()->getMethod($source)->setAccessible(true)->invoke($test, $args);
     }
     $ref = substr($source, 0, $p);
     if ('self' === $ref) {
         $class = $test->getClass();
     } else {
         if (strstr($ref, '.')) {
             $class = XPClass::forName($ref);
         } else {
             $class = new XPClass($ref);
         }
     }
     return $class->getMethod(substr($source, $p + 2))->invoke(null, $args);
 }