Fixture.php 2.22 KB
Newer Older
Qiang Xue committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace yii\test;

use yii\base\Component;

/**
 * Fixture represents a fixed state of a test environment.
 *
 * 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 [[load()]] to specify how to set up a fixture; and override [[unload()]]
 * for clearing up a fixture.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
class Fixture extends Component
{
	/**
	 * @var array the fixtures that this fixture depends on. This must be a list of the dependent
	 * fixture class names.
	 */
	public $depends = [];

Carsten Brandt committed
38

Qiang Xue committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
	/**
	 * Loads the fixture.
	 * This method is called before performing every test method.
	 * You should override this method with concrete implementation about how to set up the fixture.
	 */
	public function load()
	{
	}

	/**
	 * This method is called BEFORE any fixture data is loaded for the current test.
	 */
	public function beforeLoad()
	{
	}

	/**
	 * This method is called AFTER all fixture data have been loaded for the current test.
	 */
	public function afterLoad()
	{
	}

	/**
	 * Unloads the fixture.
	 * This method is called after every test method finishes.
	 * You may override this method to perform necessary cleanup work for the fixture.
	 */
	public function unload()
	{
	}
70 71 72 73 74 75 76 77 78 79 80 81 82 83

	/**
	 * This method is called BEFORE any fixture data is unloaded for the current test.
	 */
	public function beforeUnload()
	{
	}

	/**
	 * This method is called AFTER all fixture data have been unloaded for the current test.
	 */
	public function afterUnload()
	{
	}
Qiang Xue committed
84 85
}