From f2b63342dbd63a3f672208e87419f219d9bf1675 Mon Sep 17 00:00:00 2001 From: berliner Date: Fri, 9 Jun 2017 19:25:39 +0200 Subject: [PATCH 1/6] Add support for zombiejs options --- bin/mink-zombie-server.js | 3 ++- src/NodeJS/Server.php | 40 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/bin/mink-zombie-server.js b/bin/mink-zombie-server.js index 2a60bad..6eecdeb 100755 --- a/bin/mink-zombie-server.js +++ b/bin/mink-zombie-server.js @@ -6,6 +6,7 @@ var pointers = []; var buffer = ''; var host = process.env.HOST || '127.0.0.1'; var port = process.env.PORT || 8124; +var options = process.env.OPTIONS ? JSON.parse(process.env.OPTIONS) : {}; var zombieVersionCompare = function (v2, op) { var version_compare = function (v1, v2, operator) { @@ -108,7 +109,7 @@ net.createServer(function (stream) { stream.on('end', function () { if (browser == null) { - browser = new zombie(); + browser = new zombie(options); // Clean up old pointers pointers = []; diff --git a/src/NodeJS/Server.php b/src/NodeJS/Server.php index 8bd1881..ed518c9 100644 --- a/src/NodeJS/Server.php +++ b/src/NodeJS/Server.php @@ -45,6 +45,11 @@ abstract class Server */ protected $threshold; + /** + * @var array + */ + protected $options; + /** * @var string The full path to the NodeJS modules directory. */ @@ -69,6 +74,7 @@ abstract class Server * @param string $serverPath Path to server script * @param int $threshold Threshold value in micro seconds * @param string $nodeModulesPath Path to node_modules directory + * @param array $options Options array for zombiejs */ public function __construct( $host = '127.0.0.1', @@ -76,7 +82,8 @@ public function __construct( $nodeBin = null, $serverPath = null, $threshold = 2000000, - $nodeModulesPath = '' + $nodeModulesPath = '', + $options = array() ) { if (null === $nodeBin) { $nodeBin = 'node'; @@ -97,6 +104,7 @@ public function __construct( $this->setServerPath($serverPath); $this->setThreshold($threshold); + $this->setOptions($options); } /** @@ -273,6 +281,32 @@ public function getThreshold() return $this->threshold; } + /** + * Setter options value + * + * @param array $options Options array + * + * @throws \LogicException When server is already running. + */ + public function setOptions($options) + { + if ($this->isRunning()) { + throw new \LogicException('Unable to change options of a running server.'); + } + + $this->options = $options; + } + + /** + * Getter options value + * + * @return array Options array + */ + public function getOptions() + { + return $this->options; + } + /** * Getter process object * @@ -323,6 +357,10 @@ public function start(Process $process = null) $processBuilder->setEnv('NODE_PATH', $this->nodeModulesPath); } + if (!empty($this->options)) { + $processBuilder->setEnv('OPTIONS', json_encode($this->options)); + } + $process = $processBuilder->getProcess(); } $this->process = $process; From 147cc685090b731479367bd89150aaa1c78f0e18 Mon Sep 17 00:00:00 2001 From: berliner Date: Fri, 23 Jun 2017 17:06:47 +0200 Subject: [PATCH 2/6] Updated tests with asserts for zombie options --- tests/Custom/NodeJS/ServerTest.php | 36 +++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/tests/Custom/NodeJS/ServerTest.php b/tests/Custom/NodeJS/ServerTest.php index 07c63ab..e4d112b 100644 --- a/tests/Custom/NodeJS/ServerTest.php +++ b/tests/Custom/NodeJS/ServerTest.php @@ -17,9 +17,10 @@ protected function doEvalJS(Connection $conn, $str, $returnType = 'js') protected function getServerScript() { return <<assertEquals('/path/to/server', $server->getServerPath()); $this->assertEquals(2000000, $server->getThreshold()); $this->assertEquals('', $server->getNodeModulesPath()); + $this->assertEquals(array(), $server->getOptions()); $expected = <<assertEquals($expected, $server->serverScript); } @@ -90,7 +93,8 @@ public function testCreateCustomServer() null, null, 5000000, - '../../' + '../../', + array('waitDuration' => '15s') ); $this->assertEquals('123.123.123.123', $server->getHost()); @@ -99,11 +103,13 @@ public function testCreateCustomServer() $this->assertEquals('/path/to/server', $server->getServerPath()); $this->assertEquals(5000000, $server->getThreshold()); $this->assertEquals('../../', $server->getNodeModulesPath()); + $this->assertEquals(array('waitDuration' => '15s'), $server->getOptions()); $expected = <<assertEquals($expected, $server->serverScript); } @@ -158,6 +164,16 @@ public function testSetThresholdOnRunningServer() $server->setThreshold('test'); } + /** + * @expectedException \LogicException + * @expectedExceptionMessage Unable to change options of a running server. + */ + public function testSetOptionsOnRunningServer() + { + $server = $this->getRunningServer(); + $server->setOptions(array('waitDuration' => '15s')); + } + /** * @group legacy */ From 066669f834eecd69ac0519d5221cdb104f7cae6c Mon Sep 17 00:00:00 2001 From: berliner Date: Fri, 23 Jun 2017 17:20:35 +0200 Subject: [PATCH 3/6] Add argument validation and associated test for zombie options --- src/NodeJS/Server.php | 5 +++++ tests/Custom/NodeJS/ServerTest.php | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/NodeJS/Server.php b/src/NodeJS/Server.php index ed518c9..0ef3751 100644 --- a/src/NodeJS/Server.php +++ b/src/NodeJS/Server.php @@ -286,10 +286,15 @@ public function getThreshold() * * @param array $options Options array * + * @throws \InvalidArgumentException Invalid path is invalid. * @throws \LogicException When server is already running. */ public function setOptions($options) { + if (!is_array($options)) { + throw new \InvalidArgumentException("Options must be specified as an array."); + } + if ($this->isRunning()) { throw new \LogicException('Unable to change options of a running server.'); } diff --git a/tests/Custom/NodeJS/ServerTest.php b/tests/Custom/NodeJS/ServerTest.php index e4d112b..874d9d9 100644 --- a/tests/Custom/NodeJS/ServerTest.php +++ b/tests/Custom/NodeJS/ServerTest.php @@ -233,6 +233,16 @@ public function testSetNodeModulesPathOnRunningServer() $server->setNodeModulesPath('../../'); } + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Options must be specified as an array. + */ + public function testSetOptionsWithInvalidArgument() + { + $server = new TestServer(); + $server->setOptions('/invalid argument/'); + } + /** * @expectedException \InvalidArgumentException */ From d98cad74b9737b248a19d3e21df3b13d68ca1e41 Mon Sep 17 00:00:00 2001 From: berliner Date: Fri, 23 Jun 2017 17:25:15 +0200 Subject: [PATCH 4/6] Changed order of test functions --- tests/Custom/NodeJS/ServerTest.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/Custom/NodeJS/ServerTest.php b/tests/Custom/NodeJS/ServerTest.php index 874d9d9..23d26ad 100644 --- a/tests/Custom/NodeJS/ServerTest.php +++ b/tests/Custom/NodeJS/ServerTest.php @@ -174,6 +174,16 @@ public function testSetOptionsOnRunningServer() $server->setOptions(array('waitDuration' => '15s')); } + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Options must be specified as an array. + */ + public function testSetOptionsWithInvalidArgument() + { + $server = new TestServer(); + $server->setOptions('/invalid argument/'); + } + /** * @group legacy */ @@ -233,16 +243,6 @@ public function testSetNodeModulesPathOnRunningServer() $server->setNodeModulesPath('../../'); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Options must be specified as an array. - */ - public function testSetOptionsWithInvalidArgument() - { - $server = new TestServer(); - $server->setOptions('/invalid argument/'); - } - /** * @expectedException \InvalidArgumentException */ From 44c9adf8dce46ec8ad0bb5a54eae49ff97182b19 Mon Sep 17 00:00:00 2001 From: berliner Date: Fri, 23 Jun 2017 17:55:27 +0200 Subject: [PATCH 5/6] Use type hint instead of checking options argument, remove test case --- src/NodeJS/Server.php | 7 +------ tests/Custom/NodeJS/ServerTest.php | 10 ---------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/src/NodeJS/Server.php b/src/NodeJS/Server.php index 0ef3751..7e2d935 100644 --- a/src/NodeJS/Server.php +++ b/src/NodeJS/Server.php @@ -286,15 +286,10 @@ public function getThreshold() * * @param array $options Options array * - * @throws \InvalidArgumentException Invalid path is invalid. * @throws \LogicException When server is already running. */ - public function setOptions($options) + public function setOptions(array $options) { - if (!is_array($options)) { - throw new \InvalidArgumentException("Options must be specified as an array."); - } - if ($this->isRunning()) { throw new \LogicException('Unable to change options of a running server.'); } diff --git a/tests/Custom/NodeJS/ServerTest.php b/tests/Custom/NodeJS/ServerTest.php index 23d26ad..e4d112b 100644 --- a/tests/Custom/NodeJS/ServerTest.php +++ b/tests/Custom/NodeJS/ServerTest.php @@ -174,16 +174,6 @@ public function testSetOptionsOnRunningServer() $server->setOptions(array('waitDuration' => '15s')); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Options must be specified as an array. - */ - public function testSetOptionsWithInvalidArgument() - { - $server = new TestServer(); - $server->setOptions('/invalid argument/'); - } - /** * @group legacy */ From 6d6bf10ead670a80811c946e92467d8fb63ddd35 Mon Sep 17 00:00:00 2001 From: berliner Date: Tue, 18 Jul 2017 15:21:51 +0200 Subject: [PATCH 6/6] Change visibility of member variable --- src/NodeJS/Server.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NodeJS/Server.php b/src/NodeJS/Server.php index 7e2d935..5085710 100644 --- a/src/NodeJS/Server.php +++ b/src/NodeJS/Server.php @@ -48,7 +48,7 @@ abstract class Server /** * @var array */ - protected $options; + private $options; /** * @var string The full path to the NodeJS modules directory.