Unit-testing models: use database mock

Hi guys,

is there a native, yii-like way to mock database? If no, what is the most simple way to do this?

You should use separate database for testing purposes.

Instead of index.php, you should use index-test.php, that will load testing configuration from

../config/test.php

inside of which you can set connection string to testing database like so:




return CMap::mergeArray(

	require(dirname(__FILE__).'/main.php'),

	array(

		'components'=>array(

			'db'=>array(

				'connectionString' => 'sqlsrv:server=HOMESERVER\\SQLEXPRESS;database=forum-test;MultipleActiveResultSets=false',

			),

			

		),

	)

);



Read more:

http://www.yiiframework.com/doc/guide/1.1/en/test.overview

Lubos

The Yii way is by using fixtures:

doc/guide/1.1/en/test.fixture :)