Completed
Push — develop ( 98b532...40efcd )
by Adrien
27:48
created

SampleTest::testSample()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 8
rs 9.4285
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Sample;
4
5
use PhpOffice\PhpSpreadsheet\Helper\Sample;
6
use PHPUnit_Framework_TestCase;
7
8
class SampleTest extends PHPUnit_Framework_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
        // Unfortunately some tests are too long be ran with code-coverage
34
        // analysis on Travis, so we need to exclude them
35
        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...
36
        if (in_array('--coverage-clover', $argv)) {
37
            $tooLongToBeCovered = [
38
                'Basic/06_Largescale.php',
39
                'Basic/13_CalculationCyclicFormulae.php',
40
            ];
41
            $skipped = array_merge($skipped, $tooLongToBeCovered);
42
        }
43
44
        $helper = new Sample();
45
        $result = [];
46
        foreach ($helper->getSamples() as $samples) {
47
            foreach ($samples as $sample) {
0 ignored issues
show
Bug introduced by
The expression $samples of type string is not traversable.
Loading history...
48
                if (!in_array($sample, $skipped)) {
49
                    $file = '../samples/' . $sample;
50
                    $result[] = [$file];
51
                }
52
            }
53
        }
54
55
        return $result;
56
    }
57
}
58