diff options
author | Florian Pritz <bluewind@xinu.at> | 2016-08-20 15:19:15 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2016-08-20 15:19:15 +0200 |
commit | 3ce4e928c606f2b3a1c393819ca4a1268e3b058b (patch) | |
tree | fbcbadbc18ced14be9bfb3f1b4b553eccda0ae33 /application/test/Test.php | |
parent | b7853a87ac0575f83793d5d6a7ed44849156e189 (diff) |
tests: Use one webserver per testcase
This allows the tests to run somewhat parallel (still limited by the
database) and simplifies running single testcases without the
./run-tests.sh wrapper.
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application/test/Test.php')
-rw-r--r-- | application/test/Test.php | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/application/test/Test.php b/application/test/Test.php index a0ebf880e..33278436b 100644 --- a/application/test/Test.php +++ b/application/test/Test.php @@ -25,8 +25,9 @@ class TestMore extends \TestMore { abstract class Test { protected $t; - protected $server = ""; + protected $server_url = ""; private $testid = ""; + private $server_proc = null; public function __construct() { @@ -34,9 +35,51 @@ abstract class Test { $this->t->plan("no_plan"); } - public function setServer($server) + public function __destruct() { - $this->server = $server; + if ($this->server_proc) { + proc_terminate($this->server_proc); + } + } + + public function startServer($port) + { + $url = "http://127.0.0.1:$port/index.php"; + + $pipes = []; + $descriptorspec = [ + 0 => ['file', '/dev/null', 'r'], + 1 => STDOUT, + 2 => STDOUT, + ]; + + $this->server_proc = proc_open("php -S 127.0.0.1:$port", $descriptorspec, $pipes); + + $this->wait_for_server($url); + $this->server_url = $url; + } + + private function wait_for_server($url) + { + while (!$this->url_is_reachable($url)) { + echo "Waiting for server at $url to start...\n"; + usleep(10000); + } + } + + private function url_is_reachable($url) + { + $handle = curl_init($url); + curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE); + curl_exec($handle); + $status = curl_getinfo($handle, CURLINFO_HTTP_CODE); + curl_close($handle); + + if ($status == 200) { + return true; + } + + return false; } public function setTestID($testid) |