public function get_contents_read_returns_less_than_size() { $f = new File(Streams::readableFd(newinstance(MemoryInputStream::class, ['Test'], ['read' => function ($size = 4096) { return parent::read(min(1, $size)); }]))); $this->assertEquals('Test', FileUtil::getContents($f)); }
/** @return lang.Object */ protected function hashCodeCounter() { return newinstance(Object::class, [], ['invoked' => 0, 'hashCode' => function () { $this->invoked++; return parent::hashCode(); }]); }
protected function newConnection(URL $url) { return newinstance(Connection::class, [$url], ['response' => '', 'sent' => null, 'in' => null, 'out' => null, '__construct' => function ($url) { parent::__construct($url); $this->_connect($url); // FIXME: Required for unittest }, '_connect' => function (URL $url) { $this->in = new StringReader(new MemoryInputStream($this->response)); $this->out = new StringWriter(new MemoryOutputStream()); }, '_disconnect' => function () { $this->sent = $this->out->getStream()->getBytes(); $this->in = null; $this->out = null; }, 'setResponseBytes' => function ($s) { $this->in = new StringReader(new MemoryInputStream($s)); $this->response = $s; }, 'readSentBytes' => function () { // Case of DISCONNECT if (null !== $this->sent) { $sent = $this->sent; $this->sent = null; return $sent; } return $this->out->getStream()->getBytes(); }, 'clearSentBytes' => function () { $this->_connect(new URL()); $this->sent = null; }]); }
/** * Add test result node, if it does not yet exist. * * @param unittest.TestCase case * @return xml.Node */ protected function testNode(TestCase $case) { $class = $case->getClass(); if (!$this->classes->containsKey($class)) { $this->classes[$class] = $this->tree->addChild(new \xml\Node('testsuite', null, ['name' => $class->getName(), 'file' => $this->uriFor($class), 'tests' => 0, 'failures' => 0, 'errors' => 0, 'skipped' => 0, 'time' => 0])); } return $this->classes[$class]; }
/** * Creates a new test * * @param string $name * @param string $input A path or a file */ public function __construct($name, $input) { parent::__construct($name); if (is_file($input)) { $this->input = [new FileElement($input)]; } else { $this->input = new FilteredIOCollectionIterator(new FileCollection($input), new NameEqualsFilter('uber.json'), true); } }
/** * Constructor * */ public function __construct($name, $url = null, $user = null, $pass = null) { parent::__construct($name); if (null !== $url) { $this->url = new URL($url); $this->url->setUser($user); $this->url->setPassword($pass); } }
/** * Returns a new FileBasedTemplateLoader instance * * @param var[] args constructor arguments * @return com.github.mustache.FileBasedTemplateLoader */ protected function newFixture($args) { return newinstance(FileBasedTemplateLoader::class, $args, ['askedFor' => [], 'variantsOf' => function ($name) { return array_merge(parent::variantsOf($name), ['test']); }, 'inputStreamFor' => function ($name) { if ('test' === $name) { return new MemoryInputStream('test'); } else { $this->askedFor[] = $name; return null; } }, 'entries' => function () { return function ($package) { if ('' === rtrim($package, '/')) { return ['test']; } else { return []; } }; }]); }
/** * Run a single test * * @param unittest.TestCase test * @return unittest.TestResult * @throws lang.IllegalArgumentException in case given argument is not a testcase * @throws lang.MethodNotImplementedException in case given argument is not a valid testcase */ public function runTest(TestCase $test) { $class = $test->getClass(); if (!$class->hasMethod($test->name)) { throw new MethodNotImplementedException('Test method does not exist', $test->name); } $this->notifyListeners('testRunStarted', [$this]); // Run the single test $result = new TestResult(); try { $this->beforeClass($class); $this->runInternal($test, $result); $this->afterClass($class); $this->notifyListeners('testRunFinished', [$this, $result, null]); } catch (PrerequisitesNotMetError $e) { $this->notifyListeners('testSkipped', [$result->setSkipped($test, $e, 0.0)]); } catch (StopTests $stop) { $this->notifyListeners('testRunFinished', [$this, $result, $stop]); } return $result; }
/** * Write status of currently executing test case * * @param unittest.TestCase case */ private function writeStatus(TestCase $case) { $this->cur++; $perc = floor($this->cur / $this->sum * self::PROGRESS_WIDTH); $this->out->writef("]2;Running: [%s%s] %s::%s()", str_repeat('*', $perc), str_repeat('-', self::PROGRESS_WIDTH - $perc), $case->getClassName(), $case->getName()); }
public function select_userdefined_emitter() { ClassLoader::defineClass('xp.compiler.emit.test.Emitter', 'xp.compiler.emit.php.V54Emitter', [], ['emit' => function (ParseTree $tree, Scope $scope) { Console::writeLine('Test emitter emitting...'); return parent::emit($tree, $scope); }]); $this->assertEquals("Test emitter emitting...\nTest\n", $this->run(['-E', 'test', '-w', 'xp', '"Test"'])['out']); }
/** * Constructor * * @param string $name * @param string $folder Folder with `test_parsing` inside */ public function __construct($name, $folder = '.') { parent::__construct($name); $this->parsing = new Folder($folder, 'test_parsing'); $this->transform = new Folder($folder, 'test_transform'); }
/** * Fail this test case * * @param string reason * @param var actual * @param var expect */ public function fail($reason, $actual, $expect) { parent::fail('@' . $this->conn->getUrl()->getURL() . ': ' . $reason, $actual, $expect); }
public function __construct($name, $host = null) { parent::__construct($name); $this->host = $host; }
/** * Runs before test * * @param unittest.TestCase $t * @return void */ public function beforeTest(TestCase $t) { if (self::runtime()) { $t->skip('This test is not intended to run on HHVM'); } }
/** * Constructor * @param string $name * @param string $target The directory in which the spec files exist */ public function __construct($name, $target = null) { parent::__construct($name); $this->target = $target; }
public function assertEquals() { parent::assertEquals($a, $b); \xp::gc(__FILE__); }
/** * After test: Update field * * @param unittest.TestCase $t */ public function afterTest(\unittest\TestCase $t) { $f = $t->getClass()->getField($this->field); $f->set($t, array_merge($f->get($t), array('after'))); }
/** * After test: Update field * * @param unittest.TestCase $t */ public function afterTest(TestCase $t) { $f = $t->getClass()->getField($this->field); $f->set($t, array_merge($f->get($t), ['after'])); }
/** * Fill conn and dialectClass members */ public function __construct($name) { parent::__construct($name); $this->conn[self::MYSQL] = new MySQLConnection(new \rdbms\DSN('mysql://localhost:3306/')); $this->conn[self::SYBASE] = new SybaseConnection(new \rdbms\DSN('sybase://localhost:1999/')); }