yii2

Форк
1
/
ArrayFixture.php 
65 строк · 1.8 Кб
1
<?php
2
/**
3
 * @link https://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license https://www.yiiframework.com/license/
6
 */
7

8
namespace yii\test;
9

10
use yii\base\ArrayAccessTrait;
11
use yii\base\InvalidConfigException;
12

13
/**
14
 * ArrayFixture represents arbitrary fixture that can be loaded from PHP files.
15
 *
16
 * For more details and usage information on ArrayFixture, see the [guide article on fixtures](guide:test-fixtures).
17
 *
18
 * @author Mark Jebri <mark.github@yandex.ru>
19
 * @since 2.0
20
 */
21
class ArrayFixture extends Fixture implements \IteratorAggregate, \ArrayAccess, \Countable
22
{
23
    use ArrayAccessTrait;
24
    use FileFixtureTrait;
25

26
    /**
27
     * @var array the data rows. Each array element represents one row of data (column name => column value).
28
     */
29
    public $data = [];
30

31

32
    /**
33
     * Loads the fixture.
34
     *
35
     * The default implementation simply stores the data returned by [[getData()]] in [[data]].
36
     * You should usually override this method by putting the data into the underlying database.
37
     */
38
    public function load()
39
    {
40
        $this->data = $this->getData();
41
    }
42

43
    /**
44
     * Returns the fixture data.
45
     *
46
     * The default implementation will try to return the fixture data by including the external file specified by [[dataFile]].
47
     * The file should return the data array that will be stored in [[data]] after inserting into the database.
48
     *
49
     * @return array the data to be put into the database
50
     * @throws InvalidConfigException if the specified data file does not exist.
51
     */
52
    protected function getData()
53
    {
54
        return $this->loadData($this->dataFile);
55
    }
56

57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function unload()
61
    {
62
        parent::unload();
63
        $this->data = [];
64
    }
65
}
66

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.