From 1ae178334023d36a224b06c371a47a5c3e0aad3d Mon Sep 17 00:00:00 2001 From: wei <> Date: Mon, 14 May 2007 02:51:03 +0000 Subject: remove unfinished docs. --- .../protected/pages/Docs/CreateBusinessCode.page | 127 --------------------- 1 file changed, 127 deletions(-) delete mode 100644 demos/time-tracker/protected/pages/Docs/CreateBusinessCode.page (limited to 'demos/time-tracker/protected/pages/Docs/CreateBusinessCode.page') diff --git a/demos/time-tracker/protected/pages/Docs/CreateBusinessCode.page b/demos/time-tracker/protected/pages/Docs/CreateBusinessCode.page deleted file mode 100644 index e5afa572..00000000 --- a/demos/time-tracker/protected/pages/Docs/CreateBusinessCode.page +++ /dev/null @@ -1,127 +0,0 @@ - -

Create Business Code

-

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.

- -<?php -class Project -{ - public $ActualDuration = 0; - public $CreatorUserName = ''; - public $CompletionDate = 0; - public $DateCreated = 0; - public $Description = ''; - public $EstimateDuration = 0; - public $ID = 0; - public $ManagerUserName = ''; - public $Name = ''; -} -?> - - -

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.

- -

Business Services, test case first

-

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).

- - -<?php -Prado::using('Application.APP_CODE.*'); -class ProjectDaoTestCase extends UnitTestCase -{ - function testProjectDaoCanCreateNewProject() - { - $project = new Project(); - $project->Name = "Project 1"; - - $dao = new ProjectDao(); - - $this->assertTrue($dao->createNewProject($project)); - $this->assertEqual($dao->getProjectByID(1), $project); - } -} -?> - -

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.

- -<?php -class BaseDao -{ - private $_connection; - - public function setConnection($connection) - { - $this->_connection = $connection; - } - - protected function getConnection() - { - return $this->_connection; - } -} -?> - -

And finally our ProjectDao class.

- -<?php -Prado::using('Application.APP_CODE.BaseDao'); -class ProjectDao extends BaseDao -{ -} -?> - -

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. -

- -class ProjectDao extends BaseDao -{ - public function createNewProject($project) - { - } - - public function getProjectByID($projectID) - { - } -} - -

Run the unit test again, we see a different type of error now. This time -the unit test runner complians that the test fails.

-

Write Test, Run Test, Repeat

-
-At this point, you may notice a repetition -
    -
  1. write some test code,
  2. -
  3. run the test, test gives an error,
  4. -
  5. write some actual code to only remove the previous error,
  6. -
  7. goto step 1 to repeat.
  8. -
-
-

We shall see how we can make this test pass in the next section.

-
\ No newline at end of file -- cgit v1.2.3