Prev | Current Page 159 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

Connect to database and store adapter for later use. >
This section of the unit test file contains only the initialization code that is run once. As you can see at the
top (#1), we have to ensure that we have set up our paths correctly so that the files can be found and we also
have to include all the files we are going to need. There is a check for the definition of ROOT_DIR to allow
for expansion and placing this unit test file in to a suite of files that can be tested all at the same time; when we
are testing as part of a suite, we will not want to alter the path. We also include the files from the Framework
that we need for this test.
As the constructor is only called once, it is the ideal place to load the config.ini file and connect to the
database. Again, if this class is part of a test suite, then the database connection will already have been made,
in which case we just collect it from the Registry. Otherwise, once we have connected, we set the database
adapter as the default adapter for Zend_Db_Table and store to the registry. We also assign it as a class member
variable as it is going to be used in the setUp() function to set our database to a known state.
Initializing our database is just a case of using the database adapter to create the table and insert some
rows.


Pages:
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
politycy Prezent dla mamy market serwery projekty wnętrz