Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Writer\Xlsx; use..

Decoded Output download

<?php

declare(strict_types=1);

namespace PhpOffice\PhpSpreadsheetTests\Writer\Xlsx;

use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcException;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;

class CalculationErrorTest extends AbstractFunctional
{
    /** @var ?Spreadsheet */
    private ?Spreadsheet $spreadsheet = null;

    /** @var ?Spreadsheet */
    private ?Spreadsheet $reloadedSpreadsheet = null;

    protected function tearDown(): void
    {
        if ($this->spreadsheet !== null) {
            $this->spreadsheet->disconnectWorksheets();
            $this->spreadsheet = null;
        }
        if ($this->reloadedSpreadsheet !== null) {
            $this->reloadedSpreadsheet->disconnectWorksheets();
            $this->reloadedSpreadsheet = null;
        }
    }

    public function testCalculationExceptionSuppressed(): void
    {
        $this->spreadsheet = new Spreadsheet();
        $sheet = $this->spreadsheet->getActiveSheet();
        $calculation = Calculation::getInstance($this->spreadsheet);
        self::assertFalse($calculation->getSuppressFormulaErrors());
        $calculation->setSuppressFormulaErrors(true);
        $sheet->getCell('A1')->setValue('=SUM(');
        $sheet->getCell('A2')->setValue('=2+3');
        $this->reloadedSpreadsheet = $this->writeAndReload($this->spreadsheet, 'Xlsx');
        $rcalculation = Calculation::getInstance($this->reloadedSpreadsheet);
        self::assertFalse($rcalculation->getSuppressFormulaErrors());
        $rcalculation->setSuppressFormulaErrors(true);
        $rsheet = $this->reloadedSpreadsheet->getActiveSheet();
        self::assertSame('=SUM(', $rsheet->getCell('A1')->getValue());
        self::assertFalse($rsheet->getCell('A1')->getCalculatedValue());
        self::assertSame('=2+3', $rsheet->getCell('A2')->getValue());
        self::assertSame(5, $rsheet->getCell('A2')->getCalculatedValue());
        $calculation->setSuppressFormulaErrors(false);
        $rcalculation->setSuppressFormulaErrors(false);
    }

    public function testCalculationException(): void
    {
        $this->expectException(CalcException::class);
        $this->expectExceptionMessage("Formula Error: Expecting ')'");
        $this->spreadsheet = new Spreadsheet();
        $sheet = $this->spreadsheet->getActiveSheet();
        $calculation = Calculation::getInstance($this->spreadsheet);
        self::assertFalse($calculation->getSuppressFormulaErrors());
        $sheet->getCell('A1')->setValue('=SUM(');
        $sheet->getCell('A2')->setValue('=2+3');
        $this->reloadedSpreadsheet = $this->writeAndReload($this->spreadsheet, 'Xlsx');
    }
}
 ?>

Did this file decode correctly?

Original Code

<?php

declare(strict_types=1);

namespace PhpOffice\PhpSpreadsheetTests\Writer\Xlsx;

use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcException;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;

class CalculationErrorTest extends AbstractFunctional
{
    /** @var ?Spreadsheet */
    private ?Spreadsheet $spreadsheet = null;

    /** @var ?Spreadsheet */
    private ?Spreadsheet $reloadedSpreadsheet = null;

    protected function tearDown(): void
    {
        if ($this->spreadsheet !== null) {
            $this->spreadsheet->disconnectWorksheets();
            $this->spreadsheet = null;
        }
        if ($this->reloadedSpreadsheet !== null) {
            $this->reloadedSpreadsheet->disconnectWorksheets();
            $this->reloadedSpreadsheet = null;
        }
    }

    public function testCalculationExceptionSuppressed(): void
    {
        $this->spreadsheet = new Spreadsheet();
        $sheet = $this->spreadsheet->getActiveSheet();
        $calculation = Calculation::getInstance($this->spreadsheet);
        self::assertFalse($calculation->getSuppressFormulaErrors());
        $calculation->setSuppressFormulaErrors(true);
        $sheet->getCell('A1')->setValue('=SUM(');
        $sheet->getCell('A2')->setValue('=2+3');
        $this->reloadedSpreadsheet = $this->writeAndReload($this->spreadsheet, 'Xlsx');
        $rcalculation = Calculation::getInstance($this->reloadedSpreadsheet);
        self::assertFalse($rcalculation->getSuppressFormulaErrors());
        $rcalculation->setSuppressFormulaErrors(true);
        $rsheet = $this->reloadedSpreadsheet->getActiveSheet();
        self::assertSame('=SUM(', $rsheet->getCell('A1')->getValue());
        self::assertFalse($rsheet->getCell('A1')->getCalculatedValue());
        self::assertSame('=2+3', $rsheet->getCell('A2')->getValue());
        self::assertSame(5, $rsheet->getCell('A2')->getCalculatedValue());
        $calculation->setSuppressFormulaErrors(false);
        $rcalculation->setSuppressFormulaErrors(false);
    }

    public function testCalculationException(): void
    {
        $this->expectException(CalcException::class);
        $this->expectExceptionMessage("Formula Error: Expecting ')'");
        $this->spreadsheet = new Spreadsheet();
        $sheet = $this->spreadsheet->getActiveSheet();
        $calculation = Calculation::getInstance($this->spreadsheet);
        self::assertFalse($calculation->getSuppressFormulaErrors());
        $sheet->getCell('A1')->setValue('=SUM(');
        $sheet->getCell('A2')->setValue('=2+3');
        $this->reloadedSpreadsheet = $this->writeAndReload($this->spreadsheet, 'Xlsx');
    }
}

Function Calls

None

Variables

None

Stats

MD5 a9e25748258e909dae4559ebeb6133e6
Eval Count 0
Decode Time 83 ms