Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Fixes issue minkphp#18
Browse files Browse the repository at this point in the history
Derp.
  • Loading branch information
b00gizm committed Oct 15, 2012
1 parent 4ffae22 commit b6b3c40
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Behat/Mink/Driver/NodeJS/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -183,6 +183,7 @@ public function setNodeModulesPath($nodeModulesPath)
));
}
$this->nodeModulesPath = $nodeModulesPath;
$this->serverPath = $this->createTemporaryServer();
}

/**
Expand Down
54 changes: 53 additions & 1 deletion tests/Behat/Mink/Driver/NodeJS/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
Expand All @@ -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()
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit b6b3c40

Please sign in to comment.