There is an application which uses both php and javascript. If I want to write test cases for this application. Shall I have to write both (phpunit test cases for php code and j
The first important concept is: to be tested, your code must be run, and for that you have to use the environment needed for each case:
Once you have this clear, it's easy to understand how to setup the tests. Use PHPUnit for testing your php files and classes, and your Javascript framework of choice for testing Javascript code.
Regarding Javascript code being mixed with php code:
Strictly, the Javascript code will finally be sent to the browser, even if it is being written by php. So it should be testable running it in a Javascript environment.
But in reality, this probably is an indication of a poorly structured app, in which Javascript code is not separated from the backend code, and probably does not use objects and separation of concerns. This will make the code quite hard to test.
IMO the hardest part of testing is being able to write testable code, not writing the actual tests. If your code does not uses objects, some kind of dependency injection, templates for writing the HTML and the Javascript code is not fully separated from the backend code, I'd say you'll have a bad time trying to test it. My advice is that you rewrite some part of your app using best practices and try to test it. Using a framework usually helps because frameworks enforce the separation of concerns and usually have unit testing integrated.