Error when adding another test
Opened this issue · 0 comments
const-g commented
Hi,
Adding another test to FastModelTest broke the thing:
public function testCheckName()
{
$expectedResult = sprintf('hello %s from my model', $this->_site);
$response = $this->get('/check_name.json', array('QUERY_STRING' => 'site=ivan'));
$json = json_decode($response);
$this->assertFalse($json->error);
$this->assertSame(
$expectedResult,
$json->result);
}
public function testCheckName2()
{
$expectedResult = sprintf('hello %s from my model', $this->_site);
$response = $this->get('/check_name.json', array('QUERY_STRING' => 'site=ivan'));
$json = json_decode($response);
$this->assertFalse($json->error);
$this->assertSame(
$expectedResult,
$json->result);
}
The error:
.PHP Fatal error: Call to a member function get() on a non-object in /vagrant/fastapi/src/app.php on line 3
And this happen because in your bootstrap:
$app = '';
//test values
$mode = 'test';
//include app bootstrap to use slim instance
require_once '../../bootstrap.php';
// Include our core application file
require FASTAPI_ROOT . '/app.php';
$this->app = $app;
return $this->app;
The second test run the setup() again,, but then require_once '../../bootstrap.php';
bootstrap file is not loaded, so $app will stay empty.
I tried to fix that by "caching" $app, using $this->app with something like $app = !empty($this->app) ? $this->app : '';
but it didn't work.
I'll try other things, but if you have an idea how to fix that....