Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
PHPUnit Request error
  • Hi, I'm attempting to write some unit tests for a controller.  I'm also debugging the unit tests in PHPStorm IDE.  Here's the weird problem:

        public function testGetStuff()
        {
            $req = Request::forge('http://fapi.localhost/stuff/' . $this->stuff_id, true, 'GET');
        }
    throws the follwing error:
    Argument 1 passed to Fuel\Core\Router::process() must be an instance of Request, instance of Fuel\Core\Request given

    Surely Fuel\Core\Request is exactly what the router is looking for.  Bootstrapping my unit tests normally and other tests I've run working directly with crud models are working like a charm.
  • HarroHarro
    Accepted Answer
    Router is looking for \Request.

    All Fuel core classes are aliased to the global namespace so you can easily alias them. The Fuel\Core namespace must NEVER be used in your code, except on a class definition when you extend it.

    I assume this test runs in the \Fuel\Core namespace, so you'll have to prefix Request::forge() with a backslash to load it from global.
  • Worked like a charm.  Course I wasn't modifying core classes, but I did have use Fuel\Core\Request; at the top of the file and didn't realize I still needed the leading slash.  Now I know though. Thanks for your help!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion