MNB PHPExcelDeveloper Guide
v2.0.5

Testing examples

Testing Excel examples, explained clearly.

Open a focused example to see the implementation path, copy-ready PHP, expected workbook behavior, and the production boundary that matters.

3examples in this category
21focused categories
5implementation paths
01
Validate generated XLSX integrity

Validate package relationships, required parts, content types, and XML after generating a workbook.

EasyDirect API
strictXlsxIntegrityValidation()MnbExcel::validateXlsx()MnbExcel::assertValidXlsx()
validate-generated-xlsx-integrity.php
<?php

use Mnb\PHPExcel\MnbExcel;

$output = __DIR__ . '/output/invoices.xlsx';

MnbExcel::fromArray([
    ['invoice' => 'INV-001', 'customer' => 'Ava', 'total' => 1250.50],
    ['invoice' => 'INV-002', 'customer' => 'Noah', 'total' => 980.00],
])
    ->withHeader()
    ->strictXlsxIntegrityValidation()
    ->save($output);

$result = MnbExcel::validateXlsx($output);

if (!$result['valid']) {
    throw new RuntimeException(implode('; ', $result['errors']));
}

MnbExcel::assertValidXlsx($output);
02
Round-trip test workbook values

Write a fixture workbook, read it back through the public reader, and assert that identifiers and values survive the complete XLSX path.

MediumDirect API
MnbExcel::fromArray()textColumns()MnbExcel::read()toArray()
round-trip-test-workbook-values.php
<?php

use Mnb\PHPExcel\MnbExcel;

$expected = [
    ['student_id' => '000123', 'name' => 'Ava', 'marks' => 92],
    ['student_id' => '000124', 'name' => 'Noah', 'marks' => 88],
];

$path = sys_get_temp_dir() . '/mnb-round-trip.xlsx';

MnbExcel::fromArray($expected)
    ->withHeader()
    ->textColumns(['student_id'])
    ->save($path);

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

if ($actual !== $expected) {
    throw new RuntimeException('Round-trip values changed.');
}

unlink($path);
03
Check runtime capabilities

Report whether the PHP runtime has the extensions and optional capabilities required by the application workflow.

EasyDirect API
MnbExcel::environmentCheck()MnbExcel::environmentAlert()MnbExcel::environmentAlertMessage()
check-runtime-capabilities.php
<?php

use Mnb\PHPExcel\MnbExcel;

$environment = MnbExcel::environmentCheck();
$alert = MnbExcel::environmentAlert();

if (!$alert['ready']) {
    fwrite(STDERR, $alert['message'] . PHP_EOL);
    exit(1);
}

print_r($environment);
echo MnbExcel::environmentAlertMessage() . PHP_EOL;