ExcelTest::testCreation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
/*
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace Symball\ReportBundle\Tests\Unit;
10
11
/* The base PHPUnit test class */
12
use PHPUnit\Framework\TestCase;
13
14
use Symball\ReportBundle\Service\Excel;
15
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
16
17
/* Extend the default PHPUnit test case */
18
class ExcelTest extends TestCase
19
{
20
    public function testCreation()
21
    {
22
        $excel = new Excel();
23
        /* Check that it is an object type */
24
        $this->assertEquals(true, is_object($excel));
25
    }
26
    public function testExcelObjectCreation()
27
    {
28
        $excel = new Excel();
29
        $excel->createExcelObject();
30
31
        $this->assertEquals('PHPExcel', get_class($excel->getExcelObject()));
32
    }
33
34
    public function testSheetCreation()
35
    {
36
        $excel = new Excel();
37
38
        $this->assertEquals(0, $excel->getNumberOfSheets());
39
40
        $excel->newSheet();
41
        $this->assertEquals('sheet-1', $excel->getCurrentSheetTitle());
42
        $this->assertEquals(1, $excel->getNumberOfSheets());
43
44
        $excel->newSheet('test sheet');
45
        $this->assertEquals('test sheet', $excel->getCurrentSheetTitle());
46
        $this->assertEquals(2, $excel->getNumberOfSheets());
47
    }
48
49
    public function testReportPath()
50
    {
51
        $excel = new Excel();
52
        $excel->setReportPath(getcwd());
53
        $this->assertEquals(getcwd(), $excel->getReportPath());
54
    }
55
56
    public function testUnwritableReportPath()
57
    {
58
        $excel = new Excel();
59
60
        $this->expectException(IOExceptionInterface::class);
61
62
        $excel->setReportPath('/this/is/unwritable');
63
    }
64
65
    public function testNonExistentReportPath()
66
    {
67
        $excel = new Excel();
68
        $path = '/this/path/does/not/exist';
69
70
        try {
71
            $excel->setReportPath($path, false);
72
        } catch (\Exception $ex) {
73
            // General exception
74
            $this->assertEquals(0, $ex->getCode());
75
            $this->assertEquals('Report path does not exist: ' . $path, $ex->getMessage());
76
        }
77
    }
78
79
    public function testOutputFormat()
80
    {
81
        $excel = new Excel();
82
        $this->assertEquals('Excel2007', $excel->getOutputFormat());
83
84
        $excel->setOutputFormat('CSV');
85
        $this->assertEquals('CSV', $excel->getOutputFormat());
86
    }
87
88
    public function testUnsupportedOutputFormat()
89
    {
90
91
        $excel = new Excel();
92
        $type = 'NON_EXISTENT_TYPE';
93
94
        try {
95
            $excel->setOutputFormat($type);
96
        } catch (\Exception $ex) {
97
            // General exception
98
            $this->assertEquals(0, $ex->getCode());
99
            $this->assertEquals('Output format not supported: ' . $type, $ex->getMessage());
100
        }
101
    }
102
}
103