Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lukasoppermann's avatar

Testing API Calls on travis

Hey,

I am trying to do functional testing. It works perfectly fine locally, my setup is like this:

  • phpunit
  • guzzle

In the test I do calls via guzzle and check the results. All fine.

However on travis I can not get it to work. I tried using and ENV variable TEST_BASE_URL to set the url (api.test.app) for my local test works fine, but with http://localhost on travis or http://localhost:8000 it get a curl error

 (7) cannot connect to host exception.

Okay, I got this one working. Now guzzle gives me a 500 error. Could it be that the lumen routing does not work, because the httaccess file does not work on travis?

0 likes
5 replies
Corez64's avatar

Travis doesn't support a web browser without you telling it to start one. Without you telling me more about how you are trying to run your tests I can't really help you.

lukasoppermann's avatar

Hey, sorry, so this is my travis.yml

language: php

sudo: false

matrix:
  include:
    - php: 5.5
    - php: 5.6
      env:
        - EXECUTE_CS_CHECK=true
        - EXECUTE_COVERAGE=true
    - php: 7.0
    - php: hhvm
  allow_failures:
    - php: 7.0
  fast_finish: true

cache:
  directories:
    - $HOME/.composer/cache

before_install:
  - composer self-update

before_script:
  - composer install --prefer-dist

script:
  - vendor/bin/phpspec run
  - touch .env
  - touch storage/database.sqlite
  - php artisan migrate --seed
  - php -S localhost:8000 -t public/ &
  - phpunit -v -c phpunit.xml

My errors are of this kind:

E[Sat Aug 22 11:39:02 2015] ::1:41491 [500]: /jsonapi

So the server is starting, I guess the routing is not working? But its just a guess, no evidence. Do I need to do something for the routing to work on travis?

olyckne's avatar

If you run php -S localhost:8000 -t public locally does it work? I just tried with a lumen app I have and it's working fine with the routing.

Corez64's avatar

As willvincent point out the PHP server doesn't support .htaccess for the routes. If you want to directly call the PHP in-build server command you need to tell it to use the router script php -S localhost:8000 -t public server.php or you can use the php artisan serve command which handles everything for you.

Please or to participate in this conversation.