Problem/Motivation

Currently if you try to run a test that extends JavascriptTestBase but do not have phantomjs running it will cause an error but not tell you need to have phantomjs running.

The error received is

PHPUnit_Framework_Exception: PHP Fatal error: Uncaught exception 'GuzzleHttp\Exception\ConnectException' with message 'cURL error 7: Failed to connect to 127.0.0.1 port 8510: Connection refused (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)' in /var/www/d8_2_ux/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:186
Stack trace:
#0 /var/www/d8_2_ux/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(150): GuzzleHttp\Handler\CurlFactory::createRejection(Object(GuzzleHttp\Handler\EasyHandle), Array)
#1 /var/www/d8_2_ux/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(103): GuzzleHttp\Handler\CurlFactory::finishError(Object(GuzzleHttp\Handler\CurlMultiHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory))
#2 /var/www/d8_2_ux/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(180): GuzzleHttp\Handler\CurlFactory::finish(Object(GuzzleHttp\Handler\CurlMultiHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory))
#3 /var/www/d8_2_ux/vendor/guzzlehttp/guzzle/src/Handler/CurlM in /var/www/d8_2_ux/vendor/jcalderonzumba/gastonjs/src/Browser/BrowserBase.php on line 93

This doesn't help the user to know that they need phantomjs running

Proposed resolution

Detect if phantomjs is running and if not print out a helpful message such as "Phantomjs is currently not running. It must be running to execute Javascript based tests."

Remaining tasks

Determine if it is possible.
Do it

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tedbow created an issue. See original summary.

dawehner’s picture

Component: simpletest.module » phpunit
Category: Feature request » Task
Issue tags: +DX (Developer Experience)

Let's improve that a bit.

cilefen’s picture

What a silly patch, but this is a possible place to catch it.

dawehner’s picture

So here is a question, why was the existing exception message not shown? Can we maybe convert the exception message to be more helpful?

cilefen’s picture

The actual exception that arrives at this place is Zumba\GastonJS\Exception\DeadClient.

cilefen’s picture

Something like this would seem to make sense:

use Zumba\GastonJS\Exception\DeadClient;

// ...

    try {
      $session->visit($this->baseUrl);
    }
    catch (DeadClient $exception) {
      $this->markTestSkipped($exception->getMessage());
    }

Although it does catch the exception, it doesn't actually work.

dawehner’s picture

What about using the following message:

'PhantomJS is probably not running. Ensure to install and start it, see README.md. Original message: $message
cilefen’s picture

The message can be whatever we like but #6 doesn't work, for maybe several reasons. One is that marking a test as skipped does not halt its execution. The other is that there is probably an exception handler.

dawehner’s picture

The message can be whatever we like but #6 doesn't work, for maybe several reasons. One is that marking a test as skipped does not halt its execution. The other is that there is probably an exception handler.

Well, but the message is still shown when you use --verbose, doesn't it?

cilefen’s picture

It does not.

$ ./vendor/bin/phpunit --verbose -c core core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php
PHPUnit 4.8.11 by Sebastian Bergmann and contributors.

Runtime:	PHP 5.6.21
Configuration:	/Users/cjm/Sites/drupal8x/core/phpunit.xml

E

Time: 6.21 seconds, Memory: 5.25Mb

There was 1 error:

1) Drupal\Tests\toolbar\FunctionalJavascript\ToolbarIntegrationTest::testToolbarToggling
PHPUnit_Framework_Exception: PHP Fatal error:  Uncaught exception 'GuzzleHttp\Exception\ConnectException' with message 'cURL error 7: Failed to connect to 127.0.0.1 port 8510: Connection refused (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)' in /Users/cjm/Sites/drupal8x/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:186
Stack trace:
#0 /Users/cjm/Sites/drupal8x/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(150): GuzzleHttp\Handler\CurlFactory::createRejection(Object(GuzzleHttp\Handler\EasyHandle), Array)
#1 /Users/cjm/Sites/drupal8x/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(103): GuzzleHttp\Handler\CurlFactory::finishError(Object(GuzzleHttp\Handler\CurlMultiHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory))
#2 /Users/cjm/Sites/drupal8x/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(180): GuzzleHttp\Handler\CurlFactory::finish(Object(GuzzleHttp\Handler\CurlMultiHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory))
#3 /Users/cjm/Sites/drupal in /Users/cjm/Sites/drupal8x/vendor/jcalderonzumba/gastonjs/src/Browser/BrowserBase.php on line 93

FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
jibran’s picture

Issue tags: +JavaScriptTest
albertski’s picture

I'm running into this same error.

I installed phantomjs. When I run 'phantomjs -v' I get '1.9.0' but I still get the same error. I'm using nginx.

