Love Fuel?
Donate
About
Forums
Discussions
Login
FuelPHP Forums
Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
General
phpunit test Controllers
yoshi
May 2015
I'm using Request::forge() for controller test as follows.
I want to disable all core class object cache (static properties).
Isn't there a good method for that?
public function test_action_edit_fail($test_id)
{
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['s_ym'] = '2015-05-11';
$this->_assert_eq_err($test_id, 'error_msg1', '_post_name1');
$_POST['s_ym'] = '2015-05-12'
$this->_assert_eq_err($test_id, 'error_msg2', '_post_name2');
}
public function test_action_edit_success($test_id)
{
$_SERVER['REQUEST_METHOD'] = 'GET';
$response = Request::forge('/top/index/')->execute()->response();
$this->assertTrue(isset($response->body->get('data')[10000]));
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['status'] = 2;
$this->_assert_eq_success($test_id);
}
private function _assert_eq_err($test_id, $msg, $name)
{
Request::forge('/test/edit/'.$test_id)->execute();
$this->assertTrue($msg == Session::get_flash('error')[$name]->get_message());
Fieldset::reset(); // clear static::$_instances (extends core class)
Session::destroy();
Input::delete(); // clear static::$input
}
private function _assert_eq_success($test_id)
{
Request::forge('/test/edit/'.$test_id)->execute();
$this->assertTrue(Session::get_flash('success') != null);
Fieldset::reset();
Session::destroy();
Input::delete();
Model_Reserve::reset(); // clear static::$_cached_objects[get_called_class()]
}
Harro
May 2015
Accepted Answer
I wouldn't know, I have always found statics difficult to test, and never bothered.
Ideally you should test individual controller methods directly, in isolation, and not the entire Request/Response chain.
yoshi
May 2015
OK, Thank you
:)
kenjis
May 2015
If you could reset static properties, put the code in `setUp()`.
Add a Comment
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Apply for Membership
Categories
All Discussions
5,088
General
↳ General
3,364
↳ Job Board
13
↳ Installation & Setup
214
Packages
↳ Oil
213
↳ Orm
700
↳ Auth
260
Development
↳ Tips and Tutorials
126
↳ Code share
145
↳ Applications
52
In this Discussion
Harro
May 2015
kenjis
May 2015
yoshi
May 2015