Did anyone solve the issue of mocking the request object in Yii 1.1?

When unit-testing controllers in Yii 1.1, it’s necessary to create a mock or dummy of the request object. However, it’s a read-only property of the application component. Did anyone find a solution to this?

The hacky solution is to write to the super-globals, like

$_GET['foo'] = 'bar';

It’s a bit problematic that the request is fetched from the global App() and not from the controller itself via $this->request. If it were, then mocking could be used.

Why do you want to rewrite the request? Never did test with Yii1 though

It’s only for the unit-tests, where it’s easier to provide a custom-made request object rather than hacking into super-globals $_GET and $_POST.

I see. My understanding of Yii1 is very dim as I stopped using it many years ago. However, you might want to look at external libraries like http-mock and see if you can get them integrated with Yii1 somehow.

I hope someone more knowledgeable will step in to help.

GitHub - InterNations/http-mock: Mock HTTP requests on the server side in your PHP unit tests