Completed
Push — master ( c3d1ce...591f7c )
by Adrien
08:28 queued 11s
created

SampleTest::providerSample()   B

Complexity

Conditions 6
Paths 16

Size

Total Lines 40
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 6
eloc 22
c 2
b 0
f 0
nc 16
nop 0
dl 0
loc 40
rs 8.9457
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): void
18
    {
19
        // Suppress output to console
20
        $this->setOutputCallback(function (): void {
21
        });
22
23
        require $sample;
24
25
        self::assertTrue(true);
26
    }
27
28
    public function providerSample()
29
    {
30
        $skipped = [
31
            'Chart/32_Chart_read_write_PDF.php', // Unfortunately JpGraph is not up to date for latest PHP and raise many warnings
32
            'Chart/32_Chart_read_write_HTML.php', // idem
33
        ];
34
        // TCPDF and DomPDF libraries don't support PHP8 yet
35
        if (\PHP_VERSION_ID >= 80000) {
36
            $skipped = array_merge(
37
                $skipped,
38
                [
39
                    'Pdf/21_Pdf_Domdf.php',
40
                    'Pdf/21_Pdf_TCPDF.php',
41
                ]
42
            );
43
        }
44
45
        // Unfortunately some tests are too long be ran with code-coverage
46
        // analysis on Travis, so we need to exclude them
47
        global $argv;
48
        if (in_array('--coverage-clover', $argv)) {
49
            $tooLongToBeCovered = [
50
                'Basic/06_Largescale.php',
51
                'Basic/13_CalculationCyclicFormulae.php',
52
            ];
53
            $skipped = array_merge($skipped, $tooLongToBeCovered);
54
        }
55
56
        $helper = new Sample();
57
        $result = [];
58
        foreach ($helper->getSamples() as $samples) {
59
            foreach ($samples as $sample) {
0 ignored issues
show
Bug introduced by
The expression $samples of type string is not traversable.
Loading history...
60
                if (!in_array($sample, $skipped)) {
61
                    $file = 'samples/' . $sample;
62
                    $result[] = [$file];
63
                }
64
            }
65
        }
66
67
        return $result;
68
    }
69
}
70