X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Fclient029.phpt;fp=tests%2Fclient029.phpt;h=2ed6d7934c36773a9fdbcd2d635bb4ab84970289;hb=e8ff1c1db343e8862ff436381a9b6ba01a60a4fa;hp=0000000000000000000000000000000000000000;hpb=42f0deb424dd6348d91d09120f015844d832afd6;p=m6w6%2Fext-http diff --git a/tests/client029.phpt b/tests/client029.phpt new file mode 100644 index 0000000..2ed6d79 --- /dev/null +++ b/tests/client029.phpt @@ -0,0 +1,124 @@ +--TEST-- +client curl user handler +--SKIPIF-- + +--FILE-- +client = $client; + } + + function init(callable $run) { + $this->run = $run; + } + + function timer($timeout_ms) { + echo "T"; + if (isset($this->timeout)) { + $this->timeout->set($timeout_ms/1000, 0); + $this->timeout->start(); + } else { + $this->timeout = new EvTimer($timeout_ms/1000, 0, function() { + if (!call_user_func($this->run, $this->client)) { + if ($this->timeout) { + $this->timeout->stop(); + $this->timeout = null; + } + } + }); + } + } + + function socket($socket, $action) { + echo "S"; + + switch ($action) { + case self::POLL_NONE: + break; + case self::POLL_REMOVE: + if (isset($this->ios[(int) $socket])) { + echo "U"; + $this->ios[(int) $socket]->stop(); + unset($this->ios[(int) $socket]); + } + break; + + default: + $ev = 0; + if ($action & self::POLL_IN) { + $ev |= Ev::READ; + } + if ($action & self::POLL_OUT) { + $ev |= Ev::WRITE; + } + if (isset($this->ios[(int) $socket])) { + $this->ios[(int) $socket]->set($socket, $ev); + } else { + $this->ios[(int) $socket] = new EvIo($socket, $ev, function($watcher, $events) use($socket) { + $action = 0; + if ($events & Ev::READ) { + $action |= self::POLL_IN; + } + if ($events & Ev::WRITE) { + $action |= self::POLL_OUT; + } + if (!call_user_func($this->run, $this->client, $socket, $action)) { + if ($this->timeout) { + $this->timeout->stop(); + $this->timeout = null; + } + } + }); + } + break; + } + } + + function once() { + throw new BadMethodCallException("this test uses Ev::run()"); + } + + function wait($timeout_ms = null) { + throw new BadMethodCallException("this test uses Ev::run()"); + } + + function send() { + throw new BadMethodCallException("this test uses Ev::run()"); + } +} + + +include "helper/server.inc"; + +server("proxy.inc", function($port) { + $client = new http\Client; + $client->configure([ + "use_eventloop" => new UserHandler($client) + ]); + $client->enqueue(new http\Client\Request("GET", "http://localhost:$port/"), function($r) { + var_dump($r->getResponseCode()); + }); + Ev::run(); +}); + +?> +===DONE=== +--EXPECTREGEX-- +Test +T[ST]+U+int\(200\) +===DONE===