Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unit test controllers in Yii

How's this done? Do I just prepare a $_POST/$_GET/$_FILES set and pass it to the controller? Or is there some more elegant way to test the Yii controllers?

like image 491
MrB Avatar asked Jul 18 '11 21:07

MrB


1 Answers

Usually, unit testing is performed for models, helper, components, etc. So in other words, for something that implements application business logic. For test application controllers, a commonly used process is Functional Testing.

More information on performing such tests can be found in the Yii documentation.

In a nutshell, use some thing like Selenium, which opens some url in a web-browser and collects information after the test.

Another technique to test controllers described over here.

By the way, if it is difficult to have the logic implemented into your controller, look for the Fat Model approach in MVC pattern. More information here.

like image 91
Oleksandr Otchenashev Avatar answered Oct 14 '22 01:10

Oleksandr Otchenashev