0

Hi i am trying to set a a test to test my database calls. I want to pass a variables in url but cant seem to get it to work.

I wanted to do this

public function testDb()
{
               $response = $this->call('GET', '/searchAvailability?keyword=test product');
               $content =    $response->getContent();

           $this->assertEquals('[{"name":"test product"}]',$content );
}

But i keep getting "Undefined variable : keyword" when i try. It works in the browser just not when i run phpunit. Anyone got any ideas on why this is not working thanks.

1 Answer 1

1

The answer here is you need to specify the parameters differently in your call method:

$this->call('GET', '/searchAvailability', array('keyword' => 'test product'));

Below is the implementation of Illuminate\Foundation\Testing\TestCase::call method:

/**
 * Call the given URI and return the Response.
 *
 * @param  string  $method
 * @param  string  $uri
 * @param  array   $parameters
 * @param  array   $files
 * @param  array   $server
 * @param  string  $content
 * @param  bool    $changeHistory
 * @return \Illuminate\Http\Response
 */
public function call()
{
    call_user_func_array(array($this->client, 'request'), func_get_args());

    return $this->client->getResponse();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.