yii2
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
8namespace yii\test;
9
10use yii\base\ArrayAccessTrait;
11use 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*/
21class ArrayFixture extends Fixture implements \IteratorAggregate, \ArrayAccess, \Countable
22{
23use ArrayAccessTrait;
24use FileFixtureTrait;
25
26/**
27* @var array the data rows. Each array element represents one row of data (column name => column value).
28*/
29public $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*/
38public 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*/
52protected function getData()
53{
54return $this->loadData($this->dataFile);
55}
56
57/**
58* {@inheritdoc}
59*/
60public function unload()
61{
62parent::unload();
63$this->data = [];
64}
65}
66