Skip to content

Commit

Permalink
Revert "Merge commit 'a2b6ce161274720e2358154fa16736aee86daf7e' into …
Browse files Browse the repository at this point in the history
…features/with-grouped-headers"

This reverts commit e4634e3, reversing
changes made to 5dfdf05.
  • Loading branch information
VFAndrew committed Mar 10, 2022
1 parent e4634e3 commit e9f2552
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 72 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ All notable changes to this project will be documented in this file.
## [Unreleased]

- Adds concern `WithGroupedHeadingRow` to allow imported sheets to group the values of columns with the same header in an array
- Added failing test for `prepareForValidation` callback not being called when using `SkipsEmptyRows`

## [3.1.37] - 2022-02-28

Expand Down
5 changes: 1 addition & 4 deletions src/Sheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,9 @@ public function import($import, int $startRow = 1)
foreach ($this->worksheet->getRowIterator()->resetStart($startRow ?? 1) as $row) {
$sheetRow = new Row($row, $headingRow, $headerIsGrouped);

if ($import instanceof WithValidation) {
$sheetRow->setPreparationCallback($preparationCallback);
}

if (!$import instanceof SkipsEmptyRows || ($import instanceof SkipsEmptyRows && !$sheetRow->isEmpty($calculatesFormulas))) {
if ($import instanceof WithValidation) {
$sheetRow->setPreparationCallback($preparationCallback);
$toValidate = [$sheetRow->getIndex() => $sheetRow->toArray(null, $import instanceof WithCalculatedFormulas, $import instanceof WithFormatData, $endColumn)];

try {
Expand Down
67 changes: 0 additions & 67 deletions tests/Concerns/WithValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Illuminate\Validation\Validator;
use Maatwebsite\Excel\Concerns\Importable;
use Maatwebsite\Excel\Concerns\OnEachRow;
use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
use Maatwebsite\Excel\Concerns\ToArray;
use Maatwebsite\Excel\Concerns\ToCollection;
use Maatwebsite\Excel\Concerns\ToModel;
Expand Down Expand Up @@ -891,72 +890,6 @@ public function onRow(Row $row)
$this->assertInstanceOf(ValidationException::class, $e ?? null);
}

/**
* @test
*/
public function can_prepare_using_skipsemptyrows()
{
$import = new class implements OnEachRow, WithValidation, SkipsEmptyRows
{
use Importable;

/**
* @return array
*/
public function rules(): array
{
return [
'1' => 'email',
];
}

/**
* Prepare the data for validation.
*
* @param array $row
* @param int $index
* @return array
*/
public function prepareForValidation(array $row, int $index)
{
if ($index === 2) {
$row[1] = 'not an email';
}

return $row;
}

/**
* @param \Maatwebsite\Excel\Row $row
* @return void
*/
public function onRow(Row $row)
{
User::query()->create([
'name' => $row[0],
'email' => $row[1],
'password' => 'secret',
]);
}
};

try {
$import->import('import-users.xlsx');
} catch (ValidationException $e) {
$this->validateFailure($e, 2, '1', [
'The 1 must be a valid email address.',
]);

$this->assertEquals([
[
'There was an error on row 2. The 1 must be a valid email address.',
],
], $e->errors());
}

$this->assertInstanceOf(ValidationException::class, $e ?? null);
}

/**
* @param ValidationException $e
* @param int $row
Expand Down

0 comments on commit e9f2552

Please sign in to comment.