mardi 11 juillet 2017

Laravel5.4: How to mock the current page?

I want to test a helper function using Request::fullUrl in it.

function foo($arg)
{
    // Get current full URL.
    $url = Request::fullUrl();

    // Return modified URL.
    return $url;
}

The docs says:

You should not mock the Request facade. Instead, pass the input you desire into the HTTP helper methods such as get and post when running your test.

What are "the HTTP helper methods"? They mean "TestCase::get" and "TestCase::post"?

Yes, my problem was solved by using $this->get(). But is this correct way?

class MyHelperTest extends TestCase
{
    public function testFoo()
    {
        // Move to index page.
        $this->get('/');

        // Get a modified URL.
        $url = foo('arg');

        $this->assertEquals('Expected URL', $url);
    }
}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2ughwYm
via IFTTT

Aucun commentaire:

Enregistrer un commentaire