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
21supported categories
5implementation paths
Monolithic library
Testing examples with copy-ready, production-minded PHP.
Each example identifies the exact methods it uses and can be opened independently from the right-side index.
- 3
- examples
- 10
- documented methods
strictXlsxIntegrityValidation()MnbExcel::validateXlsx()MnbExcel::assertValidXlsx()<?php
declare(strict_types=1);
/*
Summary:
Validate package relationships, required parts, content types, and XML after generating a
workbook.
Implementation note:
XLSX saves are validated automatically. The public validation methods are useful for uploaded
fixtures, CI checks, and explicit release assertions.
*/
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);MnbExcel::fromArray()textColumns()MnbExcel::read()toArray()<?php
declare(strict_types=1);
/*
Summary:
Write a fixture workbook, read it back through the public reader, and assert that identifiers
and values survive the complete XLSX path.
Implementation note:
Round-trip tests catch reader/writer interaction bugs that package-level XML validation cannot
detect, especially around types, dates, formulas, and leading zeros.
*/
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);MnbExcel::environmentCheck()MnbExcel::environmentAlert()MnbExcel::environmentAlertMessage()<?php
declare(strict_types=1);
/*
Summary:
Report whether the PHP runtime has the extensions and optional capabilities required by the
application workflow.
Implementation note:
Run this in deployment health checks and CI. Native ZIP/XMLReader support remains strongly
recommended for true bounded-memory processing of huge files.
*/
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;No matching example found.Try a method name, task, or result.
Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue