Fixture.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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\base\Component;
  9. /**
  10. * Fixture represents a fixed state of a test environment.
  11. *
  12. * Each fixture instance represents a particular aspect of a test environment. For example,
  13. * you may use `UserFixture` to initialize the user database table with a set of known data. You may
  14. * load the fixture when running every test method so that the user table always contains the fixed data
  15. * and thus allows your test predictable and repeatable.
  16. *
  17. * A fixture may depend on other fixtures, specified via the [[depends]] property. When a fixture is being loaded,
  18. * its dependent fixtures will be automatically loaded BEFORE the fixture; and when the fixture is being unloaded,
  19. * its dependent fixtures will be unloaded AFTER the fixture.
  20. *
  21. * You should normally override [[load()]] to specify how to set up a fixture; and override [[unload()]]
  22. * for clearing up a fixture.
  23. *
  24. * For more details and usage information on Fixture, see the [guide article on fixtures](guide:test-fixtures).
  25. *
  26. * @author Qiang Xue <qiang.xue@gmail.com>
  27. * @since 2.0
  28. */
  29. class Fixture extends Component
  30. {
  31. /**
  32. * @var array the fixtures that this fixture depends on. This must be a list of the dependent
  33. * fixture class names.
  34. */
  35. public $depends = [];
  36. /**
  37. * Loads the fixture.
  38. * This method is called before performing every test method.
  39. * You should override this method with concrete implementation about how to set up the fixture.
  40. */
  41. public function load()
  42. {
  43. }
  44. /**
  45. * This method is called BEFORE any fixture data is loaded for the current test.
  46. */
  47. public function beforeLoad()
  48. {
  49. }
  50. /**
  51. * This method is called AFTER all fixture data have been loaded for the current test.
  52. */
  53. public function afterLoad()
  54. {
  55. }
  56. /**
  57. * Unloads the fixture.
  58. * This method is called after every test method finishes.
  59. * You may override this method to perform necessary cleanup work for the fixture.
  60. */
  61. public function unload()
  62. {
  63. }
  64. /**
  65. * This method is called BEFORE any fixture data is unloaded for the current test.
  66. */
  67. public function beforeUnload()
  68. {
  69. }
  70. /**
  71. * This method is called AFTER all fixture data have been unloaded for the current test.
  72. */
  73. public function afterUnload()
  74. {
  75. }
  76. }