testHorizontalSinglelevelReport()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace Mathielen\ReportWriteEngine;
3
4
use Mathielen\ReportWriteEngine\Output\Excel\Persistence\ExcelFileRepository;
5
use Mathielen\ReportWriteEngine\Engine\Renderer\HorizontalRenderer;
6
use Mathielen\ReportWriteEngine\Engine\Renderer\RendererInterface;
7
use Mathielen\ReportWriteEngine\Engine\Renderer\VerticalRenderer;
8
use Mathielen\ReportWriteEngine\Engine\RendererRepository;
9
use Mathielen\ReportWriteEngine\Engine\ReportConfig;
10
use Mathielen\ReportWriteEngine\Output\Excel\Writer\ExcelReportWriter;
11
use Monolog\Handler\StreamHandler;
12
use Monolog\Logger;
13
14
class ExcelReportWriterTest extends \PHPUnit_Framework_TestCase
15
{
16
17
    /**
18
     * @var ExcelReportWriter
19
     */
20
    private $sut;
21
22
    private $templateRepo;
23
24
    protected function setUp()
25
    {
26
        $logger = new Logger('rendertest');
27
        $logger->pushHandler(new StreamHandler('php://stdout', Logger::DEBUG));
28
29
        $rendererRepository = new RendererRepository();
30
        $rendererRepository->add(
31
            RendererInterface::ORIENTATION_VERTICAL,
32
            new VerticalRenderer()
33
        );
34
        $rendererRepository->add(
35
            RendererInterface::ORIENTATION_HORIZONTAL,
36
            new HorizontalRenderer()
37
        );
38
39
        $targetRepo = new ExcelFileRepository('tests/metadata/output');
40
        $this->templateRepo = new ExcelFileRepository('tests/metadata/template');
41
        $this->sut = new ExcelReportWriter($targetRepo, $this->templateRepo, $rendererRepository, $logger);
42
    }
43
44
    public function testSimpleReport()
45
    {
46
        $reportData = json_decode(file_get_contents('tests/metadata/data/testSimpleReport.json'), true);
47
48
        $reportConfig = new ReportConfig('simple.xlsx', 'simple-output.xlsx');
49
        $this->sut->write($reportData, $reportConfig);
50
    }
51
52
    public function testVerticalSinglelevelReport()
53
    {
54
        $reportData = json_decode(file_get_contents('tests/metadata/data/testSinglelevelReport.json'), true);
55
56
        $reportConfig = new ReportConfig('singlelevel.xlsx', 'singlelevel-output.xlsx');
57
        $this->sut->write($reportData, $reportConfig);
58
    }
59
60
    public function testVerticalMultilevelReport()
61
    {
62
        $reportData = json_decode(file_get_contents('tests/metadata/data/testMultilevelReport.json'), true);
63
64
        $reportConfig = new ReportConfig('multilevel.xlsx', 'multilevel-output.xlsx');
65
        $this->sut->write($reportData, $reportConfig);
66
    }
67
68
    public function testVerticalMultiSamelevelReport()
69
    {
70
        $reportData = json_decode(file_get_contents('tests/metadata/data/testMultiSamelevelReport.json'), true);
71
72
        $reportConfig = new ReportConfig('multisamelevel.xlsx', 'multisamelevel-output.xlsx');
73
        $this->sut->write($reportData, $reportConfig);
74
    }
75
76 View Code Duplication
    public function testHorizontalSinglelevelReport()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
    {
78
        $reportData = json_decode(file_get_contents('tests/metadata/data/testSinglelevelReport.json'), true);
79
80
        $this->templateRepo->setMetadata('horizontal-singlelevel.xlsx', ['LEVEL1'=> RendererInterface::ORIENTATION_HORIZONTAL]);
81
82
        $reportConfig = new ReportConfig('horizontal-singlelevel.xlsx', 'horizontal-singlelevel-output.xlsx');
83
        $this->sut->write($reportData, $reportConfig);
84
    }
85
86 View Code Duplication
    public function testHorizontalMultilevelReport()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
87
    {
88
        $reportData = json_decode(file_get_contents('tests/metadata/data/testMultilevelReport.json'), true);
89
90
        $this->templateRepo->setMetadata('horizontal-multilevel.xlsx', ['LEVEL2'=> RendererInterface::ORIENTATION_HORIZONTAL]);
91
92
        $reportConfig = new ReportConfig('horizontal-multilevel.xlsx', 'horizontal-multilevel-output.xlsx');
93
        $this->sut->write($reportData, $reportConfig);
94
    }
95
96 View Code Duplication
    public function testFinalReport()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
97
    {
98
        $reportData = json_decode(file_get_contents('tests/metadata/data/commission.json'), true);
99
100
        $this->templateRepo->setMetadata('commission.xlsx', ['SERVICEPARTNER'=> RendererInterface::ORIENTATION_HORIZONTAL]);
101
102
        $reportConfig = new ReportConfig('commission.xlsx', 'commission-output.xlsx');
103
        $this->sut->write($reportData, $reportConfig);
104
    }
105
106
}
107