Completed
Push — master ( cbb93f...ca3eaa )
by Matt
05:19
created

SingleWanderFixture::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
namespace App\DataFixtures;
4
5
use App\Entity\Wander;
6
use App\Service\GpxService;
7
use App\Service\UploadHelper;
8
use Doctrine\Bundle\FixturesBundle\Fixture;
9
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
10
use Doctrine\Persistence\ObjectManager;
11
use Symfony\Component\Filesystem\Filesystem;
12
use Symfony\Component\Finder\Finder;
13
use Symfony\Component\Finder\SplFileInfo;
14
use Symfony\Component\HttpFoundation\File\File;
15
16
class SingleWanderFixture extends Fixture implements FixtureGroupInterface
17
{
18
    /** @var UploadHelper */
19
    private $uploadHelper;
20
21
    /** @var GpxService */
22
    private $gpxService;
23
24
    public function __construct(UploadHelper $uploadHelper, GpxService $gpxService)
25
    {
26
        $this->uploadHelper = $uploadHelper;
27
        $this->gpxService = $gpxService;
28
    }
29
30
    public static function getGroups(): array
31
    {
32
        return ['single_wander'];
33
    }
34
35
    public function load(ObjectManager $manager): void
36
    {
37
        $fs = new Filesystem();
38
        $source = __DIR__ . '/gpx/01-APR-21 125735.GPX';
39
        $targetPath =  sys_get_temp_dir() . '/01-APR-21 125735.GPX';
40
        $fs->copy($source, $targetPath);
41
        $uploadedFile = $this->uploadHelper->uploadGpxFile(new File($targetPath));
42
        $wander = new Wander();
43
        $wander->setGpxFilename($uploadedFile);
44
        $this->gpxService->updateWanderFromGpx($wander);
45
        $wander->setTitle('Single test wander');
46
        $wander->setDescription('Single wander description');
47
        $manager->persist($wander);
48
        $manager->flush();
49
    }
50
}
51