public function setCache() { $this->xmlParser = new XmlProcessor(); $this->xmlDocument = $this->xmlParser->parse(Stream::getContents("http://localhost/game/gamedata/furnidata.xml")); $iterator = $this->xmlDocument->findAll("/furnidata/roomitemtypes/furnitype"); while ($current = $iterator->current()) { $node = $current->toModel(); $this->floorItems[$node['@classname']] = new FurnidataItem((int) $node['@id'], $node['name'], (int) $node['xdim'], (int) $node['ydim'], $node['cansiton'] == "1", $node['canstandon'] == "1"); $iterator->next(); } $iterator = $this->xmlDocument->findAll("/furnidata/wallitemtypes/furnitype"); while ($current = $iterator->current()) { $node = $current->toModel(); $this->wallItems[$node['@classname']] = new FurnidataItem((int) $node['@id'], $node['name']); $iterator->next(); } }
--TEST-- Test php\lang\Module - test include with variables --FILE-- <?php use php\io\Stream; use php\lang\Module; $module = new Module(Stream::of('res://resources/ext/standard/module/basic_003.inc.php')); $foo = 'fail'; $bar = 'fail'; $undefined = 'fail'; $module->call(['foo' => 'success_foo', 'bar' => 'success_bar']); ?> --EXPECT-- string(11) "success_foo" string(11) "success_bar" NULL
--TEST-- Jsoup test #2 --FILE-- <?php use php\io\Stream; use php\jsoup\Jsoup; $source = Stream::of('php://memory', 'w+'); $source->write('<a>foobar</a>'); $source->seek(0); $doc = Jsoup::parse($source, 'UTF-8', 'examle.com'); var_dump($doc->select('a')->text()); ?> --EXPECT-- string(6) "foobar"
/** * Returns the input stream connected to the error output of the * subprocess. The stream obtains data piped from the error output * of the process represented by this `Process` object. * * @return Stream * @throws IllegalStateException */ public function getError() { return Stream::of(''); }
--TEST-- Test basic #1 --FILE-- <?php use php\io\Stream; use php\net\ServerSocket; use php\webserver\WebServer; $server = new WebServer(function () { echo "Hello World"; }); $server->port = ServerSocket::findAvailableLocalPort(); $server->run(); var_dump(Stream::getContents('http://localhost:' . $server->port)); ?> --EXPECTF-- string(11) "Hello World"
--TEST-- Test response --FILE-- <?php use php\io\Stream; use php\net\ServerSocket; use php\webserver\WebServer; class Foobar { } spl_autoload_register(function ($class) { var_dump($class); }); $server = new WebServer(function () { try { new Foobar(); } catch (EngineException $e) { echo $e->getMessage(); } }); $server->importAutoloaders = true; $server->port = ServerSocket::findAvailableLocalPort(); $server->run(); $conn = null; echo Stream::getContents("http://localhost:{$server->port}/"); ?> --EXPECT-- string(6) "Foobar" Class 'Foobar' not found
/** * @return Stream */ public function getContent() { return Stream::of(''); }
--TEST-- Test basic #2 --FILE-- <?php use php\io\Stream; use php\net\ServerSocket; use php\webserver\WebRequest; use php\webserver\WebResponse; use php\webserver\WebServer; $port = ServerSocket::findAvailableLocalPort(); $server = new WebServer(function (WebRequest $request, WebResponse $response) use($port) { var_dump($request === WebRequest::current()); var_dump($response === WebResponse::current()); var_dump($request->method); var_dump($request->queryString); var_dump($request->url === "http://localhost:{$port}/foobar/"); var_dump($request->port == $port); }); $server->port = $port; $server->run(); echo Stream::getContents('http://localhost:' . $server->port . '/foobar/?foobar=123'); ?> --EXPECTF-- bool(true) bool(true) string(3) "GET" string(10) "foobar=123" bool(true) bool(true)
--TEST-- Test php\io\Stream - test file stream --FILE-- <?php use php\io\FileStream; use php\io\Stream; $memory = Stream::of(__DIR__ . '/stream_002.inc.txt'); var_dump($memory->readFully()); $memory->close(); var_dump(Stream::getContents(__DIR__ . '/stream_002.inc.txt')); $memory = Stream::of('file://' . __DIR__ . '/stream_002.inc.txt'); var_dump($memory->read(3)); $memory->close(); $memory = new FileStream(__DIR__ . '/stream_002.inc.txt'); var_dump($memory->readFully()); $memory->close(); try { $memory->read(10); } catch (\php\io\IOException $e) { var_dump($e->getMessage()); } ?> --EXPECTF-- string(6) "foobar" string(6) "foobar" string(3) "foo" string(6) "foobar" string(13) "Stream Closed"
--TEST-- Test php\io\Stream - test common --FILE-- <?php use php\io\Stream; $memory = Stream::of('php://memory', 'w+'); $memory->write('foobar'); $memory->seek(0); var_dump($memory->readFully()); ?> --EXPECTF-- string(6) "foobar"