albertski’s picture

Actually I'm seeing the same error on Apache.

cilefen’s picture

@albertski This issue is to fix the error message when phantomjs is not running properly. Did you start phantomjs this way?

/path/to/phantomjs --ssl-protocol=any --ignore-ssl-errors=true vendor/jcalderonzumba/gastonjs/src/Client/main.js 8510 1024 768

dawehner’s picture

@albertski Yeah I think phantomjs should be 2.0.x at least, otherwise there are problems with the underlying JS engine.

albertski’s picture

@cilefen Thanks that ended up working. To get it to work I had to:

1. ssh into server
2. Run command: phantomjs --ssl-protocol=any --ignore-ssl-errors=true vendor/jcalderonzumba/gastonjs/src/Client/main.js 8510 1024 768
3. Leave this running
4. Open new terminal window
5. ssh into server
6. Run phpunit test

Is there a way to run the command without having to keep running? So I don't have to open two separate connections.

@dawehner Thanks I updated to 2.0.x.

cilefen’s picture

phantomjs --ssl-protocol=any --ignore-ssl-errors=true vendor/jcalderonzumba/gastonjs/src/Client/main.js 8510 1024 768&

albertski’s picture

@cilefen: Thanks that worked great!

juampynr’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
71.41 KB
1.24 KB

Here I am marking the test to be skipped if phantomjs fails to start. Here is the output when I attempt to run a JavascriptTestBase test without PhantomJS running:

dawehner’s picture

+++ b/core/tests/Drupal/Tests/BrowserTestBase.php
@@ -431,7 +432,17 @@ protected function setUp() {
+    try {
+      $session = $this->initMink();
+    }
+    catch (DeadClient $e) {
+      $this->markTestSkipped('PhantomJS is either not installed or not running. Start it via phantomjs --ssl-protocol=any --ignore-ssl-errors=true vendor/jcalderonzumba/gastonjs/src/Client/main.js 8510 1024 768&');
+      return;
+    }

Could we catch that explictly in JavascriptTestBase instead?

juampynr’s picture

Sure, here it is.

Here is the output when I run a JavascriptTestBase test with PhantomJS not running and this patch applied:

juampy@Juampy/var/www/drupal8/core(8.2.x)$ sudo -u www-data ../vendor/bin/phpunit --debug --verbose tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxThemeTest.php
PHPUnit 4.8.26 by Sebastian Bergmann and contributors.

Runtime:	PHP 5.6.11-1ubuntu3.4 with Xdebug 2.3.3
Configuration:	/var/www/drupal8/core/phpunit.xml.dist


Starting test 'Drupal\FunctionalJavascriptTests\Ajax\AjaxThemeTest::testAjaxWithAdminRoute'.
S

Time: 16.32 seconds, Memory: 6.75MB

There was 1 skipped test:

1) Drupal\FunctionalJavascriptTests\Ajax\AjaxThemeTest::testAjaxWithAdminRoute
PhantomJS is either not installed or not running. Start it via phantomjs --ssl-protocol=any --ignore-ssl-errors=true vendor/jcalderonzumba/gastonjs/src/Client/main.js 8510 1024 768&

/var/www/drupal8/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php:39
/var/www/drupal8/core/tests/Drupal/Tests/BrowserTestBase.php:434

OK, but incomplete, skipped, or risky tests!
Tests: 1, Assertions: 1, Skipped: 1.
dawehner’s picture

+++ b/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php
@@ -30,7 +31,16 @@ protected function initMink() {
+    catch (Exception $e) {
+      $this->markTestSkipped('An unexpected error occurred while starting Mink: ' . $e->getMessage());
+    }

Well, do we want this catch in BrowserTestBase still?

juampynr’s picture

If we have it in BrowserTestBase, we would have to re-throw it so it bubbles up to JavascriptTestBase. Why would you prefer to do that? Shall we remove the Exception catch?

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Well the message in the catch all seems to be helpful for mink potentially as well, but I agree this is super nitpicky.

  • alexpott committed a1bc0a4 on 8.2.x
    Issue #2737781 by juampynr, cilefen, dawehner: Provide helpful message...

  • alexpott committed 25d27de on 8.1.x
    Issue #2737781 by juampynr, cilefen, dawehner: Provide helpful message...
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Helpful. Nice work. Committed 25d27de and pushed to 8.1.x and 8.2.x. Thanks!

  • alexpott committed a1bc0a4 on 8.3.x
    Issue #2737781 by juampynr, cilefen, dawehner: Provide helpful message...

  • alexpott committed a1bc0a4 on 8.3.x
    Issue #2737781 by juampynr, cilefen, dawehner: Provide helpful message...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.