This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Fixes issue #18

Derp.
  • Loading branch information...
1 parent 4ffae22 commit b6b3c402dbab8a234cd685876d2565365d1b0ea8 @b00giZm b00giZm committed Oct 15, 2012
Showing with 55 additions and 2 deletions.
  1. +2 −1 src/Behat/Mink/Driver/NodeJS/Server.php
  2. +53 −1 tests/Behat/Mink/Driver/NodeJS/ServerTest.php
@@ -88,14 +88,14 @@ public function __construct(
$this->host = $host;
$this->port = intval($port);
$this->nodeBin = $nodeBin;
+ $this->nodeModulesPath = $nodeModulesPath;
if (null === $serverPath) {
$serverPath = $this->createTemporaryServer();
}
$this->serverPath = $serverPath;
$this->threshold = intval($threshold);
- $this->nodeModulesPath = $nodeModulesPath;
$this->process = null;
$this->connection = null;
}
@@ -183,6 +183,7 @@ public function setNodeModulesPath($nodeModulesPath)
));
}
$this->nodeModulesPath = $nodeModulesPath;
+ $this->serverPath = $this->createTemporaryServer();
}
/**
@@ -7,18 +7,30 @@
class TestServer extends BaseServer
{
+ public $serverScript = null;
+
protected function doEvalJS(Connection $conn, $str, $returnType = 'js')
{
return '';
}
protected function getServerScript()
{
- return '';
+ return <<<JS
+var zombie = require('%modules_path%zombie')
+ , host = '%host%'
+ , port = %port%;
+JS;
}
protected function createTemporaryServer()
{
+ $this->serverScript = strtr($this->getServerScript(), array(
+ '%host%' => $this->host,
+ '%port%' => $this->port,
+ '%modules_path%' => $this->nodeModulesPath,
+ ));
+
return '/path/to/server';
}
}
@@ -35,6 +47,39 @@ public function testCreateServerWithDefaults()
$this->assertEquals('/path/to/server', $server->getServerPath());
$this->assertEquals(2000000, $server->getThreshold());
$this->assertEquals('', $server->getNodeModulesPath());
+
+ $expected = <<<JS
+var zombie = require('zombie')
+ , host = '127.0.0.1'
+ , port = 8124;
+JS;
+ $this->assertEquals($expected, $server->serverScript);
+ }
+
+ public function testCreateCustomServer()
+ {
+ $server = new TestServer(
+ '123.123.123.123',
+ 1234,
+ null,
+ null,
+ 5000000,
+ '../../'
+ );
+
+ $this->assertEquals('123.123.123.123', $server->getHost());
+ $this->assertEquals(1234, $server->getPort());
+ $this->assertEquals('node', $server->getNodeBin());
+ $this->assertEquals('/path/to/server', $server->getServerPath());
+ $this->assertEquals(5000000, $server->getThreshold());
+ $this->assertEquals('../../', $server->getNodeModulesPath());
+
+ $expected = <<<JS
+var zombie = require('../../zombie')
+ , host = '123.123.123.123'
+ , port = 1234;
+JS;
+ $this->assertEquals($expected, $server->serverScript);
}
public function testSetNodeModulesPath()
@@ -43,6 +88,13 @@ public function testSetNodeModulesPath()
$server->setNodeModulesPath('../../');
$this->assertEquals('../../', $server->getNodeModulesPath());
+
+ $expected = <<<JS
+var zombie = require('../../zombie')
+ , host = '127.0.0.1'
+ , port = 8124;
+JS;
+ $this->assertEquals($expected, $server->serverScript);
}
/**

0 comments on commit b6b3c40

Please sign in to comment.