Skip to content

Commit

Permalink
Allow phpoffice/phpspreadsheet 2.0+ also
Browse files Browse the repository at this point in the history
  • Loading branch information
mwikberg-virta committed Jul 10, 2024
1 parent dedf198 commit 3c51d71
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .phpunit.cache/test-results

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@
"require": {
"ext-json": "*",
"php": "^7.0||^8.0",
"phpoffice/phpspreadsheet": "^1.18",
"phpoffice/phpspreadsheet": "^1.18||^2.0",
"illuminate/support": "5.8.*||^6.0||^7.0||^8.0||^9.0||^10.0||^11.0",
"psr/simple-cache": "^1.0||^2.0||^3.0",
"composer/semver": "^3.3"
},
"require-dev": {
"orchestra/testbench": "^6.0||^7.0||^8.0||^9.0",
"predis/predis": "^1.1",
"laravel/scout": "^7.0||^8.0||^9.0||^10.0"
"laravel/scout": "^7.0||^8.0||^9.0||^10.0",
"laravel/legacy-factories": "^1.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion src/DefaultValueBinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class DefaultValueBinder extends PhpSpreadsheetDefaultValueBinder
* @param mixed $value Value to bind in cell
* @return bool
*/
public function bindValue(Cell $cell, $value)
public function bindValue(Cell $cell, $value): bool
{
if (is_array($value)) {
$value = \json_encode($value);
Expand Down
2 changes: 1 addition & 1 deletion src/Filters/ChunkReadFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(int $headingRow, int $startRow, int $chunkSize, stri
* @param string $worksheetName
* @return bool
*/
public function readCell($column, $row, $worksheetName = '')
public function readCell($column, $row, $worksheetName = ''): bool
{
// Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow
return ($worksheetName === $this->worksheetName || $worksheetName === '')
Expand Down
2 changes: 1 addition & 1 deletion src/Filters/LimitFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(int $startRow, int $limit)
* @param string $worksheetName
* @return bool
*/
public function readCell($column, $row, $worksheetName = '')
public function readCell($column, $row, $worksheetName = ''): bool
{
return $row >= $this->startRow && $row < $this->endRow;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Concerns/WithColumnFormattingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function columnFormats(): array

$actual = $this->readAsArray(__DIR__ . '/../Data/Disks/Local/with-column-formatting-store.xlsx', 'Xlsx');

$legacyPhpSpreadsheet = !InstalledVersions::satisfies(new VersionParser, 'phpoffice/phpspreadsheet', '^1.28');
$legacyPhpSpreadsheet = !InstalledVersions::satisfies(new VersionParser, 'phpoffice/phpspreadsheet', '^1.28||^2.0');

$expected = [
['06/03/2018', null],
Expand Down
4 changes: 2 additions & 2 deletions tests/Concerns/WithCustomValueBinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function collection()
/**
* {@inheritdoc}
*/
public function bindValue(Cell $cell, $value)
public function bindValue(Cell $cell, $value): bool
{
// Handle percentage
if (preg_match('/^\-?\d*\.?\d*\s?\%$/', $value)) {
Expand Down Expand Up @@ -102,7 +102,7 @@ public function test_can_set_a_value_binder_on_import()
/**
* {@inheritdoc}
*/
public function bindValue(Cell $cell, $value)
public function bindValue(Cell $cell, $value): bool
{
if ($cell->getCoordinate() === 'B2') {
$cell->setValueExplicit($value, DataType::TYPE_STRING);
Expand Down
10 changes: 8 additions & 2 deletions tests/Concerns/WithMultipleSheetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Maatwebsite\Excel\Concerns\SkipsUnknownSheets;
use Maatwebsite\Excel\Concerns\ToArray;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
use Maatwebsite\Excel\Exceptions\SheetNotFoundException;
use Maatwebsite\Excel\Tests\Data\Stubs\Database\User;
use Maatwebsite\Excel\Tests\Data\Stubs\SheetForUsersFromView;
use Maatwebsite\Excel\Tests\Data\Stubs\SheetWith100Rows;
Expand Down Expand Up @@ -96,7 +97,7 @@ public function sheets(): array

public function test_unknown_sheet_index_will_throw_sheet_not_found_exception()
{
$this->expectException(\Maatwebsite\Excel\Exceptions\SheetNotFoundException::class);
$this->expectException(SheetNotFoundException::class);
$this->expectExceptionMessage('Your requested sheet index: 9999 is out of bounds. The actual number of sheets is 2.');

$import = new class implements WithMultipleSheets
Expand All @@ -117,7 +118,7 @@ public function sheets(): array

public function test_unknown_sheet_name_will_throw_sheet_not_found_exception()
{
$this->expectException(\Maatwebsite\Excel\Exceptions\SheetNotFoundException::class);
$this->expectException(SheetNotFoundException::class);
$this->expectExceptionMessage('Your requested sheet name [Some Random Sheet Name] is out of bounds.');

$import = new class implements WithMultipleSheets
Expand All @@ -127,6 +128,8 @@ public function test_unknown_sheet_name_will_throw_sheet_not_found_exception()
public function sheets(): array
{
return [
'Sheet1' => new class {
},
'Some Random Sheet Name' => new class {
},
];
Expand All @@ -147,6 +150,8 @@ public function test_unknown_sheet_name_can_be_ignored()
public function sheets(): array
{
return [
'Sheet1' => new class {
},
'Some Random Sheet Name' => new class {
},
];
Expand Down Expand Up @@ -175,6 +180,7 @@ public function test_unknown_sheet_indices_can_be_ignored_per_name()
public function sheets(): array
{
return [
'Sheet1' => new class {},
'Some Random Sheet Name' => new class implements SkipsUnknownSheets
{
/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Concerns/WithReadFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function readFilter(): IReadFilter
{
return new class implements IReadFilter
{
public function readCell($column, $row, $worksheetName = '')
public function readCell($column, $row, $worksheetName = ''): bool
{
// Assert read filter is being called.
// If assertion is not called, test will fail due to
Expand Down

0 comments on commit 3c51d71

Please sign in to comment.