Skip to content

Commit

Permalink
fix: add strict comparison between current and row in the db loaders (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ecourtial authored Mar 1, 2022
1 parent d71a743 commit 9853333
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
5 changes: 5 additions & 0 deletions changelog.MD
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 2.1.1

**Bugfixes**
* Added a strict comparison in the DB Loaders. Without the fix, since with a loose comparison 'false' == true, some updates were skipped.

## 2.1

**New features**
Expand Down
2 changes: 1 addition & 1 deletion src/Loaders/InsertUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ protected function update(array $row, array $current): void
$this->prepareUpdate($row);
}

if ($row == array_intersect_key($current, $row)) {
if ($row === array_intersect_key($current, $row)) {
return;
}

Expand Down
46 changes: 46 additions & 0 deletions tests/Loaders/InsertUpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,52 @@ public function updateDataUsingTimestamps(): void
$this->execute($this->loader, [$this->row]);
}

/**
* @test
*
* This test has been added to check strict comparison.
* Before the fix, we had a loose comparison making skip updates because in PHP 'false' == true.
*/
public function updateWithTrickyTypesComparison(): void
{
$row = $this->createMock('Wizaplace\Etl\Row');
$row->expects(static::any())->method('toArray')
->willReturn(
[
'name' => 'Jane',
'birth_date' => '1962-06-18',
'active' => true,
]
);

$this->select->expects(static::once())->method('fetch')->willReturn(
[
'name' => 'Jane',
'birth_date' => '1962-06-18',
'active' => 'false',
]
);

// Updates

$this->statement->expects(static::once())->method('update')->with(
'table',
[
'name',
'birth_date',
'active',
]
);

$this->update->expects(static::once())->method('execute')->with([
'name' => 'Jane',
'birth_date' => '1962-06-18',
'active' => true,
]);

$this->execute($this->loader, [$row]);
}

/** @test */
public function insertDataIntoDatabaseWithoutTransactions(): void
{
Expand Down

0 comments on commit 9853333

Please sign in to comment.