diff --git a/.travis.yml b/.travis.yml index 57c029c..f54b8f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,30 +1,37 @@ language: php -sudo: false - cache: directories: - $HOME/.composer/cache/files -php: [5.3, 5.4, 5.5, 5.6, 7.0, 7.1, hhvm] +php: [5.6, 7.0, 7.1, 7.2, 7.3, 7.4] env: global: - NODE_VERSION='' - - ZOMBIE_VERSION='@^3.0' # npm will install Zombie 4.x by default, even though it is not compatible with the version of node available on Travis. - # Force using PHP 5.6 for the webserver to be able to run it on PHP 5.3 and HHVM jobs too - - MINK_PHP_BIN=~/.phpenv/versions/5.6/bin/php + - ZOMBIE_VERSION='' # Force binding to IPv4 as Zombie and PHP seem to have a different resolution for localhost on Travis. - MINK_HOST=127.0.0.1:8002 matrix: include: - - php: 5.6 - env: ZOMBIE_VERSION='@^2.0' + - php: 5.4 + dist: trusty + - php: 5.5 + dist: trusty + - php: 5.3 + dist: precise + env: + - MINK_PHP_BIN=~/.phpenv/versions/5.6/bin/php + - NODE_VERSION='8.12.0' - php: 5.6 env: - NODE_VERSION='5.4.1' - ZOMBIE_VERSION='@^4.0' + - php: 5.6 + env: + - NODE_VERSION='6.17.1' + - ZOMBIE_VERSION='@^5.0' before_install: - if [[ "$NODE_VERSION" != "" ]]; then wget https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz && tar xf node-v${NODE_VERSION}-linux-x64.tar.xz && export PATH="`pwd`/node-v${NODE_VERSION}-linux-x64/bin:$PATH"; fi @@ -40,8 +47,7 @@ before_script: # Start a webserver for web fixtures. - vendor/bin/mink-test-server > /dev/null 2>&1 & -script: phpunit -v --coverage-clover=coverage.clover +script: vendor/bin/phpunit -v --coverage-clover=coverage.clover after_script: - # XDebug is not yet available on PHP 7.1 so we don't have code coverage there. Not uploading it avoids telling Scrutinizer that it is missing - - if [[ "$TRAVIS_PHP_VERSION" != "7.1" ]]; then wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi + - wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.clover diff --git a/src/NodeJS/Server.php b/src/NodeJS/Server.php index 5085710..46b3715 100644 --- a/src/NodeJS/Server.php +++ b/src/NodeJS/Server.php @@ -10,7 +10,6 @@ namespace Behat\Mink\Driver\NodeJS; -use Symfony\Component\Process\ProcessBuilder; use Symfony\Component\Process\Process; /** @@ -344,24 +343,46 @@ public function start(Process $process = null) )); } - // Create process object if neccessary + // Create process object if necessary if (null === $process) { - $processBuilder = new ProcessBuilder(array( - $this->nodeBin, - $this->serverPath, - )); - $processBuilder->setEnv('HOST', $this->host) - ->setEnv('PORT', $this->port); + $env = array( + 'HOST' => $this->host, + 'PORT' => $this->port, + ); if (!empty($this->nodeModulesPath)) { - $processBuilder->setEnv('NODE_PATH', $this->nodeModulesPath); + $env['NODE_PATH'] = $this->nodeModulesPath; } if (!empty($this->options)) { - $processBuilder->setEnv('OPTIONS', json_encode($this->options)); + $env['OPTIONS'] = json_encode($this->options); } - $process = $processBuilder->getProcess(); + $arguments = array($this->nodeBin, $this->serverPath); + + if (\method_exists('Symfony\Component\Process\Process', 'escapeArgument')) { + // This is preferred way. + $commandLine = $arguments; + } else { + // This behavior is deprecated since Symfony 4.2. + $commandLine = implode( + ' ', + array_map(array('Symfony\Component\Process\ProcessUtils', 'escapeArgument'), $arguments) + ); + + // Replace environment inheritance as was done by ProcessBuilder. + $env = array_replace($_ENV, $_SERVER, $env); + } + + $process = new Process($commandLine, null, $env); + // to preserve the BC with symfony <3.3, we convert the array structure + // to a string structure to avoid the prefixing with the exec command + $process->setCommandLine($process->getCommandLine()); + + // Method was added in Symfony 3.2 and will be removed in Symfony 5. + if (\method_exists($process, 'inheritEnvironmentVariables')) { + $process->inheritEnvironmentVariables(); + } } $this->process = $process; diff --git a/src/ZombieDriver.php b/src/ZombieDriver.php index d4ddfa2..058ebec 100644 --- a/src/ZombieDriver.php +++ b/src/ZombieDriver.php @@ -483,7 +483,7 @@ public function getValue($xpath) if (idx >= 0) { value = node.options.item(idx).value; } else { - value = null; + value = ''; } } } else { @@ -570,6 +570,9 @@ public function setValue($xpath, $value) throw new Error('The radio group "' + name + '" does not have an option "' + value + '"'); } } +} +else if (type == 'file') { + browser.attach(node, value); } else { browser.fill(node, value); } @@ -918,7 +921,9 @@ protected function triggerKeyEvent($name, $xpath, $char, $modifier) e.altKey = {$isAltKeyArg}; e.shiftKey = {$isShiftKeyArg}; e.metaKey = {$isMetaKeyArg}; -e.keyCode = {$char}; +e.charCode = {$char}; +e.keyCode = {$char}; // deprecated. +e.which = {$char}; // deprecated. node.dispatchEvent(e); stream.end(); JS; diff --git a/tests/Custom/InstantiationTest.php b/tests/Custom/InstantiationTest.php index 5201c22..13d3a97 100644 --- a/tests/Custom/InstantiationTest.php +++ b/tests/Custom/InstantiationTest.php @@ -3,8 +3,9 @@ namespace Behat\Mink\Tests\Driver\Custom; use Behat\Mink\Driver\ZombieDriver; +use PHPUnit\Framework\TestCase; -class InstantiationTest extends \PHPUnit_Framework_TestCase +class InstantiationTest extends TestCase { public function testInstantiateWithServer() { diff --git a/tests/Custom/NodeJS/ServerTest.php b/tests/Custom/NodeJS/ServerTest.php index e4d112b..d84676d 100644 --- a/tests/Custom/NodeJS/ServerTest.php +++ b/tests/Custom/NodeJS/ServerTest.php @@ -4,6 +4,7 @@ use Behat\Mink\Driver\NodeJS\Connection; use Behat\Mink\Driver\NodeJS\Server as BaseServer; +use PHPUnit\Framework\TestCase; class TestServer extends BaseServer { @@ -47,7 +48,7 @@ protected function getServerScript() } } -class ServerTest extends \PHPUnit_Framework_TestCase +class ServerTest extends TestCase { public function testCreateServerWithDefaults() {