Passed
Push — scrutinizer-migrate-to-new-eng... ( 58afd6 )
by Alexander
18:11
created

ArrayFixture   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 62.5%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 43
ccs 5
cts 8
cp 0.625
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
 * @link http://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license http://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 <[email protected]>
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 3
    public function load()
39
    {
40 3
        $this->data = $this->getData();
41 2
    }
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 3
    protected function getData()
53
    {
54 3
        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