MNB PHPExcelDeveloper Guide
Production guide

Test Spreadsheet Features Reliably

Test values, workbook structure, security, integrations, and large-file behavior without brittle binary comparisons.

Updated

Full packageCI readyFixtures
LevelAdvancedReading time13 minPackageAny installed module
validateXlsx()assertValidXlsx()inspect()environmentCheck()

What you will learn

  • Test workbook meaning instead of raw ZIP bytes.
  • Use temporary directories and deterministic fixtures.
  • Build a CI matrix for optional extensions and database drivers.

Test round-trip values#

Round-trip test
$path = sys_get_temp_dir() . '/mnb-test-' . bin2hex(random_bytes(6)) . '.xlsx';

MnbExcel::fromArray([
    ['SKU' => 'A-1', 'Amount' => 12.50],
])->withHeader()->save($path);

$rows = MnbExcel::read($path)
    ->withHeaderRow(1)
    ->toArray();

assert($rows[0]['SKU'] === 'A-1');
assert((float) $rows[0]['Amount'] === 12.50);

unlink($path);

Validate the XLSX package#

PHP
MnbExcel::assertValidXlsx($path, [
    'strict' => true,
]);

$inspection = MnbExcel::inspect($path);

Test encryption as behavior#

PHP
MnbExcel::encryptXlsx($plain, $encrypted, 'TestPassword!');

assert(MnbExcel::isEncryptedXlsx($encrypted));

$rows = MnbExcel::read($encrypted, [
    'password' => 'TestPassword!',
])->toArray();

try {
    MnbExcel::read($encrypted, ['password' => 'wrong'])->toArray();
    throw new RuntimeException('Wrong password unexpectedly succeeded.');
} catch (Throwable) {
    // Expected failure.
}

Use a capability matrix in CI#

JobPurpose
PHP 8.1 minimumProtect the declared platform floor.
Current PHPCatch new deprecations and behavior changes.
ZIP/XMLReader enabledExercise native streaming paths.
Portable fallbackExercise pure-PHP compatibility paths.
MySQL/PostgreSQL/SQLite driverExercise SQL imports and PDO queues/schedules.
LibreOffice smoke testOpen and resave representative generated workbooks.