Each fixture instance represents a particular aspect of a test environment. For example, you may use UserFixture to initialize the user database table with a set of known data. You may load the fixture when running every test method so that the user table always contains the fixed data and thus allows your test predictable and repeatable. A fixture may depend on other fixtures, specified via the [[depends]] property. When a fixture is being loaded, its dependent fixtures will be automatically loaded BEFORE the fixture; and when the fixture is being unloaded, its dependent fixtures will be unloaded AFTER the fixture. You should normally override Fixture::load to specify how to set up a fixture; and override Fixture::unload for clearing up a fixture. For more details and usage information on Fixture, see the guide article on fixtures.
Since: 2.0
Author: Qiang Xue (qiang.xue@gmail.com)
Inheritance: extends yii\base\Component
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (is_string($this->db)) {
         $this->db = Yii::$app->getComponent($this->db);
     }
     if (!is_object($this->db)) {
         throw new InvalidConfigException("The 'db' property must be either a DB connection instance or the application component ID of a DB connection.");
     }
 }
Exemplo n.º 2
0
 /**
  * @inheritdoc
  */
 public function unload()
 {
     parent::unload();
     $this->data = [];
 }
Exemplo n.º 3
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     $this->db = Instance::ensure($this->db, Object::className());
 }