0

I mean I know I can write PHPUnit tests,
but how to mock web server / mysql server?

I'd also like to test MySQL / database code.
Best would be something suitable for Travis CI.

1 Answer 1

1

I like using codeception for my acceptance tests, but regardless, the travis setup is pretty much the same. Install a selenium server!

language: php

php:
  - 5.6
  - 7.0
  - 7.1
  - hhvm

matrix:
  allow_failures:
    - php: hhvm

addons:
  hosts:
    - FAKEHOSTNAMEHERE

sudo: false


install:
  - wget http://selenium-release.storage.googleapis.com/2.42/selenium-server-standalone-2.42.2.jar
  - composer install


before_script:
  - export DISPLAY=:99.0
  - sh -e /etc/init.d/xvfb start
  - sleep 5
  - java -jar selenium-server-standalone-2.42.2.jar -port 4444 &
  - "mysql -e 'create database codeception_test;'"
  - nohup php -S FAKEHOSTNAMEHERE:8000 public/index.php &
script:
  - php vendor/bin/codecept run  --coverage-xml --env travis
after_script:
  - phpunit --coverage-clover=coverage.clover
  - wget https://scrutinizer-ci.com/ocular.phar
  - php ocular.phar code-coverage:upload --format=php-clover tests/_output/coverage.xml

Just replace the FAKEHOSTNAMEHERE with whatever you need.

Sign up to request clarification or add additional context in comments.

6 Comments

Wow, thanks. So you say I should not mock anything, but install an actual server instead? I could simply install even MAMP?
never use mamp or xampp! but sure, this allows you to run the server and run real tests with actual requests :-) Mocking is good for testing individual units, this is good for seeing how it plays out for real
Why no MAMP / XAMPP?
because they are nothing like a real production environment! much better using vagrant and configuring it with puphpet.com, or even using docker! But anyway, Travis runs on Linux, so you want a LAMP stack. And that's just standard linux installs!
Thanks for all the references! Is there any solution that is mocking a servers programatically directly in PHP? It won't test the low-level stuff, but I could test the API anyway. Wow, Codeception just does that.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.