FixtureHelper.php 1.54 KB
Newer Older
Mark committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<?php

namespace common\tests\_helpers;

use Codeception\Module;
use yii\test\FixtureTrait;
use common\tests\fixtures\UserFixture;

/**
 * This helper is used to populate database with needed fixtures before any tests should be run.
 * For example - populate database with demo login user that should be used in acceptance and functional tests.
 * All fixtures will be loaded before suite will be starded and unloaded after it.
 */
class FixtureHelper extends Module
{

17 18 19 20 21 22 23 24 25 26 27 28
    /**
     * Redeclare visibility because codeception includes all public methods that not starts from "_"
     * and not excluded by module settings, in guy class.
     */
    use FixtureTrait {
        loadFixtures as protected;
        fixtures as protected;
        globalFixtures as protected;
        unloadFixtures as protected;
        getFixtures as protected;
        getFixture as protected;
    }
Mark committed
29

30 31 32 33 34 35 36 37 38
    /**
     * Method called before any suite tests run. Loads User fixture login user
     * to use in acceptance and functional tests.
     * @param array $settings
     */
    public function _beforeSuite($settings = [])
    {
        $this->loadFixtures();
    }
Mark committed
39

40 41 42 43 44 45 46
    /**
     * Method is called after all suite tests run
     */
    public function _afterSuite()
    {
        $this->unloadFixtures();
    }
Mark committed
47

48 49 50 51
    /**
     * @inheritdoc
     */
    public function fixtures()
52 53 54 55 56 57 58 59
    {
        return [
            'user' => [
                'class' =>  UserFixture::className(),
                'dataFile' => '@common/tests/fixtures/data/init_login.php',
            ],
        ];
    }
Mark committed
60
}