61 linhas
1.6KB

  1. <?php
  2. namespace tests\codeception\common\_support;
  3. use tests\codeception\common\fixtures\UserFixture;
  4. use Codeception\Module;
  5. use yii\test\FixtureTrait;
  6. /**
  7. * This helper is used to populate database with needed fixtures before any tests should be run.
  8. * For example - populate database with demo login user that should be used in acceptance and functional tests.
  9. * All fixtures will be loaded before suite will be starded and unloaded after it.
  10. */
  11. class FixtureHelper extends Module
  12. {
  13. /**
  14. * Redeclare visibility because codeception includes all public methods that not starts from "_"
  15. * and not excluded by module settings, in actor class.
  16. */
  17. use FixtureTrait {
  18. loadFixtures as protected;
  19. fixtures as protected;
  20. globalFixtures as protected;
  21. unloadFixtures as protected;
  22. getFixtures as protected;
  23. getFixture as protected;
  24. }
  25. /**
  26. * Method called before any suite tests run. Loads User fixture login user
  27. * to use in acceptance and functional tests.
  28. * @param array $settings
  29. */
  30. public function _beforeSuite($settings = [])
  31. {
  32. $this->loadFixtures();
  33. }
  34. /**
  35. * Method is called after all suite tests run
  36. */
  37. public function _afterSuite()
  38. {
  39. $this->unloadFixtures();
  40. }
  41. /**
  42. * @inheritdoc
  43. */
  44. public function fixtures()
  45. {
  46. return [
  47. 'user' => [
  48. 'class' => UserFixture::className(),
  49. 'dataFile' => '@tests/codeception/common/fixtures/data/init_login.php',
  50. ],
  51. ];
  52. }
  53. }