Completed
Push — master ( a9d3b9...e09e3d )
by Kirill
03:27
created

LoadActionData::load()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 44
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 44
ccs 0
cts 33
cp 0
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 31
nc 1
nop 1
crap 2
1
<?php
2
3
namespace AppBundle\DataFixtures\ORM;
4
5
use AppBundle\Entity\Action;
6
use AppBundle\Entity\Device;
7
use AppBundle\Entity\VarHook;
8
use AppBundle\Entity\Variable;
9
use Doctrine\Common\DataFixtures\FixtureInterface;
10
use Doctrine\Common\Persistence\ObjectManager;
11
12
class LoadActionData implements FixtureInterface
13
{
14
    public function load(ObjectManager $manager)
15
    {
16
        $variable = new Variable();
17
18
        $variable->setName('hooktest');
19
        $variable->setDescription('test temperature metric');
20
        $variable->setSource('internal');
21
        $variable->setParser('Simple');
22
        $variable->setValue('20');
23
        $variable->needHistory = true;
24
        $variable->needSync = false;
25
26
        $manager->persist($variable);
27
28
        $device = new Device();
29
        $device->setAlias('pi.fs');
30
        $device->setName('Filesystem');
31
32
        $manager->persist($device);
33
34
        $action = new Action();
35
36
        $action->setArguments(json_encode(['file'=>'/tmp/testfile.log', 'text'=>'testtext']));
37
        $action->setType('real');
38
        $action->setAlias('file.write');
39
        $action->setDevice($device);
40
        $action->setName("Write file to disk");
41
        $action->setExecutor('FileWriter:write');
42
43
        $manager->persist($action);
44
45
        $varHook = new VarHook();
46
        $varHook->setVariable($variable);
47
        $varHook->setAction($action);
48
        $varHook->setName("Test variable hook");
49
        $varHook->setType("decider");
50
        $varHook->setExecutor("FileWriter:decideTrue");
51
        $varHook->setArguments('{"text":"test text"}');
52
53
        $manager->persist($varHook);
54
55
56
        $manager->flush();
57
    }
58
}
59