Connecting to the database
Now that we have our skeleton application up and running, let's work on getting it properly connected to a database. Although this is more a matter of configuration than writing code, we will maintain a test-first approach, so that basic database connectivity becomes a part of our routine test suite.
Testing the connection
Chapter 3, introduced us to the testing framework provided by Yii. So, we know we add our unit tests under protected/tests/unit/. Let's create a simple database connectivity test file under this folder called DbTest.php. Create this new file with the following contents:
<?php
class DbTest extends CTestCase
{
public function testConnection()
{
$this->assertTrue(true);
}
}Here we have added a fairly trivial test. The assertTrue() method, which is part of phpUnit, is an assertion that will pass if the argument passed to it is true, and it will fail if it is false. So, in this case, it will pass if true is true. Of course...