Local simpletest drupalGet() always gives "returned 0 (0 bytes)" I want to run tests locally with simpletest module.

I tried this with the cli scripts/run-tests.sh, and also in the admin UI.
I tried different tests shipped with Drupal 7 core, such as the ContactSitewideTestCase test.

Whenever a test wants to make a http request with $this->drupalGet(), the test reports a fail saying e.g. "GET http://d7git.localhost/user returned 0 (0 bytes)."

I think to remember that something needs to be configured for simpletest to make http requests. But I cannot remember what it is, and cannot find documentation that would explain it.
This error means that your test cannot reach your website.

I had a similar issue using something based on docker for drupal. For me the solution or hack the hosts file on the php container and change to point the domain you want to test to to the ip of the proxy server, in my case traeffik.

So in my host file I had something like this:

172.18.0.5      domain.internal

once that is done you can use curl to test the connection:

curl -v domain.internal

In my case I had an issue with a self signed certificate.


Rebuilt URL to: https://domain.internal/
Trying 172.18.0.5...
TCP_NODELAY set
Connected to domain.internal (172.18.0.5) port 443 (#0)
ALPN, offering http/1.1
successfully set certificate verify locations:
CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: none
TLSv1.2 (OUT), TLS handshake, Client hello (1):
TLSv1.2 (IN), TLS handshake, Server hello (2):
TLSv1.2 (IN), TLS handshake, Certificate (11):
TLSv1.2 (OUT), TLS alert, Server hello (2):
SSL certificate problem: self signed certificate
Closing connection 0
curl: (60) SSL certificate problem: self signed certificate
More details here: https://curl.haxx.se/docs/sslcerts.html


curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

However this should allow you to run your simpletest(s) in your browser.

Ideally there should be a way to configure this in your docker-compose file but I am not sure how?