I'm having trouble getting a test to work in Laravel 4. I use the files .envto manage my database settings as described in the Laravel Configuration Guide - Protecting Sensitive Configuration
The file is app/config/database.php as follows:
'mysql' => array(
'driver' => 'mysql',
'host' => $_ENV['dbhost'],
'database' => $_ENV['database'],
'username' => $_ENV['dbusername'],
'password' => $_ENV['dbpassword'],
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
Checked controller method:
public function getTaxonomies()
{
if (Input::has('page')) {
$limit = (Input::get('limit')) ? Input::get('limit') : 15;
$taxonomy = Taxonomy::with('photos')->paginate($limit)->toArray();
return Response::json(array(
'Taxonomies' => $taxonomy
));
}
return Response::json(array(
'Taxonomies' => Taxonomy::all()->load('photos')->toArray()
));
}
Test:
<?php
class TaxonomyControllerTest extends TestCase
{
public function testGetTaxonomies()
{
$this->action('GET', 'TaxonomyController@getTaxonomies');
$this->assertResponseOk();
}
}
The error I get is ErrorException: Undefined index: dbhost. I understand this because $_ENVvar is not populated in the CLI. So my question is: how should I handle db loans for testing?
Update:
, database.php app/config/testing, . , ? ?