-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
578 additions
and
602 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,46 @@ | ||
<?php namespace web\unittest; | ||
|
||
use lang\{Runtime, XPClass}; | ||
use lang\{Runtime, IllegalStateException}; | ||
use peer\Socket; | ||
use unittest\{PrerequisitesNotMetError, Test, TestAction, TestClassAction}; | ||
use test\Provider; | ||
use test\execution\Context; | ||
|
||
class StartServer implements TestAction, TestClassAction { | ||
private $server, $connected, $process, $client; | ||
class StartServer implements Provider { | ||
private $server; | ||
private $process= null; | ||
public $connection= null; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param string $server Server process main class | ||
* @param string $connected Name of connection callback | ||
*/ | ||
public function __construct($server, $connected) { | ||
$this->server= $server; | ||
$this->connected= $connected; | ||
public function __construct($server) { | ||
$this->server= strtr($server, '\\', '.'); | ||
} | ||
|
||
/** | ||
* Starts server | ||
* | ||
* @param lang.XPClass $c | ||
* @return void | ||
* @throws unittest.PrerequisitesNotMetError | ||
*/ | ||
public function beforeTestClass(XPClass $c) { | ||
public function values(Context $context): iterable { | ||
$this->process= Runtime::getInstance()->newInstance(null, 'class', $this->server, []); | ||
$this->process->in->close(); | ||
|
||
// Check if startup succeeded | ||
$status= $this->process->out->readLine(); | ||
if (2 !== sscanf($status, '+ Service %[0-9.]:%d', $host, $port)) { | ||
$this->afterTestClass($c); | ||
throw new PrerequisitesNotMetError('Cannot start server: '.$status, null); | ||
$this->shutdown(); | ||
throw new IllegalStateException('Cannot start server: '.$status, null); | ||
} | ||
|
||
$this->client= new Socket($host, $port); | ||
$c->getMethod($this->connected)->invoke(null, [$this->client]); | ||
$this->connection= new Socket($host, $port); | ||
yield $this; | ||
} | ||
|
||
/** | ||
* This method gets invoked before a test method is invoked, and before | ||
* the setUp() method is called. | ||
* | ||
* @param unittest.Test $t | ||
* @return void | ||
* @throws unittest.PrerequisitesNotMetError | ||
*/ | ||
public function beforeTest(Test $t) { | ||
$this->client->connect(); | ||
} | ||
/** @return void */ | ||
public function shutdown() { | ||
if (null === $this->process) return; | ||
|
||
/** | ||
* This method gets invoked after the test method is invoked and regard- | ||
* less of its outcome, after the tearDown() call has run. | ||
* | ||
* @param unittest.Test $t | ||
* @return void | ||
*/ | ||
public function afterTest(Test $t) { | ||
$this->client->close(); | ||
} | ||
|
||
/** | ||
* Shuts down server | ||
* | ||
* @param lang.XPClass $c | ||
* @return void | ||
*/ | ||
public function afterTestClass(XPClass $c) { | ||
$this->process->err->close(); | ||
$this->process->out->close(); | ||
$this->process->terminate(); | ||
$this->process= null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.