ExcelFileRepositoryTest::testGet()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace Mathielen\ReportWriteEngine\Output\Excel\Persistence;
3
4
class ExcelFileRepositoryTest extends \PHPUnit_Framework_TestCase
5
{
6
7
    /**
8
     * @var ExcelFileRepository
9
     */
10
    private $sut;
11
12
    protected function setUp()
13
    {
14
        $this->sut = new ExcelFileRepository('tests/metadata/template');
15
16
        @unlink('tests/metadata/template/test.xlsx');
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
17
    }
18
19
    protected function teardown()
20
    {
21
        @unlink('tests/metadata/template/test.xlsx');
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
22
    }
23
24
    public function testGet()
25
    {
26
        $actual = $this->sut->get('simple.xlsx');
27
28
        $objReader = new \PHPExcel_Reader_Excel2007();
29
        $expected = $objReader->load('tests/metadata/template/simple.xlsx');
30
31
        $this->assertEquals($expected->getActiveSheet()->toArray(), $actual->getActiveSheet()->toArray());
32
    }
33
34
    public function testSave()
35
    {
36
        $objReader = new \PHPExcel_Reader_Excel2007();
37
        $excel = $objReader->load('tests/metadata/template/simple.xlsx');
38
39
        $actual = $this->sut->save($excel, 'test.xlsx');
40
41
        $this->assertEquals('tests/metadata/template/test.xlsx', $actual);
42
        $this->assertFileExists('tests/metadata/template/test.xlsx');
43
    }
44
45
}
46