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; |
|
|
|
|
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
|
|
|
|
Instead of relying on
global
state, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state