We start the design with the database, the entity relationships are shown in the diagram below.
class="figure" />Now we can begin to create and test some business code. Let us begin with the Project defintions. First, we add some properties or fields.
All the fields should be self explainatory. The ManagerUserName is the user name of the project manager. Notice that the fields are public, later on, we can change some or all of them to be private and provide some accessor and mutators (i.e. getters and setters). If we want we can let the Project class inherit TComponent such that the getters and setters can be used like properties, such as those found in Prado.
Next we want to add users to the project. For this, we start with some unit tests. We are going to design the business logic around the concept of Data Access Objects (DAO).
So what are we doing here? First we create a new Project named "Project 1". Then we create a new ProjectDao so we can insert new projects and retrieve it. We assert that a project will be create sucessfully using assertTrue($do->createNewProject(...)). We also assert that getProjectByID(1) will return an instance of Project class with same data (the reference may be different).
If we run the above unit test case, nothing is going to pass since we have not even defined the ProjectDao class. So lets do that first and import the class in the tests as well.
We will create a base Dao class as follows, and we save as BaseDao.php in our APP_CODE directory.
And finally our ProjectDao class.
If we run the unit test again, we get an error message something like "Fatal error: Call to undefined method ProjectDao::createNewProject() in ...". So let us, fix this.
Run the unit test again, we see a different type of error now. This time the unit test runner complians that the test fails.
We shall see how we can make this test pass in the next section.