AbstractWriter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 49
dl 0
loc 73
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A export() 0 9 2
A createMockCards() 0 39 1
A createMockExport() 0 19 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApplicationTest\Service\Exporter;
6
7
use Application\Enum\Precision;
8
use Application\Enum\Site;
9
use Application\Model\Card;
10
use Application\Model\Country;
11
use Application\Model\DocumentType;
12
use Application\Model\Export;
13
use Application\Model\Material;
14
use Application\Model\Period;
15
use Application\Service\Exporter\Writer;
16
use PHPUnit\Framework\TestCase;
17
18
class AbstractWriter extends TestCase
19
{
20
    protected function export(Writer $writer, string $tempFile): void
21
    {
22
        $export = $this->createMockExport($tempFile);
23
24
        $writer->initialize($export, 'Test Pptx');
25
        foreach ($this->createMockCards() as $card) {
26
            $writer->write($card);
27
        }
28
        $writer->finalize();
29
    }
30
31
    protected function createMockExport(string $path): Export
32
    {
33
        $export = $this->getMockBuilder(Export::class)
34
            ->onlyMethods(['getId', 'getSite', 'getPath'])
35
            ->getMock();
36
37
        $export->expects(self::any())
38
            ->method('getId')
39
            ->willReturn(333);
40
41
        $export->expects(self::any())
42
            ->method('getSite')
43
            ->willReturn(Site::Dilps);
44
45
        $export->expects(self::once())
46
            ->method('getPath')
47
            ->willReturn($path);
48
49
        return $export;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $export returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return Application\Model\Export.
Loading history...
50
    }
51
52
    protected function createMockCards(): array
53
    {
54
        $card1 = $this->getMockBuilder(Card::class)
55
            ->onlyMethods(['getId'])
56
            ->getMock();
57
58
        $card1->expects(self::any())
59
            ->method('getId')
60
            ->willReturn(111);
61
62
        $card1->setName('test with nothing');
63
64
        $documentType = new DocumentType();
65
        $documentType->setName('document type');
66
        $period = new Period();
67
        $period->setName('period');
68
        $material = new Material();
69
        $material->setName('material');
70
        $country = new Country();
71
        $country->setName('country');
72
73
        $card2 = $this->getMockBuilder(Card::class)
74
            ->onlyMethods(['getId'])
75
            ->getMock();
76
77
        $card2->expects(self::any())
78
            ->method('getId')
79
            ->willReturn(222);
80
81
        $card2->setName('test with stuff');
82
        $card2->setExpandedName('expanded');
83
        $card2->setDocumentType($documentType);
84
        $card2->addPeriod($period);
85
        $card2->addMaterial($material);
86
        $card2->setCountry($country);
87
        $card2->setPrecision(Precision::Building);
88
        $card2->setFilename('dw4jV3zYSPsqE2CB8BcP8ABD0.jpg');
89
90
        return [$card1, $card2];
91
    }
92
}
93