/** * Creates a new terminal instance. * * It sets $_SERVER['TERM'] with the value of ``$global`` parameter, then * resolves a terminfo file name from the terminal name and creates terminfo * files accordingly. * * Finally, it creates a new Terminal instance. * * @param string $global The value for $_SERVER['TERM'], defaults to * 'xterm-256color'. * @param string $tty The tty name. * @param string $term The terminal name, defaults to 'xterm-256color'. * @param string $termFile The terminfo file name. * @return Terminfo The terminfo instance. * @see getTermFileForTerm() * @see setupTerminfoFiles() */ public static function getTerminalInstance($global = 'xterm-256color', $tty = null, $term = 'xterm-256color', $termFile = 'xterm-256color') { $_SERVER['TERM'] = $global; // $termFile = TerminfoTestUtil::getTermFileForTerm($term); TerminfoTestUtil::setupTerminfoFiles($termFile); return Terminal::instance($tty, $term); }
/** * @dataProvider getGlobalTermAndTermAndTermFile * @depends testGetDefaultTerm */ public function testGetTerminfoPath($global, $term, $termFile) { $_SERVER['TERM'] = $global; $hexa = dechex(ord($termFile[0])); $alpha = $termFile[0]; $protocol = 'vfs'; $base = 'root'; $root = "{$protocol}://{$base}"; // Creates terminfo files. TerminfoTestUtil::setupTerminfoFiles($termFile, $root); // Sets up global variables. $_SERVER['TERMINFO'] = '/terminfo'; $_SERVER['HOME'] = '/home'; $_SERVER['TERMINFO_DIRS'] = '/terminfo-dirs/dir1:/terminfo-dirs/dir2'; // Tests terminfo file in all possible locations one by one. foreach (TerminfoTestUtil::$terminfoPaths as $i => $path) { $hexaPath = $base . TerminfoTestUtil::$terminfoPaths[$i] . '/' . $hexa . '/' . $termFile; $alphaPath = $base . TerminfoTestUtil::$terminfoPaths[$i] . '/' . $alpha . '/' . $termFile; $this->assertEquals(vfsStream::url($hexaPath), Terminfo::getTerminfoPath($term, $root)); unlink(vfsStream::url($hexaPath)); $this->assertEquals(vfsStream::url($alphaPath), Terminfo::getTerminfoPath($term, $root)); if (array_key_exists($i, TerminfoTestUtil::$terminfoVariableNames)) { unset($_SERVER[TerminfoTestUtil::$terminfoVariableNames[$i]]); $this->assertEquals(vfsStream::url($base . TerminfoTestUtil::$terminfoPaths[$i + 1] . '/' . $hexa . '/' . $termFile), Terminfo::getTerminfoPath($term, $root)); } unlink(vfsStream::url($alphaPath)); } }