Dieses Blog durchsuchen

Sonntag, 17. Juli 2016

symfony 3: create a unittest for an api controller

In one of my last post
http://magento2-tuts.blogspot.de/2016/07/symfony3-create-restful-api-controller.html , we have created a restful api controller.

Now we want to write a unittest to test this controller.


install phpunit:
apt-get install phpunit

configure phpunit.xml
-in your projectroot there is a file phpunit.xml.dist Rename it to phpunit.xml
- open the file and add your BundleDirectory to the directory object

In my case i had to add the src/Check/BlogBundle/Test/ directory

Now we can add a controllerTest.

Lets say, we want to test, that the service throws 500 if we try to POST an empty user to the database:  

Run your test:
open your terminal in your projectroot and type: phpunit -c phpunit.xml

Thats all your testresults are found in the console.

Keine Kommentare:

Kommentar veröffentlichen