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
01Validate generated XLSX integrityValidate package relationships, required parts, content types, and XML after generating a workbook.
EasyDirect API+
Validate package relationships, required parts, content types, and XML after generating a workbook.
strictXlsxIntegrityValidation()MnbExcel::validateXlsx()MnbExcel::assertValidXlsx()<?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);02Round-trip test workbook valuesWrite a fixture workbook, read it back through the public reader, and assert that identifiers and values survive the complete XLSX path.
MediumDirect API+
Write a fixture workbook, read it back through the public reader, and assert that identifiers and values survive the complete XLSX path.
MnbExcel::fromArray()textColumns()MnbExcel::read()toArray()<?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);03Check runtime capabilitiesReport whether the PHP runtime has the extensions and optional capabilities required by the application workflow.
EasyDirect API+
Report whether the PHP runtime has the extensions and optional capabilities required by the application workflow.
MnbExcel::environmentCheck()MnbExcel::environmentAlert()MnbExcel::environmentAlertMessage()<?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;Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue