Passed
Push — master ( ec0d02...c0f595 )
by Jan
06:31 queued 10s
created

PartProviderTest::testReplace()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
4
 *
5
 * Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics)
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU Affero General Public License as published
9
 * by the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License
18
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19
 */
20
21
namespace App\Tests\Services\LabelSystem\PlaceholderProviders;
22
23
use App\Entity\Contracts\TimeStampableInterface;
24
use App\Entity\Parts\Category;
25
use App\Entity\Parts\Footprint;
26
use App\Entity\Parts\Manufacturer;
27
use App\Entity\Parts\Part;
28
use App\Services\LabelSystem\PlaceholderProviders\GlobalProviders;
29
use App\Services\LabelSystem\PlaceholderProviders\PartProvider;
30
use DateTime;
31
use Doctrine\ORM\EntityManagerInterface;
32
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
33
34
/**
35
 * @group DB
36
 */
37
class PartProviderTest extends WebTestCase
38
{
39
    /** @var PartProvider */
40
    protected $service;
41
42
    protected $target;
43
44
    /** @var \Doctrine\ORM\EntityManager */
45
    protected $em;
46
47
    public function setUp(): void
48
    {
49
        self::bootKernel();
50
        $this->service = self::$container->get(PartProvider::class);
51
        $this->target = new Part();
52
        $this->em = self::$container->get(EntityManagerInterface::class);
53
54
        $this->target->setCategory($this->em->find(Category::class, 6));
0 ignored issues
show
Bug introduced by
The method find() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
        $this->target->setCategory($this->em->/** @scrutinizer ignore-call */ find(Category::class, 6));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
        $this->target->setFootprint($this->em->find(Footprint::class, 6));
56
        $this->target->setManufacturer(null);
57
58
        $this->target->setMass(1234.2);
59
        $this->target->setTags('SMD, Tag1, Tag2');
60
        $this->target->setManufacturerProductNumber('MPN123');
61
        $this->target->setManufacturingStatus('active');
62
63
        $this->target->setDescription('<b>Bold</b> *Italic*');
64
        $this->target->setComment('<b>Bold</b> *Italic*');
65
    }
66
67
    public function dataProvider(): array
68
    {
69
        return [
70
            ['Node 2.1', '[[CATEGORY]]'],
71
            ['Node 2 → Node 2.1', '[[CATEGORY_FULL]]'],
72
            ['Node 2.1', '[[FOOTPRINT]]'],
73
            ['Node 2 → Node 2.1', '[[FOOTPRINT_FULL]]'],
74
            ['', '[[MANUFACTURER]]'],
75
            ['', '[[MANUFACTURER_FULL]]'],
76
77
            ['1.2 kg', '[[MASS]]'],
78
            ['MPN123', '[[MPN]]'],
79
            ['SMD, Tag1, Tag2', '[[TAGS]]'],
80
            ['Active', '[[M_STATUS]]'],
81
            ['<b>Bold</b> <em>Italic</em>', '[[DESCRIPTION]]'],
82
            ['Bold Italic', '[[DESCRIPTION_T]]'],
83
            ['<b>Bold</b> <em>Italic</em>', '[[COMMENT]]'],
84
            ['Bold Italic', '[[COMMENT_T]]'],
85
        ];
86
    }
87
88
    /**
89
     * @dataProvider dataProvider
90
     */
91
    public function testReplace(string $expected, string $placeholder): void
92
    {
93
        $this->assertSame($expected, $this->service->replace($placeholder, $this->target));
94
    }
95
}
96