dimanche 15 octobre 2017

Make a HTTP Request and populate it with data

I'm trying to test a validate() method of a Service class, which accepts a Request object. Normally, when form on the frontend is submitted, I get that Request object as a parameter in controller's method and send it to Service, but now I want to test that method, I use phpunit and I would like to create my own Request objects and send them to Service class to see if it reacts how it should. My testing method looks like this:

public function testWhenUsernameIsNotSetGetValidationError()
{

    $request = new Request();

    $request->request->add(['email' => 'test@email.com', 'password' => 'test123', 'password_confirm' => 'test123']);

    dd($request->all());

    $this->assertFalse($this->regService->validate($request));

}

The problem is, that

dd($request->all())

prints out an empty array ( [] ).

Why is that happening? Do I need to add this data somehow different?

Aucun commentaire:

Enregistrer un commentaire