File tree Expand file tree Collapse file tree 4 files changed +33
-3
lines changed Expand file tree Collapse file tree 4 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -430,7 +430,7 @@ public function __construct()
430
430
*/
431
431
public function canRead (string $ filename ): bool
432
432
{
433
- if (! File::testFileNoThrow ($ filename )) {
433
+ if (File::testFileNoThrow ($ filename ) === false ) {
434
434
return false ;
435
435
}
436
436
@@ -440,6 +440,9 @@ public function canRead(string $filename): bool
440
440
441
441
// get excel data
442
442
$ ole ->read ($ filename );
443
+ if ($ ole ->wrkbook === null ) {
444
+ throw new Exception ('The filename ' . $ filename . ' is not recognised as a Spreadsheet file ' );
445
+ }
443
446
444
447
return true ;
445
448
} catch (PhpSpreadsheetException $ e ) {
@@ -449,7 +452,7 @@ public function canRead(string $filename): bool
449
452
450
453
public function setCodepage (string $ codepage ): void
451
454
{
452
- if (! CodePage::validate ($ codepage )) {
455
+ if (CodePage::validate ($ codepage ) === false ) {
453
456
throw new PhpSpreadsheetException ('Unknown codepage: ' . $ codepage );
454
457
}
455
458
Original file line number Diff line number Diff line change @@ -134,7 +134,7 @@ public function read(string $filename): void
134
134
135
135
$ bbdBlocks = $ this ->numBigBlockDepotBlocks ;
136
136
137
- if ($ this ->numExtensionBlocks != 0 ) {
137
+ if ($ this ->numExtensionBlocks !== 0 ) {
138
138
$ bbdBlocks = (self ::BIG_BLOCK_SIZE - self ::BIG_BLOCK_DEPOT_BLOCKS_POS ) / 4 ;
139
139
}
140
140
Original file line number Diff line number Diff line change @@ -108,6 +108,33 @@ public function providerIdentify(): array
108
108
];
109
109
}
110
110
111
+ public function testIdentifyInvalid (): void
112
+ {
113
+ $ file = __DIR__ . '/../data/Reader/NotASpreadsheetFile.doc ' ;
114
+
115
+ $ this ->expectException (ReaderException::class);
116
+ $ this ->expectExceptionMessage ('Unable to identify a reader for this file ' );
117
+ IOFactory::identify ($ file );
118
+ }
119
+
120
+ public function testCreateInvalid (): void
121
+ {
122
+ $ file = __DIR__ . '/../data/Reader/NotASpreadsheetFile.doc ' ;
123
+
124
+ $ this ->expectException (ReaderException::class);
125
+ $ this ->expectExceptionMessage ('Unable to identify a reader for this file ' );
126
+ IOFactory::createReaderForFile ($ file );
127
+ }
128
+
129
+ public function testLoadInvalid (): void
130
+ {
131
+ $ file = __DIR__ . '/../data/Reader/NotASpreadsheetFile.doc ' ;
132
+
133
+ $ this ->expectException (ReaderException::class);
134
+ $ this ->expectExceptionMessage ('Unable to identify a reader for this file ' );
135
+ IOFactory::load ($ file );
136
+ }
137
+
111
138
public function testFormatAsExpected (): void
112
139
{
113
140
$ fileName = 'samples/templates/30template.xls ' ;
You can’t perform that action at this time.
0 commit comments