DbFixture.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\test;
  8. use Yii;
  9. use yii\db\Connection;
  10. use yii\di\Instance;
  11. use yii\base\Object;
  12. /**
  13. * DbFixture is the base class for DB-related fixtures.
  14. *
  15. * DbFixture provides the [[db]] connection to be used by DB fixtures.
  16. *
  17. * For more details and usage information on DbFixture, see the [guide article on fixtures](guide:test-fixtures).
  18. *
  19. * @author Qiang Xue <qiang.xue@gmail.com>
  20. * @since 2.0
  21. */
  22. abstract class DbFixture extends Fixture
  23. {
  24. /**
  25. * @var Connection|array|string the DB connection object or the application component ID of the DB connection.
  26. * After the DbFixture object is created, if you want to change this property, you should only assign it
  27. * with a DB connection object.
  28. * Starting from version 2.0.2, this can also be a configuration array for creating the object.
  29. */
  30. public $db = 'db';
  31. /**
  32. * @inheritdoc
  33. */
  34. public function init()
  35. {
  36. parent::init();
  37. $this->db = Instance::ensure($this->db, Object::className());
  38. }
  39. }