Skip to content

Commit 9853333

Browse files
authored
fix: add strict comparison between current and row in the db loaders (#108)
1 parent d71a743 commit 9853333

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

changelog.MD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 2.1.1
4+
5+
**Bugfixes**
6+
* Added a strict comparison in the DB Loaders. Without the fix, since with a loose comparison 'false' == true, some updates were skipped.
7+
38
## 2.1
49

510
**New features**

src/Loaders/InsertUpdate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ protected function update(array $row, array $current): void
185185
$this->prepareUpdate($row);
186186
}
187187

188-
if ($row == array_intersect_key($current, $row)) {
188+
if ($row === array_intersect_key($current, $row)) {
189189
return;
190190
}
191191

tests/Loaders/InsertUpdateTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,52 @@ public function updateDataUsingTimestamps(): void
334334
$this->execute($this->loader, [$this->row]);
335335
}
336336

337+
/**
338+
* @test
339+
*
340+
* This test has been added to check strict comparison.
341+
* Before the fix, we had a loose comparison making skip updates because in PHP 'false' == true.
342+
*/
343+
public function updateWithTrickyTypesComparison(): void
344+
{
345+
$row = $this->createMock('Wizaplace\Etl\Row');
346+
$row->expects(static::any())->method('toArray')
347+
->willReturn(
348+
[
349+
'name' => 'Jane',
350+
'birth_date' => '1962-06-18',
351+
'active' => true,
352+
]
353+
);
354+
355+
$this->select->expects(static::once())->method('fetch')->willReturn(
356+
[
357+
'name' => 'Jane',
358+
'birth_date' => '1962-06-18',
359+
'active' => 'false',
360+
]
361+
);
362+
363+
// Updates
364+
365+
$this->statement->expects(static::once())->method('update')->with(
366+
'table',
367+
[
368+
'name',
369+
'birth_date',
370+
'active',
371+
]
372+
);
373+
374+
$this->update->expects(static::once())->method('execute')->with([
375+
'name' => 'Jane',
376+
'birth_date' => '1962-06-18',
377+
'active' => true,
378+
]);
379+
380+
$this->execute($this->loader, [$row]);
381+
}
382+
337383
/** @test */
338384
public function insertDataIntoDatabaseWithoutTransactions(): void
339385
{

0 commit comments

Comments
 (0)