diff --git a/changelog.MD b/changelog.MD index 1b475f9..3a82787 100644 --- a/changelog.MD +++ b/changelog.MD @@ -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** diff --git a/src/Loaders/InsertUpdate.php b/src/Loaders/InsertUpdate.php index 796082b..68c7973 100644 --- a/src/Loaders/InsertUpdate.php +++ b/src/Loaders/InsertUpdate.php @@ -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; } diff --git a/tests/Loaders/InsertUpdateTest.php b/tests/Loaders/InsertUpdateTest.php index b32b28c..95f6495 100644 --- a/tests/Loaders/InsertUpdateTest.php +++ b/tests/Loaders/InsertUpdateTest.php @@ -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 {