Completed
Push — develop ( 467c96...874467 )
by Mark
61:29
created

SampleTest::providerSample()   B

Complexity

Conditions 7
Paths 32

Size

Total Lines 41
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 22
nc 32
nop 0
dl 0
loc 41
rs 8.6346
c 0
b 0
f 0
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Helper;
4
5
use PhpOffice\PhpSpreadsheet\Helper\Sample;
6
use PHPUnit\Framework\TestCase;
7
8
class SampleTest extends TestCase
9
{
10
    /**
11
     * @runInSeparateProcess
12
     * @preserveGlobalState disabled
13
     * @dataProvider providerSample
14
     *
15
     * @param mixed $sample
16
     */
17
    public function testSample($sample)
18
    {
19
        // Suppress output to console
20
        $this->setOutputCallback(function () {
21
        });
22
23
        require $sample;
24
    }
25
26
    public function providerSample()
27
    {
28
        $skipped = [
29
            'Chart/32_Chart_read_write_PDF.php', // Unfortunately JpGraph is not up to date for latest PHP and raise many warnings
30
            'Chart/32_Chart_read_write_HTML.php', // idem
31
        ];
32
33
        // TCPDF does not support PHP 7.2
34
        if (version_compare(PHP_VERSION, '7.2.0') >= 0) {
35
            $skipped[] = 'Pdf/21_Pdf_TCPDF.php';
36
        }
37
38
        // DomPDF does not support PHP 7.3
39
        if (version_compare(PHP_VERSION, '7.3.0') >= 0) {
40
            $skipped[] = 'Basic/26_Utf8.php';
41
            $skipped[] = 'Pdf/21_Pdf_Domdf.php';
42
        }
43
44
        // Unfortunately some tests are too long be ran with code-coverage
45
        // analysis on Travis, so we need to exclude them
46
        global $argv;
47
        if (in_array('--coverage-clover', $argv)) {
48
            $tooLongToBeCovered = [
49
                'Basic/06_Largescale.php',
50
                'Basic/13_CalculationCyclicFormulae.php',
51
            ];
52
            $skipped = array_merge($skipped, $tooLongToBeCovered);
53
        }
54
55
        $helper = new Sample();
56
        $result = [];
57
        foreach ($helper->getSamples() as $samples) {
58
            foreach ($samples as $sample) {
0 ignored issues
show
Bug introduced by
The expression $samples of type string is not traversable.
Loading history...
59
                if (!in_array($sample, $skipped)) {
60
                    $file = '../samples/' . $sample;
61
                    $result[] = [$file];
62
                }
63
            }
64
        }
65
66
        return $result;
67
    }
68
}
69