Completed
Push — develop ( 1a2a68...2c96a0 )
by Adrien
78:44 queued 38:11
created

SampleTest::testSample()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 8
rs 9.4285
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests;
4
5
class SampleTest extends \PHPUnit_Framework_TestCase
6
{
7
    /**
8
     * @runInSeparateProcess
9
     * @preserveGlobalState disabled
10
     * @dataProvider providerSample
11
     */
12
    public function testSample($sample)
13
    {
14
        // Suppress output to console
15
        $this->setOutputCallback(function () {
16
        });
17
18
        require $sample;
19
    }
20
21
    public function providerSample()
22
    {
23
        $skipped = [
24
            '07 Reader PCLZip', // Excel2007 cannot load file, leading to OpenOffice trying to and crashing. This is a bug that should be fixed
25
            '20 Read OOCalc with PCLZip', // Crash: Call to undefined method \PhpOffice\PhpSpreadsheet\Shared\ZipArchive::statName()
26
            '21 Pdf', // for now we don't have 3rdparty libs to tests PDF, but it should be added
27
        ];
28
29
        // Unfortunately some tests are too long be ran with code-coverage
30
        // analysis on Travis, so we need to exclude them
31
        global $argv;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
32
        if (in_array('--coverage-clover', $argv)) {
33
            $tooLongToBeCovered = [
34
                '06 Largescale',
35
                '06 Largescale with cellcaching',
36
                '06 Largescale with cellcaching sqlite',
37
                '06 Largescale with cellcaching sqlite3',
38
            ];
39
            $skipped = array_merge($skipped, $tooLongToBeCovered);
40
        }
41
42
        $helper = new \PhpOffice\PhpSpreadsheet\Helper\Sample();
43
        $samples = [];
44
        foreach ($helper->getSamples() as $name => $sample) {
45
            if (!in_array($name, $skipped)) {
46
                $samples[$name] = [$sample];
47
            }
48
        }
49
50
        return $samples;
51
    }
52
}
53