Completed
Push — master ( 25fb08...38f401 )
by Mewes
02:25
created

CsvTwigTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 1 Features 2
Metric Value
wmc 5
c 2
b 1
f 2
lcom 1
cbo 2
dl 0
loc 62
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A formatProvider() 0 4 1
A testBasic() 0 13 2
A testDocumentTemplate() 0 13 2
1
<?php
2
3
namespace MewesK\TwigExcelBundle\Tests\Twig;
4
5
use Twig_Error_Runtime;
6
7
/**
8
 * Class CsvTwigTest
9
 * @package MewesK\TwigExcelBundle\Tests\Twig
10
 */
11
class CsvTwigTest extends AbstractTwigTest
12
{
13
    protected static $TEMP_PATH = '/../../tmp/csv/';
14
15
    //
16
    // PhpUnit
17
    //
18
19
    /**
20
     * @return array
21
     */
22
    public function formatProvider()
23
    {
24
        return [['csv']];
25
    }
26
27
    //
28
    // Tests
29
    //
30
31
    /**
32
     * @param string $format
33
     *
34
     * @throws \PHPExcel_Exception
35
     *
36
     * @dataProvider formatProvider
37
     */
38
    public function testBasic($format)
39
    {
40
        try {
41
            $path = $this->getDocument('documentSimple', $format);
42
43
            static::assertTrue(file_exists($path), 'File does not exist');
44
            static::assertGreaterThan(0, filesize($path), 'File is empty');
45
            static::assertEquals("\"Foo\",\"Bar\"".PHP_EOL."\"Hello\",\"World\"".PHP_EOL, file_get_contents($path), 'Unexpected content');
46
47
        } catch (Twig_Error_Runtime $e) {
48
            static::fail($e->getMessage());
49
        }
50
    }
51
52
    /**
53
     * @param string $format
54
     *
55
     * @throws \PHPExcel_Exception
56
     *
57
     * @dataProvider formatProvider
58
     */
59
    public function testDocumentTemplate($format)
60
    {
61
        try {
62
            $path = $this->getDocument('documentTemplate.csv', $format);
63
64
            static::assertTrue(file_exists($path), 'File does not exist');
65
            static::assertGreaterThan(0, filesize($path), 'File is empty');
66
            static::assertEquals("\"Hello2\",\"World\"".PHP_EOL."\"Foo\",\"Bar2\"".PHP_EOL, file_get_contents($path), 'Unexpected content');
67
68
        } catch (Twig_Error_Runtime $e) {
69
            static::fail($e->getMessage());
70
        }
71
    }
72
}
73