PHPUnit Mock RequestStack of symfony
You don't actually have to mock the RequestStack
class, since it's basically a container.
If you want to test with the RequestStack
, you could do something like this:
<?phpuse Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\RequestStack;class MessageReceivedServiceTest extends \PHPUnit_Framework_TestCase{ public function test() { $request = new Request([], [], [], [], [], [], [], json_encode([ 'foo' => 'bar' ])); $requestStack = new RequestStack(); $requestStack->push($request); // Do your tests }}
When you call currentRequest
on the $requestStack
variable, it should return the $request
variable.