I am working in web application project using php, mysql and zend framework extension classes. And my task is to write unit test case for web application. I read following document https://phpunit.de/manual/4.3/en/installation.html and saw some sample also. Even though i cant to understand fully. I dont know how to practice sample code in browser. So anyone guide me how to start phpunit framework testcase. And one more important what are the classes I have to write unit test case.
-
1See if the answer helps, if not, add more details on what exactly you are using and what your are trying to achieve. – Ian Bytchek Sep 16 '14 at 14:33
1 Answers
You are at the beginning of a painful testing journey. In the nutshell there are two basic types: unit and functional testing, there are many answers on what is the difference between the two, like this one.
Typically everything start with unit testing, when you create a basic command / function and use a unit test to confirm that they work as expected as an independent unit. Once you finish combining those commands into a fully functional part of your application (controller action / piece of code that handles the request and returns a response) you use a functional test to confirm that they provide the required business logic. Normally only the functional testing involves using the browser or browser simulator (in the PHP / server side development context).
With that in mind, you can test majority of your code with unit tests using PHPUnit, it also would be easier to begin with. For functional testing there is an amazing Behat and Mink projects. You should do your own research on the whole subject, but be prepared that this is not a few hours job, especially if you are new to this. Those links will help you kickstart your learning:
8 Must Have PHP Quality Assurance Tools
Getting Started with PHPUnit
BDD With Behat
Practical BDD with Behat and Mink
Google the search engine

- 1
- 1

- 8,804
- 6
- 46
- 72
-
thank you for reply. you said functional test, rather than unit testing. So what i have do for unit testing. And what is difference between them.? – Kumar Shanmugam Sep 17 '14 at 06:57
-
1@KumarShanmugam, see the update answer. If you have any particular questions on PHPUnit / Behat check out the existing questions under the relevant tags or ask your own, there's a lot of help around. – Ian Bytchek Sep 17 '14 at 09:56
-
you're absolutely right I am beginner of unit test. And also this is my first task in my new concern(Newly joined). Just I confirmed it. I have to do unit test only. And I understand now difference for unit and functional testing. Thank you so much... I will start to learn with your guided links – Kumar Shanmugam Sep 17 '14 at 10:18
-
If I am not wrong, The unit test is to make a bug report to developer? So how to produce the report. for ex: i write test function for add two number (1+1=2) using phpunit asserts methods. If failed the asserts how to show the output or how to make report? – Kumar Shanmugam Sep 17 '14 at 10:34
-
1The output of running PHPUnit is the report itself: it shows which tests passed and which didn't. It is also tightly integrated with many IDEs, including PhpStorm. Developers should run the relevant tests prior committing the code and ensure they are passing. If you need something more specific, it provides interfaces to format your output, but normally this isn't necessary. – Ian Bytchek Sep 17 '14 at 10:50