Recently I have been reading online about eXtreme programming and agile practices. I wish to adapt them. However most of my code is all in PHP which is the normal CRUD type web applications. Moreover I user web framework like CodeIgniter, which also abstracts a lot of the core features.

To sum up, how can I implement the test driven development into applications which are heavily dependent on databases and user input, particularly in the test automation part?

I would now ask this question targeting my current project

I am working on an college forum web application. It has the basic social network features and also includes XMPP server on its stack. The following components constitute my application stack:

  1. Apache web server with mod_php enabled.
  2. PHP as a back-end language.(CodeIgniter framework)
  3. MySql database.
  4. Openfire server for XMPP.
  5. HTML, CSS, jQuery and Strophe(for XMPP) on front end, and
  6. A Python middleware for XMPP.

Currently I am working without any testing or build cycle. I use SVN as the version control system. And I wish to include TDD and CI into the development process. I already have some code in the project. What strategies and best practices should I adopt for implementing TDD and CI in this kind of project?

PS: We are a team of three people working on a self project as such we dont have any other person who influences the design(apart from the end users).

This is what I did to start implementing

I refactored the login function which was taking the username and password passed from the front end and then applies sanity checks, checks for valid username, then for valid password, If yes it sets the session cookie and redirects the user to a page based on his role.

I broke the above function into three one to take username and password and check if they are correct, another to set the cookies and the last one that takes the values from front end and applies sanity checks, calls the other two functions and then redirects.

I could write test for only the first function. Is that enough?

closed as not a real question by Jim G., user7007, Dynamic, EL Yusubov, gnat Dec 30 '12 at 5:38

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    -1: Since when are TDD practices heavily dependent on databases? I thought that any TDD implementation must decouple the application from its database. Otherwise you're writhing integration tests. – Jim G. Dec 29 '12 at 23:32
  • @JimG. I would like to make myself more clear, I meant to get advice on implementing TDD for PHP based web applications that are mainly driven by user input and database as opposed to applications that process takes up some data and runs eg -- How would I be make a test for a module that implements authentication? – mlakhara Dec 29 '12 at 23:41
  • 2
    Very good question, +1 – Fergus In London Dec 30 '12 at 1:01
  • 3
    I think this question is now valid enough to be reopened. I can't vote for it, but those who can could take a look. – Patkos Csaba Dec 30 '12 at 12:38
  • 1
    You really aren't in an unusual situation. Lots of applications are mainly driven by user input and database, and they still use TDD. This is really quite common. Which might be part of why people don't know how they could go about answering your question. – psr Dec 31 '12 at 22:22

PHPUnit will help with testing your application.

Usually, people write unit tests to test the singularity of their business rules, the actual methods that have business logic. That would be the unitary part of your tests.

You can mock the database, or write functional or integration tests to test the features on a more wider space.

PHPUnit helps you with that as well.

Not the answer you're looking for? Browse other questions tagged or ask your own question.