FixtureHelper.php 1.8 KB

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