Passed
Pull Request — master (#20134)
by Wilmer
14:25 queued 05:46
created

ArrayFixture   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 57.14%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 43
ccs 4
cts 7
cp 0.5714
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A unload() 0 4 1
A getData() 0 3 1
A load() 0 3 1
1
<?php
2
3
/**
4
 * @link https://www.yiiframework.com/
5
 * @copyright Copyright (c) 2008 Yii Software LLC
6
 * @license https://www.yiiframework.com/license/
7
 */
8
9
namespace yii\test;
10
11
use yii\base\ArrayAccessTrait;
12
use yii\base\InvalidConfigException;
13
14
/**
15
 * ArrayFixture represents arbitrary fixture that can be loaded from PHP files.
16
 *
17
 * For more details and usage information on ArrayFixture, see the [guide article on fixtures](guide:test-fixtures).
18
 *
19
 * @author Mark Jebri <[email protected]>
20
 * @since 2.0
21
 */
22
class ArrayFixture extends Fixture implements \IteratorAggregate, \ArrayAccess, \Countable
23
{
24
    use ArrayAccessTrait;
25
    use FileFixtureTrait;
26
27
    /**
28
     * @var array the data rows. Each array element represents one row of data (column name => column value).
29
     */
30
    public $data = [];
31
32
33
    /**
34
     * Loads the fixture.
35
     *
36
     * The default implementation simply stores the data returned by [[getData()]] in [[data]].
37
     * You should usually override this method by putting the data into the underlying database.
38
     */
39 3
    public function load()
40
    {
41 3
        $this->data = $this->getData();
42
    }
43
44
    /**
45
     * Returns the fixture data.
46
     *
47
     * The default implementation will try to return the fixture data by including the external file specified by [[dataFile]].
48
     * The file should return the data array that will be stored in [[data]] after inserting into the database.
49
     *
50
     * @return array the data to be put into the database
51
     * @throws InvalidConfigException if the specified data file does not exist.
52
     */
53 3
    protected function getData()
54
    {
55 3
        return $this->loadData($this->dataFile);
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function unload()
62
    {
63
        parent::unload();
64
        $this->data = [];
65
    }
66
}
67