I'm trying to write some acceptance tests for laravel 4 with codeception and the selenium module.
I got two problems with that.
The first one is that my app is running in the homestead vagrant vm and the selenium server is running on the host machine. So is there a easy way to run the selenium server in the vm and the call the browser o n the host machine ?
My second problem is that when testing the actual live database is used, because the environment of the laravel app is not set to testing. Obviously i would like to have it to use the test database and reset it after each test.
codeception.yaml
actor: Tester
paths:
tests: app/tests
log: app/tests/_output
data: app/tests/_data
helpers: app/tests/_support
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
suite_class: \PHPUnit_Framework_TestSuite
modules:
config:
Db:
dsn: 'sqlite:app/tests/_data/testdb.sqlite'
user: ''
password: ''
dump: app/tests/_data/dump.sql
acceptance.yaml
class_name: AcceptanceTester
modules:
enabled: [WebDriver,AcceptanceHelper]
config:
WebDriver:
url: 'http://app.dev'
browser: firefox
window_size: 1920x1024
wait: 10
The easy way to run acceptance tests in the vm is to use phantom js in ghostdriver mode. There is a tutorial here:
https://gist.github.com/antonioribeiro/96ce9675e5660c317bcc
You can still see screenshots and the rendered html when tests fail, so it isn't a big deal that you can't see the browser.
For your second question, I prefer to keep a separate tests installation with it's own database. That way changes you make in dev don't alter your test results and it's a better approximation of production.
If you want to use the same installation, you can automate switching out your settings with .env files.
http://laravel.com/docs/4.2/configuration#protecting-sensitive-configuration
your config would look like this:
and your .env.php would look like:
than you can use a task runner like robo to automatically update your .env file and run codeception tests.
http://robo.li/
.env files are changing in Laravel 5, but this workflow still works with minimal modification.
http://mattstauffer.co/blog/laravel-5.0-environment-detection-and-environment-variables