I’ve decided to develop a database driven web app, but I’m not sure where to start. The end goal of the project is three-fold:
- to learn new technologies and practices,
- deliver an unsolicited demo to management that would show how information that the company stores as office documents spread across a cumbersome network folder structure can be consolidated and made easier to access and maintain and
- show my co-workers how Test Driven Development and prototyping via class diagrams can be very useful and reduces future maintenance headaches.
I think this ends up being a basic CMS to which I have generated a set of features, see below.
- Create a database to store the site structure (organized as a tree with a ‘project group’->project structure).
- Pull the site structure from the database and display as a tree using basic front end technologies.
- Add administrator privileges/tools for modifying the site structure.
- Auto create required sub pages* when an admin adds a new project.
4.1 There will be several sub pages under each project and the content for each sub page is different. - add user privileges for assigning read and write privileges to sub pages.
What I would like to do is use Test Driven Development and class diagramming as part of my process for developing this project. My problem; I’m not sure where to start. I have read on Unit Testing and UML, but never used them in practice. Also, having never worked with databases before, how to I incorporate these items into the models and test units?
Thank you all in advance for your expertise.
We always start with the data model.
Ah, well, there’s the problem.
You have to start with the data, because everything starts with the data.
Write use cases. Your 5 technical requirements aren’t really very good use cases because there’s no Actor who interacts with a system. You need to write down the things an actor does — what the actor interacts with.
Identify the objects that the actor interacts with. When in doubt, write down all the nouns in your use cases.
Draw a picture of the classes that will implement those objects.
Walk through your use cases to be sure that all the things an Actor needs to do are based on attributes of your class definitions. All the data an actor needs has to be in these classes, which will become tables in your database.
Now, you have to start doing more technical work. You need a web framework with an ORM layer. You’re using PHP, so you’ll have to find a good framework for this. Cake or Doctrine or something.
Define one class in your ORM layer. You don’t have to be complete or precise, you just need something that you can test with.
Write unit tests for this class to be sure that it has the right data elements. This will be relatively simple at first, since your individual data classes will start out simple.
Once the basic set of classes are defined, you’ll need to look at relationships among classes. This is where the real work starts.
Look at a relationship in your picture. Any line. Pick one randomly.
Write unit tests to be sure that you can “navigate” across that line. From one object, fetch the related objects at the other end of the line. This shouldn’t be very complex, just a few lines of code.
Create a “fixture” — test data you can load into a database — to represent the objects and their relationships.
Run the test. If it breaks, update your ORM definitions to support the navigation properly.
When you’ve finished doing all the various relationships, you will have built a reasonable complete data model in a Test-Driven manner.
Now you can build your PHP presentation for the model objects.