1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Port\Excel\Tests; |
4
|
|
|
|
5
|
|
|
use Port\Excel\ExcelReader; |
6
|
|
|
|
7
|
|
|
class ExcelReaderTest extends \PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
public function setUp() |
10
|
|
|
{ |
11
|
|
|
if (!extension_loaded('zip')) { |
12
|
|
|
$this->markTestSkipped(); |
13
|
|
|
} |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public function testCountWithoutHeaders() |
17
|
|
|
{ |
18
|
|
|
$file = new \SplFileObject(__DIR__.'/fixtures/data_no_column_headers.xls'); |
19
|
|
|
$reader = new ExcelReader($file); |
20
|
|
|
$this->assertEquals(3, $reader->count()); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testCountWithHeaders() |
24
|
|
|
{ |
25
|
|
|
$file = new \SplFileObject(__DIR__.'/fixtures/data_column_headers.xlsx'); |
26
|
|
|
$reader = new ExcelReader($file, 0); |
27
|
|
|
$this->assertEquals(3, $reader->count()); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testIterate() |
31
|
|
|
{ |
32
|
|
|
$file = new \SplFileObject(__DIR__.'/fixtures/data_column_headers.xlsx'); |
33
|
|
|
$reader = new ExcelReader($file, 0); |
34
|
|
|
foreach ($reader as $row) { |
35
|
|
|
$this->assertInternalType('array', $row); |
36
|
|
|
$this->assertEquals(array('id', 'number', 'description'), array_keys($row)); |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testMultiSheet() |
41
|
|
|
{ |
42
|
|
|
$file = new \SplFileObject(__DIR__.'/fixtures/data_multi_sheet.xls'); |
43
|
|
|
$sheet1reader = new ExcelReader($file, null, 0); |
44
|
|
|
$this->assertEquals(3, $sheet1reader->count()); |
45
|
|
|
|
46
|
|
|
$sheet2reader = new ExcelReader($file, null, 1); |
47
|
|
|
$this->assertEquals(2, $sheet2reader->count()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testMaxRowNumb() |
51
|
|
|
{ |
52
|
|
|
$file = new \SplFileObject(__DIR__.'/fixtures/data_no_column_headers.xls'); |
53
|
|
|
$reader = new ExcelReader($file, null, null, null, 1000); |
|
|
|
|
54
|
|
|
$this->assertEquals(3, $reader->count()); |
55
|
|
|
|
56
|
|
|
// Without $maxRows, this faulty file causes OOM because of an extremely |
57
|
|
|
//high last row number |
58
|
|
|
$file = new \SplFileObject(__DIR__.'/fixtures/data_extreme_last_row.xlsx'); |
59
|
|
|
|
60
|
|
|
$max = 5; |
61
|
|
|
$reader = new ExcelReader($file, null, null, null, $max); |
|
|
|
|
62
|
|
|
$this->assertEquals($max, $reader->count()); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: