Skip to content

add tests to support issue 4476 #4519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions tests/PhpSpreadsheetTests/Reader/Ods/Issue4476Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;

use PhpOffice\PhpSpreadsheet\Reader\Ods;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PHPUnit\Framework\TestCase;

class Issue4476Test extends TestCase
{
public function testIssue2810(): void
{
// Active sheet with title of '0' wasn't found
$filename = 'tests/data/Reader/Ods/issue.4476.ods';
$reader = new Ods();
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
$rawValue = $sheet->getCell('A1')->getValue();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add:

/** @var float|int */

before this statement to eliminate the Phpstan error.

$dt = Date::excelToDateTimeObject($rawValue);

Check failure on line 21 in tests/PhpSpreadsheetTests/Reader/Ods/Issue4476Test.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $excelTimestamp of static method PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject() expects float|int, mixed given.
self::assertSame('2016-06-01 13:37', $dt->format('Y-m-d H:i'));
$spreadsheet->disconnectWorksheets();
}
}
26 changes: 26 additions & 0 deletions tests/PhpSpreadsheetTests/Reader/Xlsx/Issue4476Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;

use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PHPUnit\Framework\TestCase;

class Issue4476Test extends TestCase
{
public function testIssue4476(): void
{
$filename = 'tests/data/Reader/XLSX/issue.4476.xlsx';

$reader = new Xlsx();
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
$rawValue = $sheet->getCell('A1')->getValue();
$dt = Date::excelToDateTimeObject($rawValue);

Check failure on line 21 in tests/PhpSpreadsheetTests/Reader/Xlsx/Issue4476Test.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $excelTimestamp of static method PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject() expects float|int, mixed given.

self::assertSame('2016-06-01 13:37', $dt->format('Y-m-d H:i'));

Check failure on line 23 in tests/PhpSpreadsheetTests/Reader/Xlsx/Issue4476Test.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

Failed asserting that two strings are identical.

Check failure on line 23 in tests/PhpSpreadsheetTests/Reader/Xlsx/Issue4476Test.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

Failed asserting that two strings are identical.

Check failure on line 23 in tests/PhpSpreadsheetTests/Reader/Xlsx/Issue4476Test.php

View workflow job for this annotation

GitHub Actions / PHP 8.3

Failed asserting that two strings are identical.

Check failure on line 23 in tests/PhpSpreadsheetTests/Reader/Xlsx/Issue4476Test.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

Failed asserting that two strings are identical.

Check failure on line 23 in tests/PhpSpreadsheetTests/Reader/Xlsx/Issue4476Test.php

View workflow job for this annotation

GitHub Actions / PHP nightly

Failed asserting that two strings are identical.
$spreadsheet->disconnectWorksheets();
}
}
Binary file added tests/data/Reader/Ods/issue.4476.ods
Binary file not shown.
Binary file added tests/data/Reader/XLSX/issue.4476.xlsx
Binary file not shown.
Loading