mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-04 14:38:16 +00:00
33eefe7c9d
* Resolve Phpstan Messages - FINALE - Shared/OLE Reduce number of Phpstan messages by addressing their issues. This is the last of a series of related tickets to achieve that end. Only a handful of messages will be left in Phpstan baseline after this change is merged. Shared/Ole.php and Shared/Ole/ChainedBlockStream.php were completely uncovered in the test suite. So I wrote some tests and found they didn't work at all. There were 2 problems. The first was that ChainedBlockStream checks for a mode of `r`, but Ole invokes it with mode `rb`. ChainedBlockStream will now just check the first character of the mode. The second was a more interesting problem. Ole was reading "an *unsigned* long". However, what it should have been reading was "a 32-bit *signed* long". The irony of this mismatch is that, once the mode problem was corrected, 32-bit Php handled Ole and ChainedBlockStream correctly, but 64-bit Php did not. The code is corrected to work properly for both 32- and 64-bit. * Scrutinizer 2 dead assignments - sufficient to just make calls which are expected to fail.
71 lines
2.2 KiB
PHP
71 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Shared;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
|
|
use PhpOffice\PhpSpreadsheet\Shared\OLE;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Throwable;
|
|
|
|
class OLETest extends TestCase
|
|
{
|
|
public function testReadNotOle(): void
|
|
{
|
|
$this->expectException(ReaderException::class);
|
|
$this->expectExceptionMessage('File doesn\'t seem to be an OLE container.');
|
|
$ole = new OLE();
|
|
$ole->read(__FILE__);
|
|
}
|
|
|
|
public function testReadNotExist(): void
|
|
{
|
|
$this->expectException(ReaderException::class);
|
|
$this->expectExceptionMessage('Can\'t open file');
|
|
$ole = new OLE();
|
|
$ole->read(__FILE__ . '.xxx');
|
|
}
|
|
|
|
public function testReadOleStreams(): void
|
|
{
|
|
$dataDir = 'tests/data/Shared/OLERead/';
|
|
$ole = new OLE();
|
|
$oleData = $ole->read('tests/data/Reader/XLS/sample.xls');
|
|
self::assertEquals(
|
|
file_get_contents($dataDir . 'wrkbook'),
|
|
$oleData
|
|
);
|
|
self::assertSame(512, $ole->bigBlockSize);
|
|
self::assertSame(64, $ole->smallBlockSize);
|
|
self::assertSame(4096, $ole->bigBlockThreshold);
|
|
self::assertSame(1024, $ole->getBlockOffset(1));
|
|
}
|
|
|
|
public function testChainedWriteMode(): void
|
|
{
|
|
$ole = new OLE\ChainedBlockStream();
|
|
$openedPath = '';
|
|
self::assertFalse($ole->stream_open('whatever', 'w', 0, $openedPath));
|
|
|
|
try {
|
|
$ole->stream_open('whatever', 'w', STREAM_REPORT_ERRORS, $openedPath);
|
|
self::fail('Error in statement above should be caught');
|
|
} catch (Throwable $e) {
|
|
self::assertSame('Only reading is supported', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function testChainedBadPath(): void
|
|
{
|
|
$ole = new OLE\ChainedBlockStream();
|
|
$openedPath = '';
|
|
self::assertFalse($ole->stream_open('whatever', 'r', 0, $openedPath));
|
|
|
|
try {
|
|
$ole->stream_open('whatever', 'r', STREAM_REPORT_ERRORS, $openedPath);
|
|
self::fail('Error in statement above should be caught');
|
|
} catch (Throwable $e) {
|
|
self::assertSame('OLE stream not found', $e->getMessage());
|
|
}
|
|
}
|
|
}
|