class Controller_Api_V1_Auth extends Controller_Rest {
public function get_authenticate(){
$this->response(array(
'foo' => Input::get('foo'),
'baz' => array(
1, 50, 219
),
'empty' => null
));
}
public function post_register(){
$this->response(array(
'foo' => Input::get('foo'),
'baz' => array(
1, 50, 219
),
'empty' => null
));
}
}
/** * @group Api */ class Test_Controller_Api extends TestCase { public function test_register_user() { $request = Request::forge('api/v1/auth/register.json'); $request->set_method('POST'); $response = $request->execute()->response(); $this->assertEquals($response->status, 200); } }
$ oil test --group=Api
Tests Running...This may take a few moments.
PHPUnit 3.6.12 by Sebastian Bergmann.
Configuration read from /.../fuel/core/phpunit.xml
FFuel\Core\Response Object
(
[status] => 405
[headers] => Array
(
)
[body] =>
)
Time: 0 seconds, Memory: 21.00Mb
There was 1 failure:
1) Test_Controller_Api::test_register_user
Failed asserting that 200 matches expected 405.
/.../fuel/app/tests/controller/api.php:14
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
$request = Request::forge('http://localhost/api/v1/auth/register');
it returns a "not found" exception (Fuel\Core\HttpNotFoundException).
3) Finally, I'm having trouble understanding how to pass parameters via POST or GET to my request.$request = Request::factory('http://localhost/api/v1/auth/register')
->method(Request::POST)
->post(array('foo' => 'bar', 'bar' => 'baz'));
// fake an AJAX request! $_SERVER['HTTP_X_REQUESTED_WITH'] = 'xmlhttprequest';
$request = \Request::forge('http://localhost/api/v1/auth/register.json', 'curl');
$request->set_method('POST');
$response = $request->execute(array('test' => 'hello POST!'))->response();
$this->assertEquals($response->status, 200);
It looks like you're new here. If you want to get involved, click one of these buttons!