I am trying to run some acceptance tests in my Laravel application. While functional tests trigger testing environment, acceptance tests do not. Is it a bug or a feature of acceptance tests? The main problem why this is bothering me is the fact, that it is not using(+populating+cleanup) testing database, it only connects to dev database (which is used, when no other ENV is specified e.g. testing, production) and this often fails those tests when I run them multiple times.
This is my configuration:
codeception.yml
paths:
tests: app/tests
log: app/tests/_log
data: app/tests/_data
helpers: app/tests/_helpers
settings:
bootstrap: _bootstrap.php
suite_class: \PHPUnit_Framework_TestSuite
colors: true
memory_limit: 1024M
log: true
modules:
config:
Db:
dsn: 'mysql:host=localhost;dbname=testdb'
user: 'root'
password: 'root'
dump: 'app/tests/_data/dump.sql'
populate: true
cleanup: true
acceptance.suite.yml
class_name: WebGuy
modules:
enabled:
- PhpBrowser
- WebHelper
- Db
config:
PhpBrowser:
url: 'http://localhost/'
functional.suite.yml
class_name: TestGuy
modules:
enabled: [Filesystem, TestHelper, Laravel4, Db]
Thanks for your help!
Codeception is a framework used for creating tests, including unit tests, functional tests, and acceptance tests. Despite the fact that it is based on PHP, the user needs only basic knowledge for starting work with the framework, thanks to the set of custom commands offered by Codeception.
"Acceptance" tests are not run in the testing environment. The reason is when Laravel is in the testing environment, it disables filters by default. So therefore the testing environment is only for unit and functional tests.
Acceptance tests should be run in another environment (like dev or a specific one to Codeception).
Because Codeception 2.x now uses Guzzle to get a page response, it is possible to detect when you are on your host machine and Codeception is doing a specific request. That way you can have a "testing" environment and also a "codeception" environment specifically for your acceptance tests.
If you are using Homestead, I do this in my start.php
file to detect if Codeception is running, and specifically put it into a 'codeception' environment, otherwise I let it run my environment detection normally
if ((gethostname() === 'homestead') && (isset($_SERVER['REMOTE_ADDR'])) && ($_SERVER['REMOTE_ADDR'] === '127.0.0.1'))
{
$env = $app->detectEnvironment(['codeception' => ['homestead']]);
}
else
{
$env = $app->detectEnvironment(['dev' => ['homestead']]);
}
Then in my 'codeception' environment, I setup a SQLite file database, and run acceptance tests against that (which is faster than mySQL testing).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With