mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-28 02:58:26 +00:00
e4e99b8a73
* Permit Date/Time Entered on Spreadsheet to be Calculated as Float Fix #1416. I do not entirely understand the use case for this old issue, but resolving it seems straightforward. Issue complains that user-entered date/time fields may be interpreted as either float or int when PhpSpreadsheet reads them. Issue suggests getCalculatedValue treat all date/time fields as float; that seems like a breaking change. However, adding an option to permit it seems okay. That option might be implemented as either a property of Calculation, or a static property of Cell. Since the changed logic is found in Cell (and Shared/Date), I opted for the latter. In Cell, the property `$parent` is incorrectly described in doc block as `Cells`, and should be `?Cells`. This change eliminates some Phpstan and Scrutinizer problems, and should allow the elimination of some try/catch blocks - I have not done an exhaustive search for those. Calls to `isDateTime` could have affected activeSheet and selectedCells; they no longer can. Optional parameters are added to it and the functions it calls to accommodate the new functionality; the defaults for the new parameters will, of course, return the same result as the earlier versions of the functions would have returned. * Scrutinizer - Self-inflicted Tests used constant which I deprecated.
79 lines
2.1 KiB
PHP
79 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Cell;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
|
use PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class CellDetachTest extends TestCase
|
|
{
|
|
/** @var ?Spreadsheet */
|
|
private $spreadsheet;
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
if ($this->spreadsheet !== null) {
|
|
$this->spreadsheet->disconnectWorksheets();
|
|
$this->spreadsheet = null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerMethodName
|
|
*/
|
|
public function testDetach(string $method): void
|
|
{
|
|
$this->expectException(SpreadsheetException::class);
|
|
$this->expectExceptionMessage('is not bound to a worksheet');
|
|
$this->spreadsheet = new Spreadsheet();
|
|
$sheet = $this->spreadsheet->getActiveSheet();
|
|
$sheet->getCell('A1')->detach();
|
|
if (method_exists(Cell::class, $method)) {
|
|
$sheet->getCell('A1')->$method();
|
|
} else {
|
|
self::fail("Cell method $method does not exist");
|
|
}
|
|
}
|
|
|
|
public function providerMethodName(): array
|
|
{
|
|
return [
|
|
['updateInCollection'],
|
|
['getColumn'],
|
|
['getRow'],
|
|
['hasDataValidation'],
|
|
['getDataValidation'],
|
|
['hasHyperlink'],
|
|
['getHyperlink'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerMethodNameSet
|
|
*/
|
|
public function testDetachSet(string $method): void
|
|
{
|
|
$this->expectException(SpreadsheetException::class);
|
|
$this->expectExceptionMessage('is not bound to a worksheet');
|
|
$this->spreadsheet = new Spreadsheet();
|
|
$sheet = $this->spreadsheet->getActiveSheet();
|
|
$sheet->getCell('A1')->detach();
|
|
if (method_exists(Cell::class, $method)) {
|
|
$sheet->getCell('A1')->$method(null);
|
|
} else {
|
|
self::fail("Cell method $method does not exist");
|
|
}
|
|
}
|
|
|
|
public function providerMethodNameSet(): array
|
|
{
|
|
return [
|
|
['setDataValidation'],
|
|
['setHyperlink'],
|
|
['setValue'],
|
|
];
|
|
}
|
|
}
